Architecture
Codebuff is built on a multi-agent orchestration architecture where specialized AI agents coordinate to complete coding tasks. Instead of using a single large model for everything, Codebuff coordinates multiple purpose-built agents that work together.High-Level Overview
When you ask Codebuff to make a change, here’s what happens:- Base Agent receives your request and plans the approach
- Specialized agents are spawned to gather context (file-picker, code-searcher)
- Editor Agent implements the changes based on gathered context
- Reviewer Agent validates the changes
- Commander Agent runs tests and validation commands
This orchestration approach gives you better context understanding, more accurate edits, and fewer errors compared to single-model tools.
Core Components
CLI (Command Line Interface)
The CLI is the primary user interface for Codebuff. Located incli/src/, it provides:
- Interactive chat interface for natural language coding requests
- Command system (
/init,/usage, etc.) for workspace management - Real-time feedback as agents work on your code
- Git integration for tracking changes
cli/src/index.tsx- Entry pointcli/src/chat.tsx- Main chat interface (49KB, handles all interaction)cli/src/app.tsx- Application shell
SDK (Software Development Kit)
The SDK (sdk/src/) provides the core runtime for executing agents and can be embedded in any Node.js application:
sdk/src/client.ts- Main client interfacesdk/src/run.ts- Agent execution engine (23KB)sdk/src/run-state.ts- State management (22KB)sdk/src/tools/- Built-in tool implementations
Agents
Agents are the specialized workers in Codebuff. Each agent is defined inagents/ and has:
- Unique purpose (finding files, editing code, reviewing changes)
- Specific tools it can use
- Custom prompts tailored to its task
- Ability to spawn sub-agents for delegation
Tools
Tools are the actions agents can perform, implemented insdk/src/tools/:
- File operations - read_files, write_file, str_replace
- Code analysis - code_search, glob, list_directory
- Terminal - run_terminal_command
- Agent spawning - spawn_agents
Data Flow
Here’s how data flows through Codebuff during a typical request:Execution Model
Agent Lifecycle
Each agent follows this lifecycle:- Initialization - Agent receives prompt and params
- handleSteps execution - Generator function controls agent behavior
- Tool calls - Agent uses tools to read files, spawn agents, etc.
- LLM steps - Agent sends messages to LLM for decision-making
- Output - Agent returns result (last_message, all_messages, or structured_output)
Step-by-Step Execution
Agents use TypeScript generator functions to control execution:Context Management
Codebuff automatically manages context through the Context Pruner agent:- Runs automatically between steps
- Summarizes conversation when context limit is approaching
- Preserves important information (user messages, file changes, errors)
- Triggers on cache misses (>5 min gaps) to take advantage of fresh context
agents/context-pruner.ts:
Model Selection
Different agents use different models optimized for their tasks:- Base Agent (base2):
claude-opus-4.6orminimax-m2.5(free mode) - Editor:
claude-opus-4.6orgpt-5.1 - File Picker:
gemini-2.5-flash-lite(fast, cost-effective) - Commander:
gemini-3.1-flash-lite-preview(quick command execution) - Context Pruner:
gpt-5-mini(efficient summarization)
Extension Points
Codebuff is designed to be extended:Custom Agents
Create agents in.agents/ directory:
Custom Tools
Provide custom tool implementations via the SDK:MCP Servers
Integrate Model Context Protocol servers for external tools:Performance Considerations
Parallel Agent Spawning
The base agent spawns multiple agents in parallel when they don’t depend on each other:Prompt Caching
Agents leverage prompt caching (Anthropic’s 5-minute cache window):- System prompts are cached
- File tree is cached
- Context pruner triggers on cache misses to refresh context
Token Efficiency
Smaller, faster models are used for routine tasks:- File discovery uses Gemini Flash
- Command execution uses Gemini Flash Lite
- Only complex reasoning uses Opus/GPT-5
Next Steps
Agents
Learn about each specialized agent
Multi-Agent Orchestration
See how agents work together
Tools
Explore available tools
Creating Agents
Build your own agents

