---
title: "Claude Code β Context & Sessions Diagrams"
description: "Context zones, memory hierarchy, session management, and fresh context patterns"
tags: [context, sessions, memory, optimization]
---
# Context & Sessions
How Claude Code manages context, memory, and sessions across your work.
---
### Context Management Zones
Your context window has 4 distinct zones, each requiring different strategies. Knowing which zone you're in prevents context bloat and maintains response quality throughout long sessions.
```mermaid
flowchart LR
subgraph GREEN["π’ 0β50% β Comfortable"]
G1(Full capabilities
available)
G2(All tools active)
G3(Rich responses)
end
subgraph BLUE["π΅ 50β75% β Normal"]
B1(Monitor usage)
B2(Consider /compact
for old threads)
B3(Normal operation)
end
subgraph ORANGE["π 75β85% β Caution"]
O1(Suggest /compact
proactively)
O2(Reduce verbosity)
O3(Defer non-critical
operations)
end
subgraph RED["π΄ 85β100% β Critical"]
R1(Auto-compact
triggered at 80%)
R2(Essential ops only)
R3(Start new session
for new tasks)
end
GREEN --> BLUE --> ORANGE --> RED
style G1 fill:#7BC47F,color:#333
style G2 fill:#7BC47F,color:#333
style G3 fill:#7BC47F,color:#333
style B1 fill:#6DB3F2,color:#fff
style B2 fill:#6DB3F2,color:#fff
style B3 fill:#6DB3F2,color:#fff
style O1 fill:#E87E2F,color:#fff
style O2 fill:#E87E2F,color:#fff
style O3 fill:#E87E2F,color:#fff
style R1 fill:#E85D5D,color:#fff
style R2 fill:#E85D5D,color:#fff
style R3 fill:#E85D5D,color:#fff
click G1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "0-50%: Full capabilities"
click G2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "0-50%: All tools active"
click G3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "0-50%: Rich responses"
click B1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "50-75%: Monitor usage"
click B2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "50-75%: Consider /compact"
click B3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "50-75%: Normal operation"
click O1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "75-85%: Suggest /compact"
click O2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "75-85%: Reduce verbosity"
click O3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "75-85%: Defer non-critical"
click R1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "85-100%: Auto-compact"
click R2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "85-100%: Essential ops only"
click R3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "85-100%: Start new session"
```
ASCII version
```
0%ββββββ50%ββββββ75%ββ85%ββ100%
β Green β Blue β Orangeβ Redβ
β Full β Normal βSuggestβAutoβ
β access βMonitor βcompactβcmp β
β β βReduce βEss.β
β β βverbos.βonlyβ
```
> **Source**: [Context Management](../ultimate-guide.md#context-management) β Line ~1335
---
### Memory Hierarchy β 6 Types
Claude Code has 6 distinct memory types with different scopes and persistence. Knowing which memory type to use for each piece of information is key to effective sessions.
```mermaid
flowchart TD
A["π Global CLAUDE.md
~/.claude/CLAUDE.md"] --> B["π Project CLAUDE.md
/project-root/CLAUDE.md"]
B --> C["π Subdirectory CLAUDE.md
/src/CLAUDE.md, /tests/CLAUDE.md"]
C --> AM["π§ Auto-Memory Native
~/.claude/projects/*/memory/MEMORY.md
v2.1.59+"]
AM --> D["π¬ In-Conversation Context
Messages + tool results this session"]
D --> E["β‘ Ephemeral State
MCP server state, tool cache"]
A1["Scope: ALL projects
Persists: Always
Use: Global prefs, API keys"] --> A
B1["Scope: This project
Persists: Always
Use: Project conventions"] --> B
C1["Scope: This directory
Persists: Always
Use: Module-specific rules"] --> C
AM1["Scope: Per project
Persists: Cross-session
Use: Auto-saved memories, /memory"] --> AM
D1["Scope: This session
Persists: Session only
Use: Task context"] --> D
E1["Scope: This session
Persists: Session only
Use: Computed results"] --> E
style A fill:#E87E2F,color:#fff
style B fill:#6DB3F2,color:#fff
style C fill:#6DB3F2,color:#fff
style AM fill:#7BC47F,color:#333
style D fill:#F5E6D3,color:#333
style E fill:#B8B8B8,color:#333
style A1 fill:#B8B8B8,color:#333
style B1 fill:#B8B8B8,color:#333
style C1 fill:#B8B8B8,color:#333
style AM1 fill:#B8B8B8,color:#333
style D1 fill:#B8B8B8,color:#333
style E1 fill:#B8B8B8,color:#333
click A href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Global CLAUDE.md"
click B href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Project CLAUDE.md"
click C href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Subdirectory CLAUDE.md"
click AM href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#22-auto-memory-v21594" "Auto-Memory Native"
click D href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "In-Conversation Context"
click E href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/architecture.md#3-context-management-internals" "Ephemeral State"
click A1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Global scope β always persists"
click B1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Project scope β always persists"
click C1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#21-claudemd-three-levels" "Directory scope β always persists"
click AM1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/memory-systems.md#22-auto-memory-v21594" "Cross-session auto-memory"
click D1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Session scope only"
click E1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/core/architecture.md#3-context-management-internals" "Session scope only"
```
ASCII version
```
PERMANENT ββββββββββββββββββββββββββββββββ SESSION ONLY
~/.claude/CLAUDE.md In-conversation context
β β
/project/CLAUDE.md Ephemeral MCP state
β
/subdir/CLAUDE.md
β
Auto-Memory (MEMORY.md) β cross-session, per project
Higher = broader scope, always persists
Lower = narrower scope, survives restarts
Auto-Memory = persists cross-session, scoped per project
```
> **Source**: [Memory System](../ultimate-guide.md#memory-system) β Line ~3160 & ~3986 | Auto-Memory: v2.1.59+ (v3.30.0)
---
### Session Continuity β Saving and Resuming State
Sessions don't automatically persist context between terminals. This diagram shows how to save state and resume it in a new session or terminal, enabling async workflows.
```mermaid
sequenceDiagram
participant U as User
participant CC as Claude Code
participant CM as CLAUDE.md
participant NI as New Session
U->>CC: Work on feature X
CC->>CC: Executes tasks, tools
U->>CC: Save progress to CLAUDE.md
CC->>CM: Write: task status, decisions, next steps
Note over CM: Persists after session ends
U->>NI: Open new terminal
U->>NI: claude (new session)
NI->>CM: Auto-loads CLAUDE.md
CM->>NI: Injects: saved context
NI->>U: Ready β context restored β
Note over CC,NI: Conversation history NOT restored
Only CLAUDE.md content persists
```
ASCII version
```
Session 1 CLAUDE.md Session 2
βββββββββ βββββββββ βββββββββ
Work on task β Open terminal
β β β
Save progress βββββββββββββββΊ Write Load CLAUDE.md
status, βββ Auto-injected
decisions,
next steps
```
> **Source**: [Session Management](../ultimate-guide.md#session-management) β Line ~9477
---
### Fresh Context Anti-Pattern vs. Best Practice
Long sessions accumulate noise that degrades response quality. This diagram shows the degradation pattern and the recommended "focused sessions" approach that maintains performance.
```mermaid
flowchart TD
subgraph BAD["β Anti-Pattern: Monolith Session"]
B1([Start big session]) --> B2(Add task A)
B2 --> B3(Add task B)
B3 --> B4(Add task C)
B4 --> B5{Context bloated
>75%}
B5 --> B6(Response quality
degrades)
B6 --> B7(Force-restart
loses all context)
style B1 fill:#E85D5D,color:#fff
style B5 fill:#E85D5D,color:#fff
style B6 fill:#E85D5D,color:#fff
style B7 fill:#E85D5D,color:#fff
end
subgraph GOOD["β
Best Practice: Focused Sessions"]
G1([Start focused session]) --> G2(Complete task A)
G2 --> G3{Natural
checkpoint?}
G3 -->|Yes| G4(Save to CLAUDE.md)
G4 --> G5([New session for task B])
G3 -->|No| G6{Context >75%?}
G6 -->|Yes| G7(/compact)
G7 --> G2
G6 -->|No| G2
style G1 fill:#7BC47F,color:#333
style G4 fill:#7BC47F,color:#333
style G5 fill:#7BC47F,color:#333
style G3 fill:#E87E2F,color:#fff
style G6 fill:#E87E2F,color:#fff
style G7 fill:#6DB3F2,color:#fff
end
click B1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Anti-Pattern: Monolith Session"
click B2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Add task A"
click B3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Add task B"
click B4 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Add task C"
click B5 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Context bloated >75%"
click B6 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Response quality degrades"
click B7 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Force-restart β loses context"
click G1 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Best Practice: Focused Sessions"
click G2 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Complete task A"
click G3 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Natural checkpoint?"
click G4 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#31-memory-files-claudemd" "Save to CLAUDE.md"
click G5 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "New session for task B"
click G6 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "Context >75%?"
click G7 href "https://github.com/FlorianBruniaux/claude-code-ultimate-guide/blob/main/guide/ultimate-guide.md#22-context-management" "/compact"
```
ASCII version
```
BAD: One giant session
Task A β Task B β Task C β Context bloat β Quality drop β Restart β Lost!
GOOD: Focused sessions
Task A βββΊ Checkpoint? ββYesβββΊ Save CLAUDE.md βββΊ New session for B
β
No
β
Context >75%? ββYesβββΊ /compact βββΊ Continue
β
No
β
Continue task
```
> **Source**: [Context Best Practices](../ultimate-guide.md#context-best-practices) β Line ~1525