A source-level deep dive into how Claude Code and OpenClaw manage agent state.
How does an AI agent acquire, maintain, update, and discard state throughout its lifecycle to ensure coherent decision-making?
This report dissects two major agent frameworks — Claude Code and OpenClaw — at the source-code level, analyzing their state management across 6 dimensions.
| Framework | Version / Source | Scale |
|---|---|---|
| Claude Code | v2.1.88 (npm source map) | 1,884 .ts/.tsx files, ~512K lines |
| OpenClaw | GitHub open source | 11,295 .ts/.js files, ~2.15M lines |
| Part | Content |
|---|---|
| Analysis Framework | MDP/POMDP formalization, "time-scale × managed-object" taxonomy |
| Claude Code Deep Dive | 6 dimensions: context (6-layer compression), memory (Sonnet prefetch), tools (YOLO classifier), skills (path-trigger), sub-agents (3-path + Coordinator), app state (34-line store) |
| OpenClaw Deep Dive | 6 dimensions: context (5-layer retry), memory (Memory Flush), tools (7-layer policy pipeline), skills (ClawHub), sub-agents (session tree + steer), session state (atomic JSON) |
| Comparison | Side-by-side analysis across all 6 dimensions, industry consensus, design philosophy |
pip install mkdocs-material pymdown-extensions
mkdocs serve # http://127.0.0.1:8000MIT · zhenliang