BPE-Calibrated Estimator · Claude Code 40K Truncation Gauge · Prompt-Cache Cost

    AI Context & CLAUDE.md Token Counter.

    Paste any CLAUDE.md, AGENTS.md, or system prompt to measure estimated tokens, check Claude Code's 40,000-character hard truncation ceiling (AgentLint rule I7), compare 128K–1M model context windows, and model monthly prompt-cache spend.

    33 lines · 2,222 chars · 2.2 KB

    Client-side estimate calibrated against cl100k_base and Claude BPE tokenization with separate weights for ASCII prose, code punctuation/identifiers, and CJK characters. 100% local — zero text leaves your browser.

    Estimated BPE Tokens
    ~478
    ASCII prose: ~339
    Code / syntax: ~139
    CJK chars (0): ~0

    Claude Code 40,000-Character Truncation Gauge (Rule I7)

    2,222 / 40,000 chars (5.6%)Warn > 25,000

    Safely below Claude Code's 40,000-character hard limit. Related AgentLint rules: I7 (40K limit), I6 (length), I1/I2.

    Context-Window Footprint Across Frontier Models

    Claude Sonnet 4 (200K)0.24%
    Claude Opus 4 (200K)0.24%
    GPT-4.1 / 4o (128K)0.37%
    Gemini 2.5 Pro (1M)0.05%

    Monthly Prompt-Cache Cost Calculator (22 Working Days)

    Turns/day/seat:
    ModelMonthly Prefix TokensUncached / moWith 90% Prompt Cache / moMonthly Savings
    Claude Sonnet 4 (200K)105.2M$315.48$67.83-$247.65
    Claude Opus 4 (200K)105.2M$1577.40$339.14-$1238.26
    GPT-4.1 / 4o (128K)105.2M$210.32$73.61-$136.71
    Gemini 2.5 Pro (1M)105.2M$131.45$45.77-$85.68

    Frequently Asked Questions

    What happens when a CLAUDE.md exceeds 40,000 characters in Claude Code?

    Claude Code enforces MAX_MEMORY_CHARACTER_COUNT = 40,000 characters on single memory entry files. Any rules appended past character 40,000 are silently truncated before the prompt reaches the model. AgentLint rule I7 catches this automatically.

    Why do Chinese, Japanese, and Korean CLAUDE.md files use more tokens per character?

    Standard BPE tokenizers encode common English words into a single token (~3.8–4.2 chars/token), whereas CJK ideographs typically split into 1–2 tokens per character. Keeping prose concise and moving deep docs into conditional read pointers saves both budget and compliance.

    How does prompt caching affect CLAUDE.md monthly cost?

    Because CLAUDE.md sits near the static prefix of every agent turn, prompt caching discounts repeated reads by up to 90% on Anthropic Claude models — yet oversized files still hurt instruction-following accuracy (IFScale) and cache-miss cold starts.

    Fix 40,000-Char Truncation Guide →GitHub Actions SHA Pinner →Cursor .mdc Glob Tester →