Background usage tracker for Claude Code and Codex CLI sessions
Project description
codetrack
Background usage tracker for Claude Code and Codex CLI sessions.
Polls active session directories, extracts token usage, context window state, cost data, and timing from JSONL transcripts, then writes deduplicated snapshots to per-session CSV files. One file per session — no shared read-modify-write, safe across multiple terminals/tabs/windows. Works on macOS, Linux, Windows, and WSL. Zero dependencies.
Install
uv tool install codetrack-cli
Or from source:
uv tool install -e .
Requires Python 3.11+. No dependencies beyond stdlib.
Quick start
# Import all existing sessions from disk
codetrack backfill
# Start watching for new activity (background)
codetrack watch --daemon
# See what's happening
codetrack status
codetrack report
Usage
Watch
Polls Claude Code and Codex CLI session directories for changes. Both providers are tracked automatically — no configuration needed.
codetrack watch # foreground (Ctrl+C to stop)
codetrack watch --daemon # background (writes PID file)
codetrack watch --interval 5 # custom poll interval (seconds)
codetrack stop # stop background watcher
codetrack status # watcher state + active sessions
Backfill
Import historical sessions already on disk. Idempotent — skips sessions that are already tracked. Uses each file's modification time as the snapshot timestamp, so historical data appears in the correct report windows.
codetrack backfill # all sessions
codetrack backfill --since 168 # last 7 days (168 hours)
codetrack backfill --dry-run # preview without writing
Report
codetrack report # all time
codetrack report --window 7d # last 7 days
codetrack report --window 5h # last 5 hours
codetrack report --provider claude
codetrack report --session abc123
Export
codetrack export --window 30d --out export.csv
codetrack export --provider codex --out codex.csv
Session discovery
Auto-discovers sessions with no configuration:
| Provider | Paths scanned |
|---|---|
| Claude Code | ~/.config/claude/projects/<hash>/<session>.jsonl (v1.0.30+) |
| Claude Code (legacy) | ~/.claude/projects/<hash>/<session>.jsonl |
| Codex CLI | ~/.codex/sessions/ (or $CODEX_HOME/sessions/) |
| WSL | All of the above under /mnt/c/Users/<name>/ |
Data captured
Each snapshot records:
| Field | Source |
|---|---|
tokens_in, tokens_out |
Cumulative input/output tokens |
cache_read, cache_write |
Prompt cache usage |
cost_usd |
costUSD from transcript (Claude Code) |
ctx_pct, ctx_tokens, ctx_max |
Context window utilization |
wall_sec |
Wall clock time (first to last timestamp) |
api_sec |
API latency (statusLine hook only) |
diff_add, diff_del |
Lines added/removed (statusLine hook only) |
model, provider, session_id |
Session identification |
Storage
Per-session CSV files at ~/.codetrack/sessions/{provider}_{session_id}.csv. Each file is append-only, written by exactly one process. Reports scan all session files and merge on read.
~/.codetrack/
sessions/
claude_a1b2c3d4e5f6.csv
claude_f7e8d9c0b1a2.csv
codex_session1234.csv
codetrack.pid
codetrack.log
Cost tracking
codetrack captures costUSD when present in Claude Code transcripts but does not estimate cost from tokens. For detailed cost breakdowns across providers, use ccusage.
How it works
- Filesystem polling: Scans session directories every 10 seconds (configurable). No filesystem watchers or inotify — pure polling for maximum portability, including WSL where inotify doesn't work on Windows-side paths.
- Deduplication: Two-layer dedup — mtime check skips unchanged files, content hash (provider + session + token counts) prevents duplicate snapshots when data hasn't changed between polls.
- Per-session isolation: No shared read-modify-write. Multiple watchers across terminals are safe because each session maps to exactly one file.
- Cross-platform daemon:
--daemonusesforkon Unix andsubprocess.PopenwithDETACHED_PROCESSon Windows.
Advanced: statusLine hook
The watcher gets all data from JSONL transcripts. For additional fields (api_sec, diff_add, diff_del), you can manually configure Claude Code's statusLine to pipe through codetrack:
Add to ~/.claude/settings.json:
{
"statusLine": {
"type": "command",
"command": "codetrack hook claude"
}
}
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file codetrack_cli-0.1.0.tar.gz.
File metadata
- Download URL: codetrack_cli-0.1.0.tar.gz
- Upload date:
- Size: 30.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
48fdbb364a826d77ef4a58995605bedfac09f7412c50b354a2e536c853eec6d6
|
|
| MD5 |
bcb2aaf6c3e28822e6c3d1ce2c6272d8
|
|
| BLAKE2b-256 |
32e02157b293b1d6f42b99bbb10439d096b4b8443e37496949deb2586b54e794
|
File details
Details for the file codetrack_cli-0.1.0-py3-none-any.whl.
File metadata
- Download URL: codetrack_cli-0.1.0-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
da551eb7c5e40d78ce06e03c69b559e18dbc344b521cb509f8eeb1c924e08cf1
|
|
| MD5 |
5649984429cc65f413779e0b6ef105d6
|
|
| BLAKE2b-256 |
b386ff32c7d18451255f42a65a1a1122935977cb911f041518f25f20534a5f72
|