agnostic-skills

thread-cost

thread-cost

Shows what each agent turn costs and has the model write a handoff before a thread gets expensive.

Quick start

  1. Copy the folder to a place it will stay: install a skill.

  2. Wire the hooks (<skill> is this folder):

    python3 <skill>/scripts/thread_hooks_install.py --write
  3. Check it reads your session:

    python3 <skill>/scripts/thread_cost_alert.py status

What's inside

Script / fileWhat it does
scripts/thread_cost_alert.pyCost line, alerts, capture block; status / check / replay
scripts/thread_idle_capture.pyIdle wake before the prompt cache lapses (Claude Code)
scripts/thread_handoff.pyRecords the handoff; resumes from it after /clear or /compact
scripts/thread_hook_antigravity.pyAntigravity hook adapter
scripts/thread_usage.pyReads Claude Code, opencode, Codex and Antigravity sessions: time, tokens, cost
scripts/model_prices.jsonPrice table (USD per million tokens, with an as_of date)
scripts/thread_hooks_common.pyShared config and state helpers
scripts/thread_hooks_install.pyWires, checks and removes the hooks

How it works

Every request re-reads the whole conversation, so a long thread pays for its past on every step. The hooks read the transcript, estimate cost, and at a threshold ask the model to write a handoff. You then clear and continue from it.

What fires and when
TriggerDoes
Every promptGives the model last turn's cost to end the reply with (off with thread_turn_cost_line=0)
Every $5Alert on screen and to the model
Live context 200KOne on-screen note
$15 (then every $15), or context 300K (then every 100K)Blocks the stop once with the capture instruction
Context 40K past the session start (then every 40K)Same capture block; skipped for subagents
SessionStart after clear or compactTells the new session to read the recorded handoff first
Resume after the cache lifetime on context over 100KOne-line note suggesting a handoff and a clear
50 min idle (cost >= $1, context >= 60K)Wakes the thread once to capture while the cache is warm
Configuration keys

All optional. Environment wins, then ~/.config/thread-cost/config.env, then the default.

KeyDefaultMeaning
thread_cost_alert_usd / thread_cost_alert_step_usd5 / 5first alert, then every step
thread_cost_capture_usd / thread_cost_capture_step_usd15 / 15cost capture
thread_ctx_capture_k / thread_ctx_step_k300 / 100context capture (K tokens)
thread_ctx_growth_k40growth capture; 0 = off
thread_idle_capture_min50idle wake; keep under the 1h cache TTL
thread_turn_cost_line10 = no per-turn cost line
thread_capture_step / thread_capture_step_filebuilt inthe capture step, as one line or a text file

Full list: SKILL.md, Config.

Harness support
HarnessCost line, alerts, captureIdle wake, resume after clear
Claude Codeautomatic (hooks)automatic
Antigravityautomatic once a conversation has token datano
opencode, Codex, Cursor, a bare terminalmanual: run status at iteration boundariesno
Hooks and what they change
  • Claude Code: five hooks merged into settings.json.

  • Antigravity: one thread-cost hook in config/hooks.json, when ~/.gemini exists.

  • Your other hooks are kept and each file is backed up first.

  • Any hook failure prints nothing and exits 0, so a hook never breaks a turn.

Limits and safety
  • Cost is an API list-price estimate; a subscription bills differently, so read it as relative size.

  • Scripts are read-only towards the harness and use no network, except the optional Antigravity local server on 127.0.0.1.

  • State lives outside every repo.

  • Uninstall: python3 <skill>/scripts/thread_hooks_install.py --uninstall --write, then delete the folder.

Files

Part of agnostic-skills · MIT