DEV Community

myougaTheAxo
myougaTheAxo

Posted on • Originally published at zenn.dev

Context Management in Claude Code: Keep AI Accurate Across Sessions

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
Enter fullscreen mode Exit fullscreen mode

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
Enter fullscreen mode Exit fullscreen mode

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)
Enter fullscreen mode Exit fullscreen mode

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"
Enter fullscreen mode Exit fullscreen mode

Sub-Agents for Context Isolation

Main context (clean)
  -> Sub-agent: research
     -> Write results to memory/
Enter fullscreen mode Exit fullscreen mode

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)