Skip to main content

See what blew up your Claude Code context window — git diff for token usage.

Project description

context-diff

git diff for your Claude Code context window. See exactly which tool call ate 40k tokens, which turn evicted the cache, and how close you are to hitting the 200k ceiling.

PyPI Python License: MIT


Why

Your Claude Code session keeps hitting "auto-compact triggered." You suspect some tool result is huge — but which? Was it the 80-file find, the Read on the giant log, or the third agent you spawned in parallel?

context-diff reads your session JSONL (Claude Code records every turn locally) and renders a turn-by-turn token waterfall: input tokens, cache reads, deltas, which tool calls fired, and the top-N biggest jumps.

You go from "my context is full and I don't know why" to "Turn 14's Grep returned 38k tokens — I should have piped it through head" in 2 seconds.


Install

pip install context-diff
# or
uvx context-diff --auto

Zero dependencies. Pure Python ≥3.10.


Use

# Auto-pick the most recently modified session
context-diff --auto

# Or point at a specific session
context-diff ~/.claude/projects/-Users-you-proj/abc-def.jsonl

# Show top 10 biggest turns
context-diff --auto --top 10

# Machine-readable
context-diff --auto --json | jq '.[] | select(.delta_input > 10000)'

Example output

Turn  Kind          Δ tokens         in   cache_r  Label
─────────────────────────────────────────────────────────────────
   1  user                 —          —         —  user: fix the auth bug in /login
   2  assistant        1.2k        1.2k         —  ⬆ Read, Grep
   3  tool_result          —          —         —  ↳ tool_result × 2  (8,420 chars)
   4  assistant        2.1k        850       1.2k  ⬆ Edit
   5  tool_result          —          —         —  ↳ tool_result × 1  (320 chars)
   6  assistant       38.4k        420      38.0k  ⬆ Bash  ← BIG
   ...

Final context: 84.2k tokens (fresh=1.4k, cache_r=82.8k, cache_w=0)
Cumulative cache hit rate: 92.4%

Top 5 context-eating turns:
  1. Turn   6   38.4k tokens   ⬆ Bash
  2. Turn  12   12.1k tokens   ⬆ Grep
  3. Turn   4    2.1k tokens   ⬆ Edit
  4. Turn  18    1.4k tokens   ⬆ Read
  5. Turn   2    1.2k tokens   ⬆ Read, Grep

Red ← BIG markers highlight any turn that added more than 20k tokens. Yellow flags ≥5k.


What the columns mean

Column Meaning
Δ tokens Change in total context input vs. previous assistant turn. The number that tells you "this tool call cost me 38k tokens."
in Fresh (uncached) input tokens — these are the ones you actually paid full price for.
cache_r Tokens read from the prompt cache — these are ~10× cheaper.
Label Tool calls issued () or tool results received ().

Where Claude Code stores sessions

OS Path
macOS ~/.claude/projects/<encoded-cwd>/<uuid>.jsonl
Linux ~/.claude/projects/<encoded-cwd>/<uuid>.jsonl
Windows %USERPROFILE%\.claude\projects\<encoded-cwd>\<uuid>.jsonl

--auto picks the most recently modified one across all projects.


Workflow recipes

"Why did my agent auto-compact at turn 30?"

context-diff --auto --top 10

"Which tool calls in my project are consistently expensive?"

for f in ~/.claude/projects/-Users-me-myproj/*.jsonl; do
  context-diff --no-color "$f" --json
done | jq -s '[.[][] | select(.kind=="assistant" and .delta_input > 5000) | .label] | group_by(.) | map({label: .[0], n: length}) | sort_by(-.n)'

"Compare two sessions side-by-side."

diff <(context-diff a.jsonl --no-color) <(context-diff b.jsonl --no-color)

Companion projects


License

MIT © yubinkim444

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

context_diff-0.1.0.tar.gz (6.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

context_diff-0.1.0-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file context_diff-0.1.0.tar.gz.

File metadata

  • Download URL: context_diff-0.1.0.tar.gz
  • Upload date:
  • Size: 6.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for context_diff-0.1.0.tar.gz
Algorithm Hash digest
SHA256 fb94b63c8eb28ad378e9d82bc0098b36c5ddc2c23df87dc7a37b1dd36dc9c5c0
MD5 6da200d1f0f071ec33de095a4bad806f
BLAKE2b-256 b90d3b23fff56da43d4947fbde2d4a6b632653d9d29d69ebeef2ed06b326d8e4

See more details on using hashes here.

File details

Details for the file context_diff-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: context_diff-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.13

File hashes

Hashes for context_diff-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 469b36f5ba158ac0df3668b919e07103c7a105a217807c34958caf4f24749a77
MD5 81f7008e2f3879968e8ba484510c0556
BLAKE2b-256 8771086924d621fac3c20ba85e28860d783929d5dede499befe2a32bde24a535

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page