Agent Backends
Gru uses a pluggable agent architecture. Each backend implements the AgentBackend trait, which normalizes different CLI tools into a common event stream that Gru can monitor, log, and act on.
Available Backends
| Backend | CLI Tool | Flag Value | Status |
|---|---|---|---|
| Claude Code | claude | --agent claude | Default |
| OpenAI Codex | codex | --agent codex | Supported |
Claude Code (default)
Claude Code is the default backend.
Install
npm install -g @anthropic-ai/claude-code
Verify
claude --version
claude --help
Configure
No configuration is required — Gru uses Claude Code by default. Optionally override the binary path in ~/.gru/config.toml:
[agent.claude]
binary = "/usr/local/bin/claude"
How Gru Uses It
Gru spawns Claude Code in non-interactive mode with stream JSON output:
claude --print --verbose --session-id <uuid> --output-format stream-json --dangerously-skip-permissions --include-partial-messages "<prompt>"
Key flags:
--print— non-interactive (prints to stdout and exits)--verbose— include tool calls in output--output-format stream-json— real-time event stream--dangerously-skip-permissions— autonomous operation--session-id <uuid>— maintain context across resumes
OpenAI Codex
Codex CLI is an alternative backend using OpenAI models.
Install
npm install -g @openai/codex
Authenticate
Set your OpenAI API key:
export OPENAI_API_KEY="sk-..."
Verify
codex --version
codex --help
How Gru Uses It
Gru spawns Codex in full-auto mode with JSON output:
codex exec --json --full-auto "<prompt>"
Resume support uses:
codex exec resume --last --json --full-auto "<prompt>"
Note: Codex does not support interactive resume (gru attach will not work with Codex minions). Codex also ignores the session_id parameter — it relies on its own session persistence for both new and resumed sessions.
Selecting a Backend
Per-command
Use the --agent flag on any command that spawns an agent:
gru do 42 --agent codex
gru review 42 --agent codex
gru prompt my-prompt --agent codex
As default
Set the default in ~/.gru/config.toml:
[agent]
default = "codex"
The --agent flag always overrides the config default.
Feature Comparison
| Feature | Claude Code | Codex |
|---|---|---|
Autonomous work (gru do) | Yes | Yes |
PR review (gru review) | Yes | Yes |
Custom prompts (gru prompt) | Yes | Yes |
Session resume (gru resume) | Yes | Yes (non-interactive) |
Interactive attach (gru attach) | Yes | No |
| Token usage tracking | Yes | Yes |
| Stream monitoring | Yes | Yes |
Adding a New Backend
To add a new agent backend:
- Create
src/<name>_backend.rsimplementing theAgentBackendtrait fromsrc/agent.rs - Register it in
src/agent_registry.rs(add toAVAILABLE_AGENTSand the match inresolve_backend) - Map the backend's output format to
AgentEventvariants inparse_events()
The AgentBackend trait requires:
name()— human-readable identifierbuild_command()— construct the CLI command for a new sessionparse_events()— convert stdout lines to normalizedAgentEventsbuild_resume_command()— (optional) construct command to resume a sessionbuild_interactive_resume_command()— (optional) construct command forgru attach; returnNoneto disable attach support