Claude Code From Scratch
Description
Build an AI Coding Agent from Scratch — Learning Context Engineering Step by Step. Companion code for the book.
Installation
This entry records only its repository, not the path inside it, so there is no
exact command to give. Open the source below and copy the folder into
~/.claude/skills/, or the file into ~/.claude/agents/.
README
Claude Code from Scratch — Chapter 4
**Conversation Management: The Art of Multi-Turn Context**
Tag: `ch04-conversation-management` | Version: `0.4.0`
What's New in This Chapter
Building on Chapter 3's multi-turn CLI, this chapter adds:
- Conversation persistence (
core/history.ts) — save/load conversations as JSON files to disk - Resume conversations —
--resumeflag or/resumecommand to pick up where you left off - Conversation IDs — each conversation gets a unique ID for tracking
- Auto-save on exit — conversations are automatically saved when you quit
- Budget warnings — caution at 60% window utilization, critical at 80%
- History browser —
/historylists saved conversations,/resume [id]loads one
Context Engineering Concepts
- The stateless illusion — LLMs have zero memory; continuity comes from resending the full history
- Message array = state — the conversation's messages array IS the complete state
- Context pressure — history grows ~500-2000 tokens per turn while the window stays fixed
- Persistence — saving the message array to disk bridges the gap between sessions
- Long conversation strategies — sliding window, summarization, selective retention (theory; implemented in Ch 10)
Run It
npm install
npm start # Start a new conversation
npm start -- --resume # Resume the most recent conversation
Commands
| Command | Action |
|---|---|
/save |
Save the current conversation to disk |
/history |
List all saved conversations |
/resume [id] |
Resume a saved conversation (most recent if no ID) |
/clear |
Start a fresh conversation |
/stats |
Show conversation statistics and budget status |
/prompt |
Display the system prompt |
quit |
Auto-save and exit |
Project Structure
claude-from-scratch/
├── src/
│ ├── index.ts # CLI with persistence and budget warnings
│ ├── config.ts # Mod
Related Skills
Agency Agents
A complete AI agency at your fingertips - From frontend wizards to Reddit community ninjas, from whimsy inject
AI Firecrawl
🔥 The API to search, scrape, and interact with the web for AI
AI Artifacts Builder
Suite of tools for creating elaborate, multi-component claude.ai HTML artifacts using modern frontend web tech
AI CrewAI
Framework for orchestrating role-playing, autonomous AI agents. By fostering collaborative intelligence, CrewA
AI TrendRadar
⭐AI-driven public opinion & trend monitor with multi-platform aggregation, RSS, and smart alerts.🎯 告别信息过载,你的
AI mem0
| Universal memory layer for AI Agents | 51341 | 221 | 1 |
AI