Install thread-cost
Install adds hooks that show per-turn cost estimates, raise $5 alerts, and ask the model to write a handoff before you clear a thread. What it does and the rule it enforces: SKILL.md.
Requirements
python33.9+ (stdlib only). On Windows usepyin place ofpython3.macOS, Linux or Windows.
Install
The installer reports first and changes nothing until --write.
Put the
thread-costfolder where it will stay. The hooks call its scripts by absolute path.- Claude Code:
~/.claude/skills/thread-cost(all projects), or<repo>/.claude/skills/thread-cost. - Antigravity, opencode, Codex: their skills folder, or any fixed folder.
- Claude Code:
Report what is missing:
python3 <skill>/scripts/thread_hooks_install.pyAdd the missing hooks:
python3 <skill>/scripts/thread_hooks_install.py --writeRestart a running session. Hooks are read at session start.
Check it works
python3 <skill>/scripts/thread_cost_alert.py status
Uninstall
python3 <skill>/scripts/thread_hooks_install.py --uninstall --write
Then delete the folder. Optional cleanup: hook state under thread_hooks_state_dir (default ${XDG_STATE_HOME:-~/.local/state}/thread-hooks, or %LOCALAPPDATA%\thread-hooks on Windows), and the config file (if you made one) under ~/.config/thread-cost/.
What the installer changes
Merges five hooks into Claude Code's
settings.json.Adds one hook named
thread-costto Antigravity'sconfig/hooks.jsonwhen~/.geminiexists.Keeps your other hooks, and backs up each file first.
--no-idleleaves out the idle wake.--harnesslimits it to one harness.In Claude Code, the next reply should end with a
_Last turn ~$...line. The first turn showsFirst turn ~$...on screen at Stop instead.
Harnesses without hooks (opencode, Codex, Cursor, a bare terminal)
Paste this into the project's AGENTS.md (or the harness's always-loaded rules):
## Thread cost
At an iteration boundary (a PR opens or merges, before a long wait, after about 40K of new
context), run `python3 <skill>/scripts/thread_cost_alert.py status`. When it prints CAPTURE NOW,
do what it says: write the handoff, make no outward writes, then tell the user to start a new
conversation from the handoff. Delegate screenshot- and log-heavy work to a subagent that returns
a verdict.
Configuration
Optional; with no config the defaults apply.
Put
KEY=valuelines in~/.config/thread-cost/config.env(%APPDATA%\thread-cost\config.envon Windows, or the file$THREAD_COST_CONFIGnames).Or set the environment variables the script
--helplists.All keys are in
SKILL.md, Config.
Most setups change only:
| Key | Example | Meaning |
|---|---|---|
thread_capture_step_file | ~/path/to/capture-step.txt | One paragraph telling the model how this setup records a handoff (which folder, what to update, whether to commit). Without it, the built-in step asks for a handoff doc where the project keeps its notes. |
thread_ctx_growth_k | 80 (or 0) | Use if the 40K growth capture fires too often. |
What is in the folder
| Path | What it is |
|---|---|
SKILL.md | The rule, what fires, harness support, config keys |
scripts/thread_cost_alert.py | Cost line, alerts, capture block; status / check / replay |
scripts/thread_idle_capture.py | Idle wake before the prompt cache lapses (Claude Code) |
scripts/thread_handoff.py | Records the handoff; resumes from it after /clear or /compact |
scripts/thread_hook_antigravity.py | Antigravity hook adapter |
scripts/thread_usage.py | Reads Claude Code, opencode, Codex and Antigravity sessions: time, tokens, cost |
scripts/model_prices.json | Price table (USD per million tokens, with an as_of date) |
scripts/thread_hooks_common.py | Shared config and state helpers |
scripts/thread_hooks_install.py | Wires, checks and removes the hooks |
Update
Replace the folder in place; the hooks keep working. Run the installer again if the folder moved.