# The hooks installer and hook script

`https://23step.com/install/hooks.sh` wires coding agents to 23step. It downloads one Python hook script and merges entries for it into each agent's hook config. The hook sends each turn's prompt, thoughts, tool calls, commands, and token usage to the API, and starts a headless recorder when the agent opens a browser with a DevTools port. Per-agent walkthroughs are on [Getting started](https://23step.com/getting-started#repo).

## Usage

It writes the hook to `.agents/hooks/step23_otel.py` (plus a Cursor wrapper in `.cursor/hooks/`), under `~` with `--global`. Running it again refreshes the script and replaces only its own config entries; your other hooks are kept. If both a repository and a global install exist, the hook sends each turn once. It needs `curl` and `python3`, and never reads or writes your key.

Terminal:

```sh
# In the repository the agent works in (commit the result)
curl -fsSL https://23step.com/install/hooks.sh | sh -s -- claude cursor

# Once for every project on this machine
curl -fsSL https://23step.com/install/hooks.sh | sh -s -- --global all
```

Options:

| Option | Meaning |
| --- | --- |
| `--repo` (default) | Install in the current repository: the git top level, else the current directory. Aliases `--local`, `--project`. |
| `-g`, `--global` | Install in your home directory for every project. Alias `--user`. |
| `--step-link` | Opt in to injecting the active `step_url` into pre-turn hooks so the agent posts `[23step](<step_url>)` at the end of final responses (and save in `~/.config/23step/preferences.json` with `--global`). Off by default. |
| `--no-step-link` | Explicitly keep step-link prompt injection off (the default). |
| `--progress-bar` | Opt in to live widget progress-bar calibration prompts in the hook config (and `~/.config/23step/preferences.json` with `--global`). Off by default because calibrating progress uses extra tokens and slows down turns. |
| `--no-progress-bar` | Explicitly keep progress-bar calibration prompts off (the default). |
| `--api <url>` | Point installed hooks at a custom 23step API base URL (and save `apiEndpoint` in `~/.config/23step/preferences.json` with `--global`). |
| `--dev` | Shorthand for `--api https://dev.23step.com`. |
| `-h`, `--help` | Print usage. |

Agents:

| Argument | Repository config | Global config |
| --- | --- | --- |
| `claude` (`claude-code`) | `.claude/settings.json` | `~/.claude/settings.json` |
| `codex` | `.codex/hooks.json` | `~/.codex/hooks.json` (or `$CODEX_HOME/hooks.json`) |
| `cursor` | `.cursor/hooks.json` | `~/.cursor/hooks.json` |
| `antigravity` | `.agents/hooks.json` | `~/.gemini/config/hooks.json` |
| `gemini` (`gemini-cli`) | `.gemini/settings.json` | `~/.gemini/settings.json` |
| `cline` (`openrouter`) | `.clinerules/hooks/*` | `~/.cline/hooks/*` and `~/Documents/Cline/Hooks/*` |
| `all` | every agent above | every agent above |

## Installer environment

hooks.sh environment:

| Env | Default | Meaning |
| --- | --- | --- |
| `STEP23_HOOKS_BASE` | `https://23step.com/install` | Where to download the hook scripts from. |
| `STEP23_REPO_DIR` | git top level | Repository root for a repository install. |
| `STEP23_GLOBAL_DIR` | `$HOME` | Root for a `--global` install. |

## Hook script settings

The hook reads its key from `STEP23_OTEL_KEY`, then `STEP23_TOKEN`, then the file in `STEP23_OTEL_KEY_FILE`, then `~/.config/23step-otel-key`. With no key it exits quietly. It never blocks the agent: each request times out after 2 seconds.

The hook config passes the agent with a flag: `--claude`, `--codex`, or `--cline` / `--openrouter`. Cursor, Antigravity, and Gemini CLI are detected from the event payload. Any other harness that can run a command per lifecycle event can pipe its JSON event to the hook on stdin the same way (see the OpenRouter SDK guide on [Getting started](https://23step.com/getting-started/openrouter-sdk.md)).

Hook environment:

| Env | Default | Meaning |
| --- | --- | --- |
| `STEP23_OTEL_ENDPOINT` | `https://api.23step.com` | Where traces are sent. |
| `STEP23_OTEL_TIMEOUT` | `2` | Seconds per request. |
| `STEP23_DAEMON=0` | on | Do not start the screenshot recorder. |
| `STEP23_STEP_LINK=1` | off | Opt in to injecting the active `step_url` into pre-turn hooks so the agent includes `[23step](<step_url>)` at the end of final responses (off by default to save tokens and latency). |
| `STEP23_PROGRESS_BAR=1` | off | Opt in to injecting live progress-bar calibration instructions (off by default to save tokens and turn latency). |
| `STEP23_CDP_PORT` | discovered | DevTools port for the recorder to attach to. |
| `STEP23_TURN_MAX_SECONDS` | `3600` | Longest a turn may stay open. |
| `STEP23_DISABLE_RECONCILER=1` | on | Do not start `23step reconcile --watch`. |
| `STEP23_NO_AUTO_UPDATE=1` | on | Do not update `23step` from the hook. |
| `STEP23_BIN` | `PATH`, `~/.local/bin` | Path to the `23step` binary. |
| `STEP23_ARTIFACT_DIR` |  | Folder whose Markdown and image outputs are attached to the step as artifacts. |
| `STEP23_HOSTNAME` | detected | Machine name shown on the run. |

---

Version: `v0.2` (latest). All 23step developer docs: https://23step.com/docs.md
