Skip to main content
Claude Code is built on several key concepts that work together to provide intelligent, context-aware coding assistance. Understanding these concepts will help you use Claude Code more effectively.

Core Architecture

Claude Code combines multiple technologies to understand and modify your codebase:

Natural Language Interface

Conversational commands that understand intent and context

Specialized Agents

Background workers for complex analysis and code generation

Codebase Understanding

Deep analysis of code structure, patterns, and relationships

Tool Execution

Safe, controlled execution of file operations and shell commands

How Claude Code Works

When you interact with Claude Code, several systems work together:
1

Input Processing

Your natural language request is parsed to understand intent, referenced files, and required actions.
2

Context Assembly

Claude Code gathers relevant context from:
  • Conversation history
  • Referenced files (@-mentions)
  • Project structure and patterns
  • Git history and status
  • Custom configuration (CLAUDE.md)
3

Intelligent Planning

Based on your request and context, Claude determines:
  • Which files need to be read
  • What changes to make
  • Which tools to use
  • Whether to launch specialized agents
4

Permission Checking

Before executing operations, Claude Code:
  • Checks permission rules
  • Applies security policies
  • Requests approval for new operations
  • Validates against allowed tools
5

Execution

Approved operations are executed using specialized tools:
  • Read: Load file contents
  • Edit: Make targeted changes
  • Write: Create new files
  • Bash: Run shell commands
  • Grep/Glob: Search code
6

Result Processing

Execution results are:
  • Displayed with syntax highlighting
  • Added to conversation context
  • Used to inform next steps
  • Stored in session history

Key Components

1. Conversation Context

Claude Code maintains conversation context throughout your session:
  • Message History: All previous messages and responses
  • Tool Results: Outputs from file reads, searches, and commands
  • File References: Files mentioned with @
  • Session State: Current working directory, git branch, permissions
Context Window: Claude Code uses Claude 4.6 models with large context windows (up to 1M tokens for Sonnet 4.6). When approaching limits, use /compact to summarize.

2. Tool System

Claude Code uses specialized tools for different operations:
ToolPurposeExample
ReadLoad file contentsRead configuration files, source code
EditModify existing filesFix bugs, refactor code
WriteCreate new filesGenerate new modules, tests
BashExecute shell commandsRun tests, git operations
GlobFind files by patternLocate all TypeScript files
GrepSearch file contentsFind function usages
WebFetchRetrieve web contentRead documentation
WebSearchSearch the webFind solutions, examples
TaskLaunch background agentsComplex analysis, code exploration
Tools are executed with safety checks. File operations are sandboxed, and bash commands can be restricted based on security policies.

3. Permission System

Granular control over what Claude Code can do: Permission Levels:
  • Allow: Automatically approved
  • Ask: Prompts for approval
  • Deny: Blocked
Scopes:
  • Session: This conversation only
  • Project: All sessions in this project
  • User: All projects globally
Rule Matching: Permissions support wildcards and patterns:
{
  "permissions": {
    "allow": [
      "Bash(git status:*)",
      "Bash(npm test:*)",
      "Read",
      "Grep"
    ],
    "ask": [
      "Bash(git push:*)",
      "Write",
      "Edit"
    ],
    "deny": [
      "Bash(rm -rf:*)",
      "WebFetch"
    ]
  }
}

4. Plugin System

Extend functionality with plugins that provide: Custom Commands: Slash commands for specific workflows
---
description: Create a git commit
allowed-tools: Bash(git:*)
---
Create a commit based on current changes...
Specialized Agents: Background workers for complex tasks
---
description: Explore code execution paths
model: claude-sonnet-4.6
---
Trace through code comprehensively...
Event Hooks: React to events like tool execution or session start
{
  "events": ["PreToolUse", "PostToolUse"],
  "command": "./validate.sh"
}
MCP Servers: Connect external tools and data sources
{
  "mcpServers": {
    "github": {
      "command": "npx",
      "args": ["-y", "@modelcontextprotocol/server-github"]
    }
  }
}

5. Session Management

Sessions preserve conversation state: Auto-save: Conversations are automatically saved Resume: Continue previous sessions:
claude --resume
claude --resume session-id
Compaction: Summarize long conversations to free context:
> /compact
Forking: Branch from any message to explore alternatives:
> /fork

6. Model Selection

Claude Code supports multiple models:
ModelBest ForContext Window
Sonnet 4.6General coding, fast responses200K (1M with flag)
Opus 4.6Complex tasks, deep reasoning200K (1M with flag)
Sonnet 4.5Legacy support200K
Fast Mode: Available for Opus 4.6, trades some accuracy for speed:
> /fast
Effort Levels: Control thinking depth for complex tasks:
> /model
# Select Opus 4.6 and choose effort level

Advanced Concepts

Prompt Caching

Claude Code uses prompt caching to reduce latency and costs:
  • System Prompts: Cached across messages
  • Tool Definitions: Cached when unchanged
  • Large Context: Frequently accessed files cached
Cache Hit Rates: Typically 80%+ in active sessions

Context Management

Optimizing context usage: Efficient File Loading:
  • PDFs: Load specific page ranges with pages parameter
  • Large files: Collapsed summaries with expand option
  • Binary files: Automatic exclusion
Search Tools:
  • Glob: Find files by pattern (fast, minimal context)
  • Grep: Search contents (returns matches, not full files)
  • MCP Search: Defer tool discovery until needed
Compaction: Automatic summarization when nearing limits

Security Model

Sandbox Mode: Restrict bash commands to sandboxed environment:
{
  "sandbox": {
    "network": {
      "allowedDomains": ["api.github.com"],
      "allowLocalBinding": false
    },
    "excludedCommands": ["git", "npm"]
  }
}
Managed Settings: Enterprise policies that users cannot override:
{
  "allowManagedPermissionRulesOnly": true,
  "allowManagedHooksOnly": true,
  "strictKnownMarketplaces": []
}
Path Safety: Automatic validation of file paths:
  • Gitignored files: Warnings
  • Outside project: Blocked by default
  • Sensitive files (.env): Extra confirmation

Data Flow

Understanding how data flows through Claude Code:

Best Practices

Use @-mentions: Reference specific files to provide precise context and reduce token usage.
Leverage agents: For complex analysis, launch specialized agents instead of asking Claude to do everything.
Set up permissions: Create rules for frequently used operations to streamline workflow.
Monitor context: Check /context periodically and compact when needed to maintain performance.
Use CLAUDE.md: Document project conventions in .claude/CLAUDE.md for consistent behavior.

Learn More

Dive deeper into specific concepts:

Natural Language

How Claude understands your requests

Agents

Background workers and task management

Codebase Understanding

How Claude analyzes your code

Build docs developers (and LLMs) love