中文 | English
- Readers who already understand the basic loop and are ready for the real source
- Readers who want to move from “I can run the demos” to “I can explain the implementation”
2-3 hours
This stage leaves concept-only understanding behind and reads the stabilized mainline directly:
- how
query.tscarries the single-turn mainline - why
QueryEngine.tsis the session orchestration center instead of a redundant wrapper - how
services/api/claude.tsturns provider streaming into the higher-level event stream
Mainline position: mainline concept is stable → read query.ts → QueryEngine.ts → services/api/claude.ts directly
P2 built the intuition for how one turn moves. P3 compresses that intuition down into the real source.
You are no longer just learning that these concepts exist. You are directly reading the key files to confirm:
- where one request starts advancing
- where orchestration is centralized
- where streaming events are lifted into the upper-level flow
Return to the example closest to the mainline:
python examples/l2_agent_loop.pyIf you have an API key, then add:
python examples/l8_streaming.pyThe goal here is not new concepts. It is to re-anchor the mainline rhythm before you open the real source.
Read in this order:
- L10 QueryEngine And System Prompt Assembly
- L11 API Streaming And The Event Model
- Source Navigation Guide
- Example-To-Source Bridge: l2 / l8
Only after the mainline source feels stable should these become second-layer additions:
Open the three-file mainline set directly:
claudecode_src/src/query.tsclaudecode_src/src/QueryEngine.tsclaudecode_src/src/services/api/claude.ts
Only after you can explain their division of labor should UI become a second-layer addition:
claudecode_src/src/screens/REPL.tsx
Do not spread your attention across these boundary topics yet:
- memory extraction details
- hooks / plugins / MCP extension surfaces
- print / serve / bridge runtime modes
- coordinator / structured-output boundaries
- if the three mainline files are not stable in your head yet, do not open the fine-grained REPL state tree either
P3 exists to keep the mainline stable before you branch outward.
- read
query.tsdeeply - read
QueryEngine.tsdeeply - read
services/api/claude.tsfor the main event-stream path first
screens/REPL.tsxL5L12L9
Do not try to swallow four core files and five deep dives all at once.
system_message_yieldedbefore_getSystemPromptafter_getSystemPromptqueryModelWithStreamingapi_request_sentprocessInitialMessageDO NOT ADD MORE STATE HERE
If you are ready to add context, then also search:
SYSTEM_PROMPT_DYNAMIC_BOUNDARY
- Why is QueryEngine not a redundant wrapper, but the session orchestration center?
- How does API streaming become the higher-level event stream?
- How do
query.ts,QueryEngine.ts, andservices/api/claude.tsdivide the work?
- Exercise 2: why QueryEngine is not redundant
- Exercise 4: streaming events
- if you already added REPL, then do Exercise 5: REPL state boundary
By the end of this page, you should be able to:
- explain the division of labor between
query.ts,QueryEngine.ts, andservices/api/claude.ts - explain where system prompt assembly and event streaming each happen
- search and locate the key symbols above without help
- know clearly that permissions, memory, runtime modes, and coordinator topics belong to the next stage
If this still feels unstable, go back to:
P2if loop, permissions, and streaming still do not connect cleanlyL10if QueryEngine’s role is still blurryL11if the event stream still feels like only API detail
Continue to P4 Advanced Architecture