Claude Code CLI
Claude Code uses the Anthropic SDK under the hood, so the ANTHROPIC_BASE_URL shim is enough to route every call through TokenOps.
Setup
Start the daemon:
bashTOKENOPS_STORAGE_ENABLED=true tokenops startPoint Claude Code at the proxy:
bashexport ANTHROPIC_BASE_URL="http://127.0.0.1:7878/anthropic" export ANTHROPIC_API_KEY="sk-ant-..."Launch Claude Code as usual:
bashclaude
Prepared workflow attribution
Claude Code can select a proxy base URL but cannot attach a TokenOps workflow header itself. Pass the workflow_id returned by tokenops_prepare_work to the local bridge for one bounded execution:
tokenops anthropic-bridge --workflow-id workflow:prepared -- claudeThe bridge adds stable execution and workflow correlation locally, prints both identifiers, and removes the headers before the request reaches Anthropic. Pass the same workflow ID to tokenops_review_work afterward to review the measured execution.
Smoke test
./scripts/smoketest-claude-code.shSends a one-shot Anthropic messages request through the proxy and asserts a fresh PromptEvent landed in ~/.tokenops/events.db.
Troubleshooting
- 403 on Claude Code launch — the proxy stripped a header. Check
tokenopslogs for "upstream error"; usually a staleanthropic-version. - TLS errors — Claude Code does not ship a custom CA store. Run TokenOps without TLS in dev (default) or trust the local CA via
tokenops cert install. - No events in store — confirm
TOKENOPS_STORAGE_ENABLED=truewas set beforetokenops start. Storage is opt-in.