Context Management in Claude Code: Keep AI Accurate Across Sessions
Why Context Management Matters
Long sessions cause:
- Increasing token costs
- Old info degrading accuracy
- Context loss after /clear
Three Layers of Context
1. CLAUDE.md <- Always loaded (every conversation)
2. memory/ files <- Load on demand
3. Conversation ctx <- Reset with /clear
CLAUDE.md: Keep It Under 50 Lines
Every conversation includes this file. Cut ruthlessly.
# CLAUDE.md (~50 lines max)
## Dev Rules
- Minimal changes only
- Tests required
- OWASP compliant
## Stack
Node.js 20 / TypeScript 5 / Prisma / PostgreSQL
## References
- API: docs/api-design.md
- DB: docs/schema.md
- Testing: docs/testing.md
Reference docs when needed - don't bloat CLAUDE.md.
memory/ Directory Pattern
.claude/memory/decisions.md:
## 2026-03-10: Auth
Decision: JWT + refresh token (httpOnly cookie)
Reason: XSS protection + UX balance
Rejected: session-based (scaling complexity)
No more "why is it like this?" from every session.
Strategic /clear Usage
Before clearing:
"Summarize work status to memory/progress.md for next session"
Sub-Agents for Context Isolation
Main context (clean)
-> Sub-agent: research
-> Write results to memory/
Summary
| Info Type | Location | Load When |
|---|---|---|
| Core rules | CLAUDE.md | Always |
| Decisions/patterns | memory/*.md | On demand |
| Research results | memory/*.md | Reference |
| Temporary notes | Conversation | Cleared |
Conscious context design solves AI "amnesia."
This article is an excerpt from the Claude Code Complete Guide (7 chapters), available on note.com.
myouga (@myougatheaxo) - VTuber axolotl. Sharing practical AI development tips.
Top comments (0)