Install for Claude Code¶
alr install claude-code wires OpenALR into Claude Code, so each turn you work
in Claude Code leaves one record on your machine. You need the alr command
first: see Quickstart steps 1 and 2.
Requires Claude Code 2.1.296 or later. Transcripts written by Claude Code 2.1.251 or later are read.
Install¶
alr install claude-code # prints the install preview; changes nothing
alr install claude-code --yes # applies it
The preview, --yes, the backup copies, and --home DIR work as on every install: see
How Every Install Works. After you upgrade OpenALR, run
alr install claude-code again.
Then fetch the latest price book with alr prices update: see
Get the Latest Price Book.
What It Writes¶
Paths below are as on macOS and Linux; on Windows ~ is %USERPROFILE% (see
Where Files Live).
Five hooks in ~/.claude/settings.json. Each one runs an alr hook command that
hands the event to the emitter. Stop, SubagentStop, and SessionEnd run
alr hook claude-code --event <name> (with that hook's own name).
UserPromptExpansion and UserPromptSubmit run alr hook claude-code-tag.
| Hook | What it does |
|---|---|
Stop |
Writes a record for every turn that has none yet. |
SubagentStop |
Writes the records of the subagent that just finished. |
SessionEnd |
Does what Stop does, and also writes the session's cost record. |
UserPromptExpansion |
Answers the in-session commands. It matches alr-tag, alr-ctl, alr-turns, alr-grade, alr-help, and alr. |
UserPromptSubmit |
Answers the in-session commands, and notes the start of each turn and the tags it takes. |
Your own hooks stay as they are. Eight command files in ~/.claude/commands/:
alr-tag.md, alr-ctl.md, alr-turns.md, alr-grade.md, alr-help.md,
alr.md, alr-plan.md, and alr-prices.md. The first six are answered by a hook
before any model call, so they cost no model turn. /alr-plan and /alr-prices
are interviews with the agent, so each is a model turn. A file that already has one of these names is left alone, and
the install preview says so.
The hooks always exit 0. A broken emitter never breaks your session. A missed record is a gap in the accounting, not an incident.
Two Settings Worth Making First¶
- The agent ID. A record's
agentis your login name. If you share anything built from the records, name the agent withALR_EMIT_AGENT_ID. - The cost basis. The transcript does not say how the session was billed, so
the records' basis is
unstateduntil you state it. For a session billed to an API key, setALR_EMIT_COST_BASIS=meteredbeforeclaudestarts (how to set it). How costs are computed explains the bases.
Cost for Each Turn (Optional)¶
Claude Code gives a session's cost once, when the session ends. Until then a turn shows a dash for its cost, and afterwards each turn gets a share of the session's total. To give each turn its own figure, let OpenALR receive Claude Code's cost telemetry:
alr otel start # starts a small receiver on your machine and sets Claude Code's four telemetry settings
alr otel status # shows the receiver and each setting
alr otel stop # stops the receiver and removes the settings
Restart Claude Code after start or stop. The receiver listens on your own
machine only, and nothing is sent anywhere. It does not start again after a
reboot: run alr otel start again. How costs are
computed explains
the figures.
Check It¶
- Start
claudeand send a prompt. - Type
/alr-ctl. It answers with one status line: the version, whether OpenALR is emitting, the profile, the last turn, and the record file. In Claude Code the answer appears as the block message under your prompt. - Type
/alr-turnsto see your last turns. - End the session, then run:
alr summary
alr turns last
alr check
alr check lists every line of the record files that the viewer could not use,
and why. A Claude Code turn shows a dash for its cost until the session exits,
because Claude Code reports a session's cost once, when the session ends.
If Claude Code was killed before it exited (kill -9, a closed terminal), resume
the session (claude --resume <session id>) and exit it normally. Its records
are then written once each. The cost of the killed process is not in the
session total, so the session record says cost_is_partial: true.
Uninstall and Purge¶
alr uninstall claude-code --yes # removes only the hooks the install added
alr uninstall claude-code --purge --yes # ... and deletes Claude Code's records
Uninstall removes exactly the hooks whose command starts with alr hook and
leaves every other hook alone. It removes the command files it added, unless you
changed them since. Your records are kept unless you pass --purge.
--purge deletes only the Claude Code records from the shared record file, and
the grades, cost corrections, and tag events that name only those records. Every
other harness's records stay, byte for byte. Without --yes, --purge previews:
per file, how many documents it would delete and how many stay. A line the purge
cannot read is never deleted, and the purge names it.
Why It Works This Way¶
- The install preview comes first. The install edits a settings file you may have written by hand, so it shows the exact change as a diff before it touches anything, and keeps a copy of the file when it does.
- The hooks never fail your session. A tool that meters your work must not be able to stop it. A turn that is missed can be written later; a session that is broken cannot be given back.
- Uninstall takes only what the install added. Your records are yours, so
removing the hooks never deletes them. Deleting records is a separate, named
step,
--purge, and it touches only the harness you name.
Next: tag your work.