๐พ Layer 5: State Layer
<div align="center">
Overview
๐ Home โบ ๐ง Implementation โบ ๐๏ธ Architecture โบ ๐พ Layer 5: State
โ โก Execution Layer โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Architecture โ
</div>๐พ Layer 5: State Layer
Persistence, memory, and context management across interactions.
Purpose
The State Layer manages all persistent data and context. It enables sessions to maintain state, resume from interruptions, and share information across components.
Components
| Component | Emoji | Type | Scope |
|---|---|---|---|
| Memory | ๐พ | In-session context | Conversation |
| Files | ๐ | Persistent storage | Project |
| CLAUDE.md | ๐ | Project instructions | Project |
| Checkpoints | ๐ฅ๏ธ | Resume points | Workflow |
State Flow Diagram
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart TB
classDef state fill:#10b981,stroke:#059669,stroke-width:2px,color:#ffffff
classDef main fill:#8b5cf6,stroke:#7c3aed,stroke-width:2px,color:#ffffff
classDef tool fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#ffffff
subgraph StateLayer["๐พ State Layer"]
MEM["๐พ Session Memory"]:::state
FILES["๐ File System"]:::state
CLAUDE["๐ CLAUDE.md"]:::state
CHECK["๐ฅ๏ธ Checkpoints"]:::state
end
EXEC["โก Execution Layer"]:::tool -->|Reads/Writes| FILES
EXEC -->|Updates| MEM
EXEC -->|Saves| CHECK
MA["๐ Main Agent"]:::main -->|Loads| CLAUDE
MA -->|Accesses| MEM
MA -->|Resumes from| CHECK
classDef stateBox fill:#ecfdf5,stroke:#10b981,stroke-width:2px,color:#065f46
StateLayer:::stateBox
๐พ Session Memory
In-session context that persists throughout a conversation.
What It Stores
- Conversation history
- Current task state
- Intermediate results
- User preferences from session
Scope
- Lifetime: Single conversation session
- Access: ๐ Main Agent and ๐ฆ Subagents
- Persistence: Lost when session ends
๐ File System
Persistent storage for project files and outputs.
Operations
| Operation | Tool | Description |
|---|---|---|
| Read | ๐ง๐ Read | Load file contents |
| Write | ๐งโ๏ธ Write | Create/overwrite files |
| Edit | ๐งโ๏ธ Edit | Modify existing files |
| Search | ๐ง๐๏ธ Glob | Find files by pattern |
| Search | ๐ง๐ Grep | Find content in files |
Scope
- Lifetime: Permanent (until deleted)
- Access: All layers via tools
- Persistence: Project-level
๐ CLAUDE.md
Project-specific instructions loaded at session start.
Hierarchy
~/.claude/CLAUDE.md # Global (user-level)
./CLAUDE.md # Project root
./src/CLAUDE.md # Directory-specific
Purpose
- Define project conventions
- Specify coding standards
- Configure tool preferences
- Set workflow defaults
๐ฅ๏ธ Checkpoints
Resume points for long-running workflows.
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
flowchart LR
classDef checkpoint fill:#f59e0b,stroke:#d97706,stroke-width:2px,color:#ffffff
subgraph Workflow
P1["๐๏ธ Phase 1"] --> CP1["๐ฅ๏ธ Checkpoint"]:::checkpoint
CP1 --> P2["๐ Phase 2"]
P2 --> CP2["๐ฅ๏ธ Checkpoint"]:::checkpoint
CP2 --> P3["๐ Phase 3"]
end
FAIL["โ Failure/Interrupt"] -.->|Resume from| CP2
Checkpoint Data Structure
{
"workflow_id": "wf_2025_001",
"current_phase": 2,
"completed_tasks": ["task_1", "task_2"],
"pending_tasks": ["task_3", "task_4"],
"state": {
"variables": {},
"context_summary": "..."
},
"resume_point": "checkpoint_2",
"timestamp": "2025-11-28T10:00:00Z"
}
Use Cases
| Scenario | Why Checkpoints? |
|---|---|
| Large-scale generation | 1000+ files exceed context limits |
| Long research tasks | Days of research need persistence |
| Multi-day workflows | Cannot complete in single session |
| Error recovery | Resume after failures |
| Team handoffs | Different operators continue work |
State Interaction Example
%%{init: {'theme': 'base', 'themeVariables': {'lineColor': '#64748b'}}}%%
sequenceDiagram
participant MA as ๐ Main Agent
participant EL as โก Execution
participant SL as ๐พ State Layer
MA->>SL: Load ๐ CLAUDE.md
SL-->>MA: Project instructions
MA->>EL: Execute task
EL->>SL: Read source files
SL-->>EL: File contents
EL->>SL: Write output files
EL->>SL: Update ๐พ memory
MA->>SL: Save ๐ฅ๏ธ checkpoint
SL-->>MA: Checkpoint saved
Layer Position
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ โก LAYER 4: EXECUTION LAYER โ
โ ๐ฆ Subagents, ๐ง Built-in, ๐ External, ๐โโ๏ธ User โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโฌโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ
โผ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
โ ๐พ LAYER 5: STATE LAYER โโโโ YOU ARE HERE โ
โ Memory, Files, Context - persistence โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
<div align="center">
โ โก Execution Layer โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Architecture โ
</div>