This document provides a technical overview of Claude Code's high-level architecture, covering the core agent system, tool suite, plugin ecosystem, and how major components interact. For detailed documentation on specific subsystems, see the following pages:
Claude Code is built around an agent-based architecture with a modular tool system, extensive plugin support, and hierarchical configuration management. The system serves two primary use cases:
claude command) that provides an AI coding assistant with session management, context handling, and tool executionBoth use cases share the same core agent system, tools, and extension mechanisms.
The following diagram shows the primary components and their relationships:
Sources: High-level diagrams provided (Diagram 1: Overall System Architecture), CHANGELOG.md1-100
The primary entry point is the claude command, which supports both interactive mode (starting an agent session) and non-interactive subcommands:
| Command | Purpose |
|---|---|
claude | Start interactive session in current directory |
claude --resume | Resume previous session from picker |
claude --agent <name> | Start session with specific agent |
claude --worktree | Start in isolated git worktree |
claude auth login/logout/status | Manage authentication |
claude doctor | Diagnostic tool for installation |
claude mcp add/remove/list | Manage MCP server connections |
claude plugin enable/disable/browse | Manage plugins |
claude install | Installation wizard |
The CLI layer handles:
CLAUDE_CODE_* prefixes)Sources: README.md1-73 CHANGELOG.md156-169
Sessions are the unit of conversation persistence. Each session has:
Session storage structure:
~/.claude/sessions/<session-id>/transcript.jsonl: Line-delimited JSON of messages.claude.json: Metadata (custom title, tags, branch, directory)/resume, forked with /fork, renamed with /renameKey features:
gh pr create or --from-pr)/renameSources: CHANGELOG.md55-100 High-level diagrams
The main agent is the primary conversational interface. It:
Subagents are specialized instances spawned via the Task tool. They enable:
Agent definitions (.claude/agents/*.md) specify:
model: Which Claude model to usetools: Restricted tool access (e.g., Task(review-agent) allows only specific subagent types)memory: Persistent memory scope (user/project/local)background: Always run as background taskExample from marketplace: The code-review plugin uses parallel subagents with validation:
Sources: CHANGELOG.md5-11 CHANGELOG.md206-210 .claude-plugin/marketplace.json29-38 High-level diagrams (Diagram 6)
Tools are the agent's primary mechanism for interacting with the environment. Each tool has:
| Tool | Purpose | Permission Category |
|---|---|---|
Bash | Execute shell commands | Bash (with sandbox option) |
Read | Read file contents or PDF pages | Read |
Write | Create/overwrite files | Write |
Edit | Modify existing files with diffs | Write |
Glob | Find files matching patterns | Read |
Grep | Search file contents | Read |
Task | Spawn subagent | Task |
TaskUpdate | Update/delete background task | Task |
TaskStop | Stop background task | Task |
WebSearch | Search the web | WebTools |
WebFetch | Fetch URL content | WebTools |
MCPSearch | Discover MCP tools | MCPSearch |
Permission rules are pattern-based filters in settings.json:
Patterns use wildcard matching with tool name and parameter inspection. The classifier extracts relevant parameters (e.g., command for Bash, paths for file operations) and matches against rules.
Sources: CHANGELOG.md45-58 CHANGELOG.md199-200 High-level diagrams (Diagram 5)
The Bash tool supports sandboxed execution for network isolation:
Configuration (settings.json):
Features:
allowedDomains via iptables/ipsetexcludedCommandsautoAllowBashIfSandboxed skips permission prompts for sandboxed commandsImplementation: Uses init-firewall.sh script with iptables rules for network filtering. Requires NET_ADMIN capability in containerized environments.
Sources: CHANGELOG.md186-187 CHANGELOG.md199-200 CHANGELOG.md240-241 High-level diagrams (Diagram 4, Diagram 5)
Plugins extend Claude Code with custom commands, agents, skills, hooks, and MCP servers. Discovery paths (in order of precedence):
.claude-plugin/ in repository~/.claude/plugins/.claude/plugins/--add-dirPlugin Structure (plugin.json):
Plugins are loaded at startup and can be managed via:
claude plugin enable/disable <name>claude plugin browse (interactive marketplace browser)Sources: CHANGELOG.md9-14 CHANGELOG.md120-121 .claude-plugin/marketplace.json1-151 High-level diagrams (Diagram 2)
Skills are custom slash commands defined in SKILL.md files with YAML frontmatter:
Discovery paths:
.claude/skills/~/.claude/skills/<plugin>/skills/--add-dir directoriesSkills are invoked via slash commands (e.g., /example-skill arg1 arg2) and inject their content as system instructions. They can:
Sources: CHANGELOG.md61-63 CHANGELOG.md208-209 CHANGELOG.md226-230 plugins/frontend-design/skills/frontend-design/SKILL.md1-42
Hooks enable custom behavior at lifecycle events:
| Hook Type | Trigger Point | Input Data |
|---|---|---|
SessionStart | After session initialization | Session metadata |
PreToolUse | Before tool execution | Tool name, parameters |
PostToolUse | After tool execution | Tool name, result, duration |
Stop | Session termination | Final message, transcript path |
TeammateIdle | Subagent waiting for work | Agent ID, status |
TaskCompleted | Subagent finished | Agent ID, result |
Setup | Explicit maintenance trigger | Via --init, --init-only, --maintenance flags |
ConfigChange | Settings file modified | Changed file path |
Hook Definition (e.g., .claude/hooks/pre-tool-use.sh):
Hooks receive JSON input via stdin and can:
additionalContext in PreToolUse)Enterprise Control: allowManagedHooksOnly in managed settings prevents custom hooks, enforcing organizational policy.
Sources: CHANGELOG.md24-31 CHANGELOG.md54-55 CHANGELOG.md206-207 CHANGELOG.md424-425 CHANGELOG.md439-440
MCP servers provide external tool integrations with three transport types:
| Transport | Use Case | Configuration |
|---|---|---|
stdio | Local processes | Command + args |
HTTP | REST APIs | Base URL + endpoints |
SSE | Server-sent events | Streaming connections |
MCP Server Management:
claude mcp add <url> - Add serverclaude mcp remove <name> - Remove serverclaude mcp list - Show configured servers~/.claude/mcp-servers/OAuth Support: MCP servers can use OAuth 2.0 with:
--client-id, --client-secret)Tool Discovery: By default, MCP tool descriptions load upfront. When they exceed 10% of context window, MCPSearch tool enables lazy loading via auto mode (configurable with auto:N syntax for N% threshold).
Sources: CHANGELOG.md106-107 CHANGELOG.md252-255 CHANGELOG.md420-421 CHANGELOG.md434-435 CHANGELOG.md458-459
Context Management Features:
/compact command for user-initiated summarizationCompaction Process:
Sources: CHANGELOG.md38-45 CHANGELOG.md225-234 CHANGELOG.md329-330 CHANGELOG.md400-410 CHANGELOG.md452-453
The memory system provides persistent state across sessions:
| Scope | Storage Location | Use Case |
|---|---|---|
user | ~/.claude/memory/ | Cross-project preferences, learnings |
project | .claude/memory/ | Project-specific context, patterns |
local | .claude/memory/<session-id>/ | Session-specific temporary state |
Agent Memory Configuration (.claude/agents/*.md frontmatter):
Agents with memory specified automatically record and recall relevant information as they work. Memory is scoped per agent type and persists across invocations.
Sources: CHANGELOG.md207-208 CHANGELOG.md224-225 High-level diagrams (Diagram 1)
Settings cascade through four levels with increasing precedence:
Enterprise-Only Controls (cannot be overridden):
strictKnownMarketplaces: Block plugin sourcesallowManagedHooksOnly: Prevent custom hooksallowManagedPermissionRulesOnly: Centralize permission rulesdisableAllHooks: Force disable all hooks (respects managed hierarchy)Common Settings:
permissionRules: Allow/ask/deny patterns for toolssandbox: Network isolation configurationdisallowedTools: Block specific toolsbypassPermissions: Disable permission system (can be forced off)model: Default model selectionenabledPlugins: Active plugin listextraKnownMarketplaces: Additional plugin sourcesspinnerVerbs, spinnerTipsOverride: UI customizationConfiguration Management:
/config command: Interactive settings editor with search~/.claude/backups/ (5 most recent, timestamped)ConfigChange hook: Fires when files change (for auditing)Sources: CHANGELOG.md28-31 CHANGELOG.md112-114 CHANGELOG.md292-294 CHANGELOG.md464-469 High-level diagrams (Diagram 5)
Primary model provider with support for:
Model Support:
API Features:
Sources: CHANGELOG.md16-17 CHANGELOG.md110-111 CHANGELOG.md141-142 CHANGELOG.md194-195 CHANGELOG.md222-223
Used in two contexts:
PR Linking (interactive sessions):
gh pr create--from-pr <number|url>Automation Workflows (see GitHub Automation):
Sources: CHANGELOG.md279-286 CHANGELOG.md326-328 High-level diagrams (Diagram 3)
Statsig Integration: Event tracking for:
SDKRateLimitInfo, SDKRateLimitEvent)tool_decision OTel events)OpenTelemetry: Distributed tracing with:
speed (fast mode visibility)Sentry: Error reporting and monitoring (opt-in)
Sources: CHANGELOG.md113-115 CHANGELOG.md154-155 CHANGELOG.md75-76 High-level diagrams (Diagram 3)
Claude Code development uses a DevContainer for reproducible, isolated environments:
Container Configuration (.devcontainer/devcontainer.json):
node:20node with limited sudo accessinit-firewall.sh with iptables rulesOrchestration:
run_devcontainer_claude_code.ps1For detailed DevContainer documentation, see Development Environment.
Sources: High-level diagrams (Diagram 4), CHANGELOG.md115-116
Refresh this wiki