Claude Code Source Deep-Dive Tutorial

A structured learning path from zero to advanced, based on a source-map reconstruction of 1,987 TypeScript files from the @anthropic-ai/claude-code npm package.


📚 Tutorial Table of Contents

This tutorial has six main chapters, progressing along three dimensions:

Functionality dimension (what it can do)
    ↓
Architecture dimension (why it is designed this way)
    ↓
Source-code dimension (how it is implemented)

📖 Chapter 1: Global Overview — What is Claude Code?

Best for: beginners who want a complete mental model first


🏗️ Chapter 2: Architecture Design — System Structure and Layering

Best for: readers who understand usage and want system-level design insight


⚙️ Chapter 3: Core Engine — The Agent Conversation Loop

Best for: readers who want to understand how AI agents "think and act"


🔧 Chapter 4: Tool System — Design Philosophy Behind 53 Tools

Best for: readers who want to understand how AI interacts with the real world


🚀 Chapter 5: Advanced Topics — Hidden Features Deep Dive

Best for: readers curious about what Anthropic is building internally


🔒 Chapter 6: Engineering Practices — Release and Quality Control

Best for: readers focused on engineering management and production rollout


🎓 Chapter 7: Summary

🧠 ClaudeCode Walkthrough (Added)


🗺️ Quick Navigation

I want to understand...Jump to
What Claude Code is and what it can doChapter 1
How to read the overall code structure1.3 Source Map
Vim mode keybindings1.4 Vim Mode
How the AI agent main loop works3.2 query.ts Deep Read
How to inject scripts into Claude's decisions3.6 Hooks System
How tool permissions are decided4.3 Permission System
How KAIROS persistent assistant is implemented5.1 KAIROS
How multi-agent orchestration works5.2 Coordinator
Hidden commands/flags/env vars quick lookup5.6 Hidden Command Reference
How feature switches are controlled6.1 Three-Layer Gates
What services exist in services layer6.5 Services Overview
What you can do after finishing this tutorialTutorial Summary

📌 Notes


💡 Suggested reading order: beginners should read chapter by chapter; experienced developers can jump directly to Chapter 3 (query.ts) or Chapter 5 (advanced topics); for quick lookup, use the Quick Navigation table.