Verification Source: AI companion bot + multiple agent sessions (2026-03) Validity Conditions: Long-term projects where context must persist across sessions
Core Principles
Agent sessions will inevitably break. Context must live in files. Do not trust the agent's memory.
A new session's agent has no memory of the previous session. Context not in files must be recreated every session.
Context Layer Structure
A well-structured agent project manages context in multiple layers.
Layer 1: Immutable identity → CLAUDE.md (project purpose, constraints, Core file list)
Layer 2: Accumulated patterns → accumulated_context.md (verified behavioral patterns + user characteristics)
Layer 3: Real-time state → Session summaries / PD reports (what happened today)
Layer 4: Memory search → Vector DB / searchable logs (reference specific past conversations)
Layer 5: Work progress state → task_lessons.md / loop_state.json (how far have we gotten)
Layer 6: Agent self-awareness → bot_accumulated.md or similar agent self-narrative (optional)
Not all layers are necessary. The minimum configuration is Layers 1 + 3.
Session Bootstrap Protocol
Specify the reading order for new agent sessions in CLAUDE.md.
Recommended Reading Order
1. CLAUDE.md — "What project am I in right now"
2. accumulated_context.md — "What are the verified patterns with this person/system"
3. Latest state file — "What happened in the last session"
4. Current task file — "What do I need to do right now"
Why this order: Identity (1) → Relationship (2) → Present (3) → Action (4). If this order is reversed, the agent acts without context or misjudges the present based on outdated information.
CLAUDE.md Sync Rules
When CLAUDE.md diverges from reality, new agents work in the wrong direction. This is context drift.
When Drift Occurs
Drift Prevention Rules
Drift Detection Method
git log --oneline -10 # Compare recent commits against CLAUDE.md's "Current Implementation Status"
If commits are ahead but CLAUDE.md reflects an old state, drift has occurred.
Accumulated Context Management (accumulated_context.md)
The file where verified patterns accumulate in long-term projects. Management principles:
- Write criterion: "Have I confirmed this pattern 3+ times, and will it remain valid in the next session?"
- Delete criterion: If circumstances have changed and it's no longer valid, remove immediately (stale entries = contamination)
- Size limit: When it starts exceeding 50 lines, compression/deduplication is needed. The longer it gets, the more likely agents will ignore it entirely.
- Strictly forbidden: Agents arbitrarily resetting or restructuring this file
Anti-Pattern: Context Contamination
The most dangerous situation in agent projects is outdated/incorrect information persisting in Core files.
Contamination symptoms:
- Agent incorrectly assumes "already known facts"
- Outdated rules corrupt current decisions
- Two files contain contradictory information
Contamination prevention:
- When new information conflicts with existing files → open the existing file first to check for conflicts
- Explicitly annotate "possibly contaminated" files: "Caution: 60% contaminated, reference only"
- Periodically compare Core files against current state