Skip to main content

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: --daemon uses fork on Unix and subprocess.Popen with DETACHED_PROCESS on 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"
  }
}

Metadata

Release files for codetrack-cli 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for codetrack-cli 0.1.0
File Size Uploaded
codetrack_cli-0.1.0.tar.gz 30.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for codetrack-cli 0.1.0
File Interpreter ABI Platform
codetrack_cli-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 56.1 kB

Release files / codetrack_cli-0.1.0.tar.gz

Download URL codetrack_cli-0.1.0.tar.gz
Size 30.2 kB
Tags Source
SHA-256 checksum
How to use checksums
48fdbb364a826d77ef4a58995605bedfac09f7412c50b354a2e536c853eec6d6
BLAKE2b-256 checksum
How to use checksums
32e02157b293b1d6f42b99bbb10439d096b4b8443e37496949deb2586b54e794
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release files / codetrack_cli-0.1.0-py3-none-any.whl

Download URL codetrack_cli-0.1.0-py3-none-any.whl
Size 26.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
da551eb7c5e40d78ce06e03c69b559e18dbc344b521cb509f8eeb1c924e08cf1
BLAKE2b-256 checksum
How to use checksums
b386ff32c7d18451255f42a65a1a1122935977cb911f041518f25f20534a5f72
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.8

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page