Skip to main content

Claude Code context window budget calculator — know your token cost before you load

Project description

context-budget

Know your token cost before you load.

A CLI tool for Claude Code users. Counts the token cost of files in your workspace so you can make informed decisions about what to load in a session — before you hit the context wall.

The Problem

Claude Code has a ~200K token context window. Your system prompt + tools already consume ~80K. Every file you load eats into the remaining ~120K. Load too much = early compaction = shorter, less useful sessions.

But you don't know the cost until it's too late.

The Solution

# See what's eating your context budget
python3 context_budget.py scan ./my-workspace

# Check the exact cost of files you're about to load
python3 context_budget.py check CLAUDE.md M-memory/SESSION-BRIEF.md A-agents/jams-agent.md

# Validate your tiered loading strategy (reads CLAUDE.md tier definitions)
python3 context_budget.py tier ./my-workspace

Install

pip install tiktoken
# That's it — single file, no other dependencies

Example Output

--- Token Scan Results for './M-memory' ---
Budget: 50,000 tokens | Claude Max Context: 200,000 tokens
───────────────────────────────────────────────────────────
  15,134 tokens  (30.3% budget) (7.6% window)  learning-log-archive.md
   9,080 tokens  (18.2% budget) (4.5% window)  vision-backlog.md
   2,793 tokens   (5.6% budget) (1.4% window)  decisions.md
   1,656 tokens   (3.3% budget) (0.8% window)  SESSION-BRIEF.md
───────────────────────────────────────────────────────────
Total: 40,271 tokens (80.5% of budget) — ⚠️ NEAR LIMIT

Insight: Loading learning-log-archive.md alone costs 7.6% of the full window. SESSION-BRIEF (0.8%) gives you 90% of the value at 10% of the cost. That's why tiered loading works.

Commands

Command What it does
scan PATH Recursively lists all files sorted by token count
check FILE1 FILE2... Sums up token costs for specific files
tier PATH Reads CLAUDE.md, maps files to their loading tier

Options

Flag Default Description
--budget N 50000 Token budget to compare against
--format json text Output as JSON for scripting

Use Cases

  • Before a session: Run scan to identify which files are most expensive
  • Planning a CLAUDE.md: Use check to validate that your Tier 1 files stay under budget
  • Debugging slow sessions: Find which files are causing context bloat
  • Tiered loading audits: Use tier to confirm your loading strategy is cost-efficient

Built by

Harel Asaf · 2026-05-26

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_budget-0.1.0.tar.gz (7.0 kB view details)

Uploaded Source

Built Distribution

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

context_budget-0.1.0-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: context_budget-0.1.0.tar.gz
  • Upload date:
  • Size: 7.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for context_budget-0.1.0.tar.gz
Algorithm Hash digest
SHA256 bd70dfa7e0f291ddb37fcf84e6c7a109ed77d7ef3312c252cb201ef18ad05a73
MD5 05b5d6f11d7b75656320cd741de2f299
BLAKE2b-256 17f4018ca0df17bc6f87c2c90607fd5418c0257f6eb14584e4639eaf336f5d19

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_budget-0.1.0.tar.gz:

Publisher: publish.yml on RLASAF12/context-budget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

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

File metadata

  • Download URL: context_budget-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for context_budget-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 aa20326e16d82cc941e3fa3cf77232bee6547c8df32b78120bf57cd627fdcdda
MD5 d13af5416c7fdd99e6a5da800c059c23
BLAKE2b-256 96ad54cd2ab536f06a9ac08d93ccb1a6dde5c283e16e05481ce50a7558c0f80d

See more details on using hashes here.

Provenance

The following attestation bundles were made for context_budget-0.1.0-py3-none-any.whl:

Publisher: publish.yml on RLASAF12/context-budget

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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