AI Engines¶
Brat works with multiple AI coding tools through a unified engine interface.
Supported Engines¶
| Engine | Command | Best For |
|---|---|---|
| Claude Code | claude | Native Anthropic integration, session resume |
| Aider | aider | Multi-model flexibility, local LLM support |
| OpenCode | opencode | 75+ providers, Claude Code alternative |
| Codex | codex | Structured JSON output |
| Continue | cn | IDE integration, CI/CD |
| Gemini | gemini | Google's free tier |
| GitHub Copilot | gh copilot | Shell/git suggestions |
Engine Configuration¶
Set your default engine in .brat/config.toml:
[engine]
default = "claude"
[engine.claude]
# Claude Code specific settings
[engine.aider]
model = "gpt-4"
# Aider specific settings
Engine Interface¶
All engines implement a common interface:
trait Engine {
fn spawn(&self, spec: SpawnSpec) -> Result<SpawnResult>;
fn send(&self, session: SessionHandle, input: EngineInput) -> Result<()>;
fn tail(&self, session: SessionHandle, n: usize) -> Result<Vec<String>>;
fn stop(&self, session: SessionHandle, how: StopMode) -> Result<()>;
fn health(&self, session: SessionHandle) -> Result<EngineHealth>;
}
This means:
- Any engine can work with any Brat workflow
- New engines can be added by implementing the trait
- Engine-specific quirks are hidden behind the abstraction
Engine Comparison¶
Claude Code¶
Pros:
- Native Anthropic integration
- Session resume capability
- Best context understanding
Cons:
- Requires Anthropic API key
- Usage-based pricing
Aider¶
Pros:
- Multi-model support (GPT-4, Claude, Gemini, local)
- Works with local LLMs
- Active open-source community
Cons:
- Requires separate LLM API key
- More configuration needed
OpenCode¶
Pros:
- 75+ LLM providers
- Open-source Claude Code alternative
- Flexible configuration
Cons:
- Newer project
- Less documentation
Codex¶
Pros:
- Structured JSON output
- Easy to parse responses
Cons:
- Older technology
- Limited context window
Timeouts and Safety¶
All engine operations have bounded timeouts:
| Operation | Default Timeout |
|---|---|
| Spawn | 60 seconds |
| Send | 5 seconds |
| Tail | 10 seconds |
| Stop | 10 seconds |
| Health | 5 seconds |
Configure in .brat/config.toml:
Engine Selection¶
Per-Task Override¶
Specify an engine for a specific task:
Fallback Chain¶
Configure fallback engines:
If Claude fails, Brat tries Aider, then OpenCode.
Setting Up Engines¶
Claude Code¶
-
Install Claude Code:
-
Configure API key:
-
Set as default:
Aider¶
-
Install Aider:
-
Configure model:
-
Set API key:
OpenCode¶
-
Install OpenCode:
-
Configure provider:
Engine Health¶
Check engine availability:
The Witness monitors engine health and restarts unhealthy sessions.
Adding Custom Engines¶
Implement the Engine trait for custom integrations:
- Create a new crate:
libbrat-engine-myengine - Implement the trait methods
- Register in
libbrat-engine/src/lib.rs - Add configuration options
See the existing engine implementations for examples.