build-code-agent is a reading guide to an agent CLI, not a framework
从零构建 Code Agent:Claude Code 源码深度解析 | Build a Code Agent from Scratch: Deep Dive into Claude Code Source
At a glance
- What is it?
- build-code-agent is a 24-unit course written in Chinese that dissects the source of an AI coding agent, covering the agent loop, the tool registry, streaming execution, context compression, permissions, hooks, MCP and multi-agent coordination, and it ships three complete practice projects in TypeScript. It is documentation about someone else's code, and the licence and provenance are worth understanding before you rely on it.
- Who is it for?
- build-code-agent suits a developer who already writes TypeScript and wants to understand how a production coding agent is put together, and the three practice projects give that reading a concrete shape. It is the wrong tool if you need official API documentation, if you need code you can ship commercially, since the licence is CC BY-NC-SA 4.0, or if you are unwilling to work from source that circulated outside the vendor.
- Can I use it commercially?
- Not without permission. GitHub finds no licence file in the repository, and without a licence all rights are reserved by default: you may read the code but not reuse it. Check the README, or ask the authors, before using it.
- Is it still maintained?
- Yes. The repository last received commits 85 days ago.
- What is it written in?
- GitHub does not report a main language for this repository.
Answers come from the project's GitHub data, last synced on October 22, 2026, and from our analysis. They are not legal advice.
Editorial analysis
A course built from reading somebody else's source
The repository is a course, not a library. It is a systematic course for developers that walks through the real source of a flagship AI coding agent layer by layer, covering 7 modules, 22 core chapters and 3 practice projects, and every chapter carries real source references with file paths and line numbers.
The subject is Claude Code, described as a complete engineering system rather than a chatbot, one that can read files, write code, run commands and schedule several sub agents to collaborate. The course takes it apart as an engineering system: the agent loop, an AsyncGenerator streaming architecture, a streaming tool executor for concurrent execution, a tool system of 40 built-in tools with a buildTool factory pattern, and a three layer context model with four compression strategies.
The scale is stated precisely in the README, which is unusual and useful. There are 24 teaching units, the opening chapter plus 22 chapters plus a conclusion, 40,055 lines of Markdown, and 142 infographics in one consistent hand-drawn style organised in four levels, two book level, seven module level, 24 chapter level and 109 within-chapter.
What it is not is a framework. Nothing here installs into your project. The value is in the reading, and in the three projects that follow it.
The first two modules: the loop, the tools and the executor
Module one covers architecture and startup, module two the tool system, and between them they set out the parts an agent is made of.
The architecture chapter frames the whole thing as a panorama with a seven subsystem design, and compares paradigms and design philosophy. The CLI bootstrap chapter follows the path from the command line to the REPL, naming Commander.js, four phases of initialisation, adaptation to several environments and the 86 commands the tool exposes. The agent loop chapter gets to the heart: the main loop of the query function as a while(true) construct, the QueryEngine, the AsyncGenerator pipeline, the termination conditions and the error recovery.
Module two then opens the tool surface. The abstraction chapter covers the core fields of the Tool interface, the ToolUseContext and a classification of 40 tools. The core tools chapter looks at BashTool, FileEditTool, AgentTool, Grep and Glob, and WebFetch individually. The final chapter of the module, on the streaming execution engine, deals with concurrency safety, the split between serial and parallel work, and how an AbortController is propagated through the system.
For a reader building an agent, that last chapter is where the design questions live. Deciding what runs in parallel and what must be serial, and how cancellation reaches work already in flight, is the difference between a demo and something that behaves under load.
Context, memory and what it costs
Module three deals with the part of an agent that is hardest to design and easiest to get wrong.
The conversation context chapter describes a three layer architecture: how the system prompt is assembled, a five level CLAUDE.md loading scheme, and compatibility with AGENTS.md, which is the cross-vendor convention other tools also use. The context compression chapter sets out four strategies, autoCompact, microCompact, apiMicrocompact and sessionMemoryCompact, together with cost tracking and a token budget.
The memory chapter adds SessionMemory for cross-session memory, MagicDocs, AgentSummary and a DreamTask, and the source reference for the source itself is described as one of Claude Code's subsystems.
The four compression strategies are the interesting part, because they represent four different answers to the same question. Compact at the session level, compact within a single request, compact through the API path, or compact from a persisted memory. A course that names all four and shows the file paths gives you a map of the design space rather than a slogan about context windows.
The cost tracking and token budget work is the other half. An agent that can run a hundred tool calls in a session needs a way to know what that session has cost, and the course treats that as a first-class subsystem rather than an afterthought.
Permissions, hooks and the machinery around them
Module four is where the course gets into the part that matters when an agent runs with your permissions.
The permission system chapter describes 5 modes plus 2 more, and what it calls a multi way race: the useCanUseTool hook, three kinds of handler, a createResolveOnce mechanism and channel permissions. The hooks chapter covers 27 events across 5 handler types, naming them as command, http, mcp_tool, prompt and agent, along with the infrastructure that backs them.
Twenty seven hook events is a lot of surface, and that is the point. An agent that can read files, run commands and call out to services needs extension points at each of those seams, otherwise a team either gives up the ability to intercept behaviour or gives up the behaviour.
The multi way race description for permissions is worth a second look, since it describes a design where several sources of permission can answer at once. In an implementation like that, the ordering and the once-only resolution are where bugs live, and a chapter that names createResolveOnce by name is pointing at the mechanism rather than the outcome.
The course is explicit that it is teaching the implementation of one system, not a specification. There is no claim here that these five modes and 27 events are how agents should be built, only how this one is built.
The extension ecosystem: MCP, skills, plugins and slash commands
Module five covers the surfaces through which an agent is extended, and the numbers here are large.
The MCP chapter works through the protocol from the transport layer inward, covering 8 transport types, the 5 primitives of Tools, Resources, Prompts, Sampling and Elicitation, and authentication with OAuth, PKCE and XAA. The skills chapter covers the 6 possible sources of a skill, a SkillTool, delayed loading through ToolSearch, and the 17 bundled skills, along with how a skill survives compaction. The plugins and commands chapter covers the plugin lifecycle, a catalogue of 86 slash commands and output styles. The terminal UI chapter covers Ink, Vim mode, keybindings, a companion sprite and output styles.
Two of those numbers are worth pausing on. Delayed loading through ToolSearch is the answer to the problem that a large tool set eats the context window, and skill survival across compaction is the answer to the problem that the agent forgets what it was told.
The stack table at the end of the README is also useful as a shopping list for anyone reproducing the exercises: the Anthropic SDK, the Claude Agent SDK, the official MCP SDK, TypeScript 5.x, React with Ink for the terminal UI, commander for CLI parsing, zod for schema validation, and AsyncGenerator as the core of the streaming pipeline.
Multi-agent coordination and the three practice projects
Module six covers advanced behaviour, module seven is where the reader writes code.
The multi-agent chapter describes 7 kinds of task, the Swarm system spread across 14 files, a Coordinator architecture in 6 stages, and Agent Teams. The feature flags chapter covers GrowthBook, the analytics pipeline, a cost tracker and the token budget, and the SDK chapter covers the two interface styles, decorator based tool registration, the functional query form, ClaudeSDKClient, SDKMessage, EntryPoints and LSP integration. The Bridge and Remote chapter covers the web backend, remote sessions, SSH, Teleport, voice and a direct connect path.
The three projects then apply all of it, and their stated sizes are useful for gauging the work involved. MiniAgent is about 800 lines of TypeScript with an agent loop, 4 tools, permissions and context management. The custom MCP server is about 600 lines with 3 tools, 2 resources and 1 prompt. The multi-agent system is about 1000 lines with a Coordinator, 3 workers covering security, performance and style, and task scheduling through SendMessage.
Each project is documented as shipping a complete package.json, a tsconfig.json, all source files, the run commands, test cases, and a mapping back to the Claude Code source. That last element is what makes the projects lessons rather than bare code samples: the comparison table is the lesson.
Provenance, licence and what to check before you rely on it
Two facts about this repository deserve to be read before anything else.
The first is the provenance. The README states that the course is based on a deep analysis of Claude Code v2.1.88 source code circulating online, and it thanks the linux.do community for the information. That is an unofficial analysis of a version of a proprietary product, not vendor documentation. The figures the author has corrected are collected in docs/canonical-numbers.md, which is where to check any number you plan to quote.
The second is the licence. The course content is under CC BY-NC-SA 4.0, which is a non-commercial, share-alike content licence. You can read it, translate it, adapt it and teach from it, and the share-alike condition applies to adaptations. What you cannot do is use it in a commercial training programme or in internal documents for a company without checking the terms. The repository listing does not classify the licence, so the LICENSE information in the README is the place to look.
There is also a note that the project has been upgraded and published as a Juejin book, and that the book was reorganised and improved on the basis of this repository, with text that is not entirely consistent with the repository version, intended as advanced and supplementary reading.
On maintenance, the last push was on 2026-07-30 and the repository is not archived, with no GitHub releases. The top level is 24 Markdown files, an images directory, a cover image and a legacy-v1 directory, which suggests the older version of the course is kept alongside the current one.
Editorial conclusion
build-code-agent suits a developer who already writes TypeScript and wants to understand how a production coding agent is put together, and the three practice projects give that reading a concrete shape. It is the wrong tool if you need official API documentation, if you need code you can ship commercially, since the licence is CC BY-NC-SA 4.0, or if you are unwilling to work from source that circulated outside the vendor. Verify first the version the course analyses against the version you actually use, check docs/canonical-numbers.md for the figures the author has corrected, and read the terms in full before you redistribute any of it inside a company.
Frequently asked questions
What does the build-code-agent course cover?
It is a 24 unit course in 7 modules covering the agent loop, the tool system with 40 built-in tools, context and memory with four compression strategies, permissions and 27 hook events, the MCP protocol with 8 transport types, skills, plugins and slash commands, multi-agent coordination, and the Claude Agent SDK, followed by three practice projects.
Do I need to know TypeScript to follow the build-code-agent course?
The README lists the prerequisites as TypeScript basics that let you read generics, async/await and the decorator pattern, basic terminal skills with npm, git and shell, and basic familiarity with LLM API concepts such as prompt, completion and tool_use. React experience is not required.
Is build-code-agent official Claude Code documentation?
No. The README states that the course is based on a deep analysis of Claude Code v2.1.88 source code that circulated online, and it thanks the linux.do community for the information. Corrected figures are collected in docs/canonical-numbers.md.
Can I use the build-code-agent course content in a company?
The content is licensed under CC BY-NC-SA 4.0, a non-commercial share-alike licence, so you can read, translate and adapt it with attribution and share alike, but commercial use needs the terms checked first.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/jiji262-build-code-agent)Was this useful?