critical severityclaude-code

    CLAUDE.md 40,000-Character Limit — How Silent Truncation Breaks Safety Rules

    Warning: CLAUDE.md exceeds 40,000 characters — rules at the bottom are silently truncated by Claude Code.

    Direct-Answer Fix Summary

    Claude Code caps single memory files at 40,000 characters (MAX_MEMORY_CHARACTER_COUNT). Across 4,533 audited GitHub repos, 37 real repositories exceed this ceiling and lose their tail rules silently. Fix it by cutting root CLAUDE.md under 150 lines (~6,000 chars) and moving deep docs into docs/ with conditional read pointers.

    Broken vs. Fixed Configuration

    Broken: 44,800-char monolith CLAUDE.md
    # Monorepo Handbook (44,800 characters)
    ## Entire OpenAPI Spec (28,000 chars pasted inline...)
    ## Complete Database Schema Dump (14,000 chars...)
    ## Production Safety Rules (starts at char 42,100 -> SILENTLY DROPPED!)
    - Never run prisma migrate reset on staging or prod.
    Fixed: 3,200-char index with conditional pointers
    # Monorepo Root CLAUDE.md (3,200 chars)
    ## Verification
    - Fast check: pnpm --filter api test src/orders.test.ts
    
    ## Conditional Deep Guides
    - When editing HTTP contracts, read docs/openapi-conventions.md.
    - When changing SQL tables, read docs/database-migrations.md.
    
    ## Production Safety Rules (always inside first 4,000 chars)
    - Don't run prisma migrate reset. Instead create a forward migration via pnpm prisma migrate dev.

    Why This Happens

    Teams copy architecture wikis, API schemas, or auto-generated file trees into CLAUDE.md. Because new emergency rules are usually appended at the bottom, the highest-priority incident rules are the very lines truncated off the end.

    Step-by-Step Fix

    1. 01
      Measure exact character count

      Paste CLAUDE.md into the AgentLint Token Counter to see exact characters, percentage of 40,000, and which bottom lines are dropped.

    2. 02
      Extract subsystem guides to docs/

      Move migration guides, API catalogs, and design-system docs into dedicated Markdown files under docs/.

    3. 03
      Add conditional read pointers in root CLAUDE.md

      Replace 200-line sections with one-line triggers like: When modifying GraphQL resolvers, read docs/graphql.md first.

    4. 04
      Enforce rule I7 in CI

      Add agentlint check to pull requests so nobody can push CLAUDE.md past 40,000 characters again.

    Automated AgentLint Checks That Catch This

    Frequently Asked Questions

    Does Claude Code throw an error when CLAUDE.md passes 40,000 characters?

    No hard crash occurs — the content past 40,000 characters is silently truncated with only a subtle warning, so teams rarely notice until an agent breaks a bottom-of-file rule.

    Are @import files counted toward the total injected memory budget?

    Yes. Even when individual files stay under 40,000 characters, transitive @include chains inflate the total injected context budget tracked by AgentLint rule I8.

    Related Troubleshooting Guides