Recommended Setup
Add hooks to your Claude Code settings
Add the following to The
.claude/settings.json for project-level tracking, or to ~/.claude/settings.json to track every Claude Code session globally:|| true on every command means tracking failures never interrupt your work.What Gets Tracked
- AI tokens & cost — estimated from the conversation transcript, auto-priced per model
- Git commits — every commit Claude makes during the session
- Files changed — all file modifications between session start and end
- Duration — how long the session lasted
- Agent name — shows “Claude Code” in the dashboard for filtering
How cs auto-log Works
The Stop hook fires after each Claude response and calls cs auto-log, which:
- Reads hook input JSON from stdin (which includes
transcript_path) - Parses the Claude Code conversation transcript (JSONL format)
- Tracks its position so it only counts new messages since the last call
- Estimates token counts from conversation content (~1 token per 4 characters)
- Auto-calculates cost using the built-in pricing table for the specified model
- Logs everything to the active CostHQ session
cs auto-log Options
| Flag | Default | Description |
|---|---|---|
--provider | anthropic | AI provider |
--model | claude-sonnet-4 | Model for pricing lookup |
--agent | Claude Code | Agent name shown in the dashboard |
--model in the Stop hook to match what you’re actually using:
Alternative: CLAUDE.md Instructions
If you prefer Claude to handle tracking as part of its own workflow instead of using hooks, add the following to yourCLAUDE.md:
Alternative: Manual CLI
You can also run the session lifecycle yourself alongside Claude Code:Multi-Agent Tracking
If you run Claude Code alongside OpenClaw or other agents, the--agent flag keeps costs separated in the dashboard. Each agent gets its own cost breakdown so you always know which tool spent what.
Troubleshooting
"session_active" error on start
"session_active" error on start
The
--close-stale flag in the SessionStart hook handles this automatically. If you see this error in a manual workflow, run:Hook not firing
Hook not firing
Run
claude --debug to view hook execution logs. Verify that cs is on your PATH by running which cs (macOS/Linux) or where cs (Windows) in a fresh terminal.Token estimates seem off
Token estimates seem off
cs auto-log estimates approximately 1 token per 4 characters from the transcript. The estimate is consistent across calls, but it is approximate. For exact token counts, replace the Stop hook with explicit cs log-ai calls using real token values from your API responses.Windows path issues
Windows path issues
Replace
2>/dev/null with 2>NUL in your hook commands, and use the full path to the cs binary: