Agentic Loop
Understand the LLM + System Prompt + Context + Tools loop — the same design pattern behind Claude Code and Cursor.
Inspired by Claude Code's architecture. From first principles to production. 17 chapters, fully open source.
A fully functional CLI coding agent with these capabilities:
🤖 Smart Conversations — Multi-turn chat via OpenAI-compatible APIs with thinking display and auto-collapse
📂 File Operations — Read, write, edit, search, glob — the agent autonomously operates on your codebase
⚡ Command Execution — Shell command execution with permission control and user confirmation
🧠 Context Management — Token counting, auto-compaction, session persistence — break through context window limits
🎨 Interactive UI — Syntax highlighting, Markdown rendering, themes, command completion, code block copy
🧩 Extensible Architecture — MCP protocol, custom commands, hooks system — designed for real-world use
┌──────────────────────────────────────────────────────────┐
│ CLI Entry (yargs) │
│ ↓ │
│ Agent Loop ←──────────────────────────────┐ │
│ ├─ Build Context (messages + tools) │ │
│ ├─ Call LLM (streaming) │ │
│ ├─ Parse Response │ │
│ │ ├─ text → render to UI │ │
│ │ └─ tool_calls → Execution Pipeline │ │
│ │ ├─ 1. Discovery │ │
│ │ ├─ 2. Permission │ │
│ │ ├─ 3. Pre-Hooks │ │
│ │ ├─ 4. Confirmation (UI) │ │
│ │ ├─ 5. Execute │ │
│ │ ├─ 6. Post-Hooks │ │
│ │ └─ 7. Format │ │
│ └─ Inject Results ──────────────────────┘ │
│ │
│ Store (Zustand) ← → UI (Ink/React) ← → Theme Manager │
│ Context Manager ← → Token Counter ← → Compaction │
│ MCP Registry ← → External Tool Servers │
└──────────────────────────────────────────────────────────┘Not a toy project. Architecture modeled after Anthropic's Claude Code — permission system, hooks, MCP integration.
From Hello World to a complete agent. Every chapter has runnable code. Understand why every line exists.
TypeScript strict mode, Zod runtime validation, complete error handling, AbortController cancellation.
npm install -g clawdcode and go. Not just a tutorial — it's a working coding agent you can use today.
# Install
npm install -g clawdcode
# Configure
export OPENAI_API_KEY=sk-...
# Use
clawdcode "analyze the architecture of this project"