中文 | English
- Readers entering this repo for the first time
- Readers who do not yet understand Claude Code startup flow
- Readers without an API key
60-90 minutes
This stage narrows the work to the three things that happen before a request really enters the main loop:
- how Claude Code decides which runtime mode to enter
- what
setupfinishes before the loop begins - why this is the wrong moment to dive into tools, streaming, or memory
Mainline position: user input → startup / mode routing
This page does not ask you to trace the whole request lifecycle yet. It asks you to stabilize the entry:
- CLI arguments, working directory, and run mode decide which surface to enter
setupprepares the baseline environment for later execution- only after those steps are stable does
query/queryLoopget a trustworthy entry point
If you dive into tool execution or UI streaming here, the cognitive load jumps too early.
Run l1_startup.py until it feels obvious:
python examples/l1_startup.py
python examples/l1_startup.py --print "hello"
python examples/l1_startup.py serveIf you want proof that later layers exist, do a light preview only:
python examples/l3_tool_system.py
python examples/l4_ui_ink.pyThose previews are not obligations in this stage. They only show that more layers come later.
Read in this order:
If you only want a preview of later stages, skim:
Keep this stage tight and open only the two files closest to the entry:
claudecode_src/src/main.tsx— where CLI arguments and mode routing choose a runtime surfaceclaudecode_src/src/setup.ts— where initialization finishes before the loop begins
If you encounter runHeadless, serve, or REPL while searching, treat them as routing outcomes first instead of expanding into every later implementation.
Deliberately ignore these topics for now:
- the full tool registration and execution machinery
- the full single-turn
query/queryLooppath - streaming implementation details
- memory, prompt cache, and multi-agent
- fine-grained REPL state organization
This page should reduce cognitive load. Build the “how the request enters the system” spine first.
In this stage, search these four first:
main_entrysetuprunHeadlessserve
If you still have bandwidth, then add:
buildToolREPL
- Where does Claude Code decide between REPL, print, serve, and other runtime surfaces?
- Why must mode dispatch happen before the agent loop really begins?
- Why should setup-style initialization not be scattered later in the execution chain?
Use this sequence:
- open source-map: startup path
- use source-navigation to search
main_entryandsetup - open
main.tsxandsetup.tsfirst
If you want a tighter handoff, open:
By the end of this page, you should be able to:
- explain what startup, initialization, and mode dispatch each own
- locate the key symbols above in the source
- explain in your own words why Claude Code is not a single giant script
- know clearly that this is still not the moment to dive into tools, streaming, or memory
If you cannot, go back to:
L1if REPL, print, and serve are still blurred together- the startup section in
source-mapif the call chain still feels unstable
This whole stage is designed to work offline.
Continue to P2 Core Loop