BrainBank
AI Classroom/KnowledgeClaude Code Deep Dive

Claude Code Source Code Core Concepts at a Glance

7/12/2026, 9:21:06 PM · updated 7/12/2026, 9:22:42 PM

#mcp#claude-code#agent-architecture#knowledge#anthropic#source-code

This article provides an in-depth analysis of the ten core architectural concepts of Anthropic's command-line Agent tool, Claude Code, helping developers quickly understand its operating mechanism and establish a clear roadmap for reading the source code.

Why Look at the Concepts First

Many people, when looking at the Claude Code source code for the first time, get repeatedly bombarded by a bunch of terms:

  • QueryEngine
  • Tool
  • AppState
  • Plan Mode
  • MCP
  • LSP
  • Skills
  • Agent

If you don't build a basic understanding of these terms first, it will be very easy to get lost when reading the source code later.

So the goal of this article is not to dive deep into implementation details, but rather to give you a "core concepts map" first.

An Overview of the Relationships in One Diagram

image.png

1. QueryEngine

This is the core engine of Claude Code.
You can think of it as the brain scheduler for the entire task loop.

It is responsible for:

  • Receiving user input
  • Organizing message history
  • Calling the model
  • Handling tool calls
  • Streaming results back to the next round

In a nutshell:

QueryEngine determines how a task progresses round by round.

2. Tool

Tool is the way Claude Code lets the model "actually get its hands dirty."
Claude doesn't just output text; it can also use Tools to:

  • Read files
  • Modify files
  • Run commands
  • Access external resources
  • Enter Plan Mode

In a nutshell:

Tool is the execution interface layer of Claude Code.

3. AppState

AppState is the runtime state center of the terminal interface.
It doesn't record the state of a single small component, but rather what is currently happening across the entire session, such as:

  • Current mode
  • Tool permissions
  • Task list
  • Remote connection status
  • Plugin status

In a nutshell:

AppState determines "what state" the current terminal session is in right now.

4. Context

Context refers to the environmental info that Claude Code supplements for the model in each task round.
Typical content includes:

  • Git status
  • Current branch
  • CLAUDE.md
  • Current date
  • Project memory

In a nutshell:

Context explains why Claude Code seems to "understand your project."

5. Plan Mode

Plan Mode is a very important concept in Claude Code.
Its purpose is not to modify code directly, but rather to first let Claude:

  • Make plans
  • Output solutions
  • Wait for approval

In a nutshell:

Plan Mode is the planning and approval gate before automatic execution.

6. MCP

MCP is one of the important ways for Claude Code to access external capabilities.
Through MCP, it can connect to:

  • External tools
  • External resources
  • External commands

In a nutshell:

MCP allows Claude Code to not just rely on built-in capabilities, but to connect with the external world.

7. LSP

LSP is the Language Server Protocol.
In Claude Code, it primarily helps the system obtain more structured code semantic capabilities, such as:

  • Diagnostics
  • Language service feedback
  • Information closer to the code structure

In a nutshell:

LSP allows Claude Code to understand code using language toolchains instead of just viewing code as plain text.

8. Skills

Skills can be understood as the encapsulation of task experience and work methodologies.
It is not the tool itself, but more like:

  • Extra knowledge
  • Extra workflows
  • Job instructions for specific tasks

In a nutshell:

Skills make Claude Code act more like an "experienced person" on certain types of tasks.

9. Agent

Agent is not a vague concept in Claude Code, but rather an object of actual capability.
It means Claude Code does not necessarily have only a single main-thread assistant; it can also:

  • Spawn child Agents
  • Assign subtasks
  • Aggregate results

In a nutshell:

Agent is an important indicator of Claude Code moving towards multi-role collaboration.

10. Prompt / System Prompt

When reading the source code, many people will see fields like customSystemPrompt and appendSystemPrompt.
This shows that Claude Code's prompts are not static blocks of text, but are dynamically assembled.

In a nutshell:

The Prompt system determines "how Claude Code should think and what rules it must follow" in this round.

How These Concepts Coordinate

image.png

Most Common Misconceptions When Reading the Source Code

Misconception 1: Treating Claude Code as a simple chat wrapper

Incorrect. It is more like a terminal Agent with a runtime, a tool system, and a state system.

Misconception 2: Treating Tools as ordinary plugins

Incorrect. Tools are strictly modeled execution interfaces.

Misconception 3: Treating Prompts as the sole core

Also incorrect. Prompts are important, but what truly makes Claude Code powerful is the joint action of:

  • Prompt
  • Context
  • Tool
  • QueryEngine
  • Permissions and state systems

working together.

Summary

Before reading the Claude Code source code, you should at least remember these mappings:

  • QueryEngine = Core task engine
  • Tool = Execution interface
  • Context = Project context
  • AppState = Session state center
  • Plan Mode = Planning & approval mode
  • MCP / LSP = External extension capabilities
  • Skills / Agent = Experience encapsulation & collaboration capabilities

Once you understand these terms, the subsequent source code articles will be much easier to follow.

Learning map

Phase 1: Core Components and Task Loops

  • QueryEngine: Learn how, as the core brain scheduler, it manages multi-round LLM interactions and state distribution.
  • Tool Interface Design: Analyze how Claude Code standardizes and models external capabilities such as file operations and terminal execution.
  • Context Construction: Understand how the system automatically assembles project-specific context like Git status and CLAUDE.md, and injects it into prompts.

Phase 2: Session Management and Security Policies

  • AppState Runtime: Understand the dynamic evolution of global states such as session lifecycles, tool authorization, and remote connections.
  • Plan Mode Planning Mechanism: Master how the system ensures security through plan-to-execute reviews before performing complex modifications or high-risk commands.
  • Prompt Dynamic Concatenation: Explore logic such as customSystemPrompt to see how the system embeds user rules into model constraints in real time.

Phase 3: External Ecosystem and Advanced Collaboration

  • MCP (Model Context Protocol): Learn how to bridge external data sources based on the MCP protocol to unlock a larger ecosystem of tools.
  • LSP (Language Server Protocol): Master how to integrate with language servers for semantic-level code analysis, rather than simple text searching.
  • Skills & Agent Collaboration: Learn how to encapsulate specific empirical workflows (Skills) and the design patterns for multi-Agent task dispatching and result aggregation.

Get hands-on — step by step

  1. Installation and Initialization of Claude Code: Ensure you have Node.js installed (latest LTS version recommended), then run the following command in your terminal to install it globally: npm install -g @anthropic-ai/claude-code After installation, run claude and follow the prompts to complete the Anthropic account authorization and login.

  2. Establish Project-Level Context: Create a test project directory locally, initialize Git, and create a new file named CLAUDE.md, writing the common specifications into it:

# Build & Test Instructions
- Build: npm run build
- Test: npm run test
  1. Trigger and Observe the Synergy between Tools and Context: Enter Help me initialize a simple Node.js project and generate package.json in the interactive window. Observe the terminal; you will see Claude automatically recognize the local environment, call the file-writing tool, and operate according to the CLAUDE.md specifications.

  2. Run in Debug Mode to Analyze the Execution State: Start the command with the --verbose parameter, or view the console logs during complex interactions to track how the QueryEngine packages each step's tool results, AppState, and Local Context in real-time and sends them as the next round's Prompt to the API.

Top 3 sources

  1. 1
    Anthropic Claude Code Official Documentation

    官方关于 Claude Code 的使用指南与配置文档,详细介绍了底层运行规则与命令行参数。

    https://docs.anthropic.com/en/docs/agents-and-tools/claude-code

  2. 2
    Model Context Protocol (MCP) Portal

    了解 MCP 协议的核心规范与实现,帮助你深刻理解 Claude Code 是如何与外部上下文及工具链进行通信的。

    https://modelcontextprotocol.io

  3. 3
    Anthropic Official GitHub Organization

    Anthropic 官方开源仓库群,包含了许多 MCP 服务端模板与 Agent 最佳实践示例。

    https://github.com/anthropics

Links are AI-suggested — worth a quick sanity check before diving in.