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:Input Processing
Your natural language request is parsed to understand intent, referenced files, and required actions.
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)
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
Permission Checking
Before executing operations, Claude Code:
- Checks permission rules
- Applies security policies
- Requests approval for new operations
- Validates against allowed tools
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
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
/compact to summarize.
2. Tool System
Claude Code uses specialized tools for different operations:| Tool | Purpose | Example |
|---|---|---|
| Read | Load file contents | Read configuration files, source code |
| Edit | Modify existing files | Fix bugs, refactor code |
| Write | Create new files | Generate new modules, tests |
| Bash | Execute shell commands | Run tests, git operations |
| Glob | Find files by pattern | Locate all TypeScript files |
| Grep | Search file contents | Find function usages |
| WebFetch | Retrieve web content | Read documentation |
| WebSearch | Search the web | Find solutions, examples |
| Task | Launch background agents | Complex 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
- Session: This conversation only
- Project: All sessions in this project
- User: All projects globally
4. Plugin System
Extend functionality with plugins that provide: Custom Commands: Slash commands for specific workflows5. Session Management
Sessions preserve conversation state: Auto-save: Conversations are automatically saved Resume: Continue previous sessions:6. Model Selection
Claude Code supports multiple models:| Model | Best For | Context Window |
|---|---|---|
| Sonnet 4.6 | General coding, fast responses | 200K (1M with flag) |
| Opus 4.6 | Complex tasks, deep reasoning | 200K (1M with flag) |
| Sonnet 4.5 | Legacy support | 200K |
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
Context Management
Optimizing context usage: Efficient File Loading:- PDFs: Load specific page ranges with
pagesparameter - Large files: Collapsed summaries with expand option
- Binary files: Automatic exclusion
- Glob: Find files by pattern (fast, minimal context)
- Grep: Search contents (returns matches, not full files)
- MCP Search: Defer tool discovery until needed
Security Model
Sandbox Mode: Restrict bash commands to sandboxed environment:- Gitignored files: Warnings
- Outside project: Blocked by default
- Sensitive files (.env): Extra confirmation
Data Flow
Understanding how data flows through Claude Code:Best Practices
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