high severityclaude-code

    Claude Code Ignores CLAUDE.md Rules — 5 Root Causes & Instant Fixes

    Symptom: Claude Code starts cleanly yet repeatedly violates rules written right inside CLAUDE.md.

    Direct-Answer Fix Summary

    Claude Code ignores CLAUDE.md rules for five mechanical reasons: wrong path or filename casing (e.g. claude.md on Linux), silent truncation past 40,000 characters, instruction overload past ~150 directives (IFScale decay), shouting emphasis keywords everywhere (diluting priority), or bare prohibitions without an alternative and reason.

    Broken vs. Fixed Configuration

    Broken: Bloated, shouting, no alternatives
    # Rules
    You are a 10x senior engineer. ALWAYS write clean code!
    CRITICAL: NEVER break tests!
    IMPORTANT: NEVER use npm!
    IMPORTANT: MUST follow architecture!
    (... 420 more lines of prose wiki ...)
    Fixed: Concise, falsifiable, Don't / Instead / Because
    # Checkout API
    TypeScript + Node 22 service.
    
    ## Verification
    - Fast single test: npx vitest run src/billing/webhook.test.ts
    - Typecheck: npx tsc --noEmit
    
    ## Hard Boundaries
    - Don't run npm install. Instead run pnpm install --frozen-lockfile. Because npm overwrites pnpm-lock.yaml and breaks CI.
    - When editing Prisma schemas, read docs/migrations.md before running commands.

    Why This Happens

    Claude Code discovers CLAUDE.md upward from the current working directory and merges root, parent, and user memory. When a file exceeds MAX_MEMORY_CHARACTER_COUNT (40,000 chars), sits in an unvisited nested directory, or packs 200+ vague bullets filled with IMPORTANT/NEVER, instruction adherence collapses sharply.

    Step-by-Step Fix

    1. 01
      Verify exact filename and working directory

      Ensure the file is named CLAUDE.md (uppercase) at the Git repository root and launch Claude Code from inside the repository.

    2. 02
      Check the 40,000-character hard limit

      Run wc -c CLAUDE.md or open the AgentLint Token Counter. Anything after character 40,000 is truncated before the prompt reaches Claude.

    3. 03
      Rewrite bare prohibitions with Don't / Instead / Because

      Anthropic's 265 prompt versions show models comply far more reliably when a ban names the concrete replacement command and consequence.

    4. 04
      Move deterministic rules into hooks or CI

      Never rely on prose alone for formatting, linting, or forbidden commands — enforce them with PostToolUse hooks or CI gates.

    Automated AgentLint Checks That Catch This

    Frequently Asked Questions

    Does Claude Code read lowercase claude.md on Linux CI or macOS?

    macOS default filesystems are case-insensitive so claude.md may work locally, while Linux containers and GitHub runners are case-sensitive and will skip it. Always use uppercase CLAUDE.md.

    How many lines should CLAUDE.md be for best compliance?

    Empirical data across 4,533 repos shows a median of 132 lines, and top-scoring exemplars stay between 60 and 180 lines with conditional pointers to subsystem docs.

    Related Troubleshooting Guides