Original Reddit post

Most “optimize Claude Code” content stops at scattered tips — “keep CLAUDE.md short”, “/clear often”. Correct, but they’re consequences of a deeper mental model. Get the model and you derive the tips instead of memorizing them. Two failure modes, different in nature

  • Amnesia (between sessions): every session you re-explain “use PGlite, no mocks”, “I’m senior, skip tutorials”. Next session, gone.
  • Context rot (within a session): long session, Claude repeats old mistakes and hallucinates. Anthropic’s official term: “attention gets spread across more tokens, stale material sticks around and competes with the task you actually care about now”. These need two different tools — most blog posts conflate them and confuse readers. Mental model: information lives in 3 places:
  • One is CLAUDE.md you hand-write, loaded at the start of every session.
  • Two is MEMORY.md
  • topic files Claude writes itself (Auto Memory) — index always loaded, detail files on-demand.
  • Three is the live context window. Each has different rules — mixing columns is the bug.

CLAUDE.md — hard rules for every session Anthropic’s principle: “Hooks are deterministic; CLAUDE.md is advisory.” Must happen every time, no exceptions (format, lint, block sensitive writes) → hooks. Needs judgment (style, architectural patterns) → CLAUDE.md. Stuffing linter rules into CLAUDE.md wastes tokens AND is less deterministic than an actual linter. Anthropic, blunt: “Never send an LLM to do a linter’s job — expensive, slow, pollutes your context”. Top anti-pattern: CLAUDE.md too long. Anthropic confirms: “If it’s too long, Claude ignores half because important rules get lost in the noise”. Practical rule: <300 lines, shorter is better. HumanLayer’s root CLAUDE.md (case Anthropic references) is ~60 lines. Test before adding anything: applicable to every task? not derivable from codebase? not automatable as a hook? All three “yes” → put it in. One “no” → drop it. 2. Auto Memory — Claude learns itself, v2.1.59+ Run claude --version — if ≥ 2.1.59 it’s on by default. Claude saves notes about build commands, debugging insights, architecture, style preferences, workflow habits. Structure: MEMORY.md is the always-loaded index, topic files load on-demand. Hard cap 200 lines or 25KB. Exceed → only first 200 lines load, with warning. It’s a table of contents, not a knowledge base — don’t stuff everything. Let Auto Memory decide. Force-remember with an explicit “remember this”. 3. Context window — in-session hygiene Anthropic distinguishes them clearly: /clear when switching tasks — reset, fresh start. /compact when continuing same task — summarize, continue on summary. Power move most miss: /compact <instructions>. Example: /compact Focus on API changes, drop debugging history. You direct the summarization instead of letting it guess. Manual /compact with focus often beats passive auto-compact because you know the next direction and the AI doesn’t. When to push? /compact at 70-90% context fill, /clear at 90%+ as last resort. Past 70% precision degrades, past 85% hallucinations rise noticeably. /clear between unrelated tasks is far cheaper than your 4th /compact in the same session. Source: https://docs.claude.com/en/docs/claude-code/memory https://code.claude.com/docs/en/best-practices https://www.anthropic.com/engineering/effective-context-engineering-for-ai-agents https://www-cdn.anthropic.com/58284b19e702b49db9302d5b6f135ad8871e7658.pdf submitted by /u/lawnguyen123

Originally posted by u/lawnguyen123 on r/ClaudeCode