Skip to main content

context-audit

85–99% of your coding agent bill is invisible input tokens. Inspect your context economics in 5 seconds.


📈 The Problem

Almost every engineer building or using agentic coding tools (like Claude Code, Cursor, Aider, or custom IDE agents) complains about runaway context growth and mounting API bills.

When sessions get long, you aren't paying for your prompts—you’re paying for the compounding weight of raw terminal logs, repeated file reads, and tool history re-sent on every single turn.

We built context-audit as a zero-config, 100% local CLI that parses your local session transcripts, measures context reuse, models dynamic prefix caching, and identifies true redundant waste.


⚡ Quick Start (Zero Config)

# Auto-detects local Claude Code, Cursor, and IDE agent session logs
pip install context-audit && context-audit

📊 Cross-Session Benchmark (27 Real Developer Sessions)

We benchmarked 27 real-world developer session transcripts scanned across IDE agent logs:

+-------------------------- context-audit benchmark --------------------------+
|   CROSS-SESSION BENCHMARK SUMMARY                                           |
|   Directory: 27 Real Developer Sessions                                     |
|                                                                             |
|   Sessions Analyzed: 27                                                     |
|                                                                             |
|   Cumulative Session Tokens:                                                |
|     Avg: 3.3M | Median: 314.2k | Max: 43.3M                                 |
|   Peak Context Size:                                                        |
|     Avg: 33.2k | Median: 20.1k | Max: 188.9k                                |
|   Final Context Size:                                                       |
|     Avg: 33.2k | Median: 20.1k                                              |
|   Context Reuse Ratio:                                                      |
|     Avg: 92.6% | Median: 94.2%                                              |
|   Average Novel Context Ratio: 7.4%                                         |
|                                                                             |
|   Financial Cost Aggregations (USD):                                        |
|     Total Standard Spend: $269.80                                           |
|     Avg Session Cost (No Cache): $9.99 | Median: $0.94                      |
|     Avg Session Cost (With Cache): $1.09 | Median: $0.15                    |
|     Total Potential Cache Savings: $240.40 (Avg: $8.90 / session, 89.1%)    |
|                                                                             |
+-----------------------------------------------------------------------------+

Context Size Scaling Breakdown

Session Size Class (Final Turn) Session Count Avg Context Reuse % Avg Cache Savings ($) Avg Peak Context Size Avg Cumulative Tokens
< 5k tokens 1 94.2% $0.09 2.0k 34.3k
5k - 20k tokens 12 87.4% $0.24 10.0k 97.5k
20k - 50k tokens 8 95.6% $1.49 23.6k 575.4k
> 50k tokens 6 99.0% $37.59 97.3k 14.0M

(For the complete cross-session benchmark report, see benchmark_summary.md.)


💡 Key Architectural Insights

1. The Prompt Caching Paradox

  • Dynamic Prefix Caching (Anthropic/OpenAI style): Caching the multi-turn conversational prefix across turns reduces input costs by ~89.1% ($240 of $270 spend across our 27 sessions). If you're running custom agent loops without cache breakpoints configured, you are overpaying by ~9x.
  • Static Header Caching: Caching only the static header (system prompt + tools) saves only ~1.0%. In long sessions, the dynamic message history (>50k tokens) completely dwarfs the static header (~500 tokens).

2. The Residual Waste (What Caching Doesn't Fix)

Even with prompt caching enabled, ~35% of payload volume was redundant workspace state:

  • Identical files re-read multiple times within the same session without edits.
  • Redundant tool declarations that are never invoked.
  • Multi-kilobyte compiler error logs lingering across 40 subsequent turns.

This dead payload pushes context windows toward the 100k/200k token limits, increases per-turn latency, and degrades model attention.

3. Coding Agents Have Two Memory Systems

  • Workspace Memory (Disk-Backed): Terminal command outputs, read file payloads, directory listings, and compiler logs.
    • Verdict: Safe for compaction. Once code changes are written to the workspace, the filesystem is the source of truth.
  • Conversational Memory (Not Disk-Backed): User preferences, constraints, stylistic choices, and rejected options.
    • Verdict: Must persist. Pruning them naively causes behavioral regressions (e.g. the agent re-suggesting previously rejected architectures). (See regression_case.md for a case study).

📊 Terminal Run Output

Running context-audit instantly outputs a clean summary card and timeline report:

+--------------------------- context-audit summary ---------------------------+
|   Target: 27 Sessions (Auto-Discovered)                                     |
|                                                                             |
|   93%  repeated context (paid for twice+)                                   |
|   12%  fixed overhead (tools/system prompt before you typed)                |
|   89%  effective cache hit rate (target benchmark: ~86%)                    |
|                                                                             |
|   Estimated wasted spend: ~$267.12                                          |
|                                                                             |
+-----------------------------------------------------------------------------+
[*] My context-audit: 93% repeated context | 89% cache hit rate | ~$267.12 wasted. Run yours: pip install context-audit && context-audit

🚀 CLI Usage

# 1. Zero-config auto-discovery across ~/.claude, ~/.cursor, and local workspace:
context-audit

# 2. Audit a specific session transcript:
context-audit run path/to/transcript.jsonl

# 3. Benchmark a directory recursively:
context-audit benchmark path/to/logs_directory

🔒 Privacy & Offline Guarantee

  • 100% Local: No network requests, no telemetry, no tracking, no data leaves your machine.
  • Open Source: MIT Licensed.

Release files for context-audit 0.1.1

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

Source distribution (sdist)

Source distribution for context-audit 0.1.1
File Size Uploaded
context_audit-0.1.1.tar.gz 28.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for context-audit 0.1.1
File Interpreter ABI Platform
context_audit-0.1.1-py3-none-any.whl Python 3 none any Details

Total release size: 54.1 kB

Release files / context_audit-0.1.1.tar.gz

Download URL context_audit-0.1.1.tar.gz
Size 28.8 kB
Tags Source
SHA-256 checksum
How to use checksums
fc7162a839c7481171dd04842f0642479e91d61666189b9a1e73e275728f385b
BLAKE2b-256 checksum
How to use checksums
9a21f602e64a07d1dba8204f61e9f10069240ee6add859c602310cb6399a10f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release files / context_audit-0.1.1-py3-none-any.whl

Download URL context_audit-0.1.1-py3-none-any.whl
Size 25.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
6270f7f19bfc365dd7721400102919d88cb78a8a2fa58e08eecffcc7fbe7835c
BLAKE2b-256 checksum
How to use checksums
f944199832cd4566c2230f8cd7861fd1ef8c74b3dd404abc0ca1c85352c7bfa4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.4

Release history Release notifications | RSS feed

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

This release

0.1.1 This release

2 release files

0.1.0

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