DEV Community

Juan Bermudez Roldan
Juan Bermudez Roldan

Posted on • Originally published at code.bluggie.com

The 11 steps that run every time you press Enter in Claude Code

Every time you press Enter in Claude Code, an 11-step loop kicks off. Not a simple request-response — a self-directed cycle that keeps running until the task is done.

I spent a few weeks tracing through the source code and turned what I found into a free course. Here's the condensed version of that loop.

The 11 Steps

Step 1 — Input. You type a prompt. The terminal captures the keypress via a custom React renderer (yes, React in a terminal).

Step 2 — Message. Your text becomes a UserMessage object appended to the conversation history.

Step 3 — Memory. CLAUDE.md files from 4 levels (enterprise → user → project → subdirectory) are loaded and concatenated into the system prompt.

Step 4 — System Prompt. Tool definitions, environment info, and memory are merged into the full system prompt.

Step 5 — API Call. Messages + system prompt + tool definitions stream to the Anthropic API. Tokens come back in real time.

Step 6 — Parse. The response is split into content blocks: text, thinking, and tool_use.

Step 7 — Decision. Does the response contain tool_use blocks? If yes → execute tools. If only text → done, return to user.

Step 8 — Execute. Each tool is found in the registry, validated against its JSON Schema, permission-checked (allow/ask/deny), then executed. Read-only tools run in parallel; write tools run one at a time.

Step 9 — Result. Tool outputs are wrapped as UserMessage objects (the API requires strict user/assistant alternation).

Step 10 — Loop. Updated history goes back to Claude. The loop continues until no more tool calls.

Step 11 — Render. Final text streams to the terminal. The screen buffer diffs and redraws only changed cells.

What surprised me

  • The agent loop itself is simple. The complexity lives in error recovery and retry logic (5 different retry strategies for different error types).
  • There are 50+ tools, and read-only tools run concurrently while write tools get exclusive access.
  • The source has ~8 unreleased features: a terminal companion pet (Buddy), persistent memory mode (Kairos), multi-agent teams, and more.
  • Context compaction automatically summarizes old messages when the window fills up — there's a reactive safety net that catches prompt-too-long errors.

The full course

I built a free interactive course that goes deep on each of these systems:

  • 12 lessons covering all 8 architecture layers
  • Animated video walkthroughs with narration
  • Python code examples (not TypeScript — patterns you can reuse)
  • Hands-on exercises and quizzes
  • An interactive stepper that lets you click through all 11 steps

code.bluggie.com

Everything is free, no paywall. I'd love to hear what parts of Claude Code you'd want explained that I haven't covered yet.


Not affiliated with Anthropic. Built by reading the public source code.

Top comments (0)