Runners
claude (login or API key), llm, cmd: what each one does and what it can touch.
A runner executes an agent step. Every runner follows the same contract: it works in the workspace, reads and writes files (mostly in .agent/), and the step's verify: decides whether the work is good. So you can swap the model behind a step without touching the pipeline.
| Runner | For | Tools | Cost tracking |
|---|---|---|---|
claude | Real agent work: reading code, editing, running allowed commands, web, MCP. Your login or an API key (auth) | Strict allowlist | USD, turns, tokens |
llm | One-shot text work: summarize, classify, extract, reformat | None | Tokens |
cmd | Any other agent CLI | Whatever the CLI allows | None |
The runner comes from the step's model role (see Configuration).
claude
Runs the Claude Code CLI in print mode and reads its event stream (--output-format stream-json). Every tool call shows up live in the terminal, and the full transcript goes to the step's log file.
caffeine starts the CLI with:
| Option | Effect |
|---|---|
--tools <names> | Only the built-in tools named in allowed_tools exist for the agent. |
--allowedTools <entries> | Those entries are approved without a prompt, including patterns such as Bash(cargo test*) and mcp__docs__*. |
--permission-mode dontAsk | Anything else is refused, with no prompt: nobody is there to answer. |
--disallowedTools Agent,Task | Sub-agents are never available: they would escape the allowlist. |
--strict-mcp-config + --mcp-config | Only the pipeline's MCP servers. Your global ones are not loaded. |
--setting-sources=project | The target's own CLAUDE.md and project settings are read. Your user settings are not. |
--max-turns, --max-budget-usd | From the step's max_turns and the pipeline's max_budget_usd. |
--strict-mcp-config | Left out when the pipeline sets claude_connectors: true, so your claude.ai connectors load too. |
--model | From the role. |
--append-system-prompt-file | The pipeline's rules file, then the step's skills, written to <logdir>/<step>.system.md (a file: one argument is capped at 128 KB on Linux, and the logs keep what the agent got). |
--add-dir | Each skill's folder, so the agent can read its references and templates. |
--no-session-persistence | Runs leave no resumable session behind. |
The CLI runs in its own process group: the step's timeout and Ctrl-C kill it with everything it started. In a sandbox the CLI itself runs inside, so its Bash and Edit act there: claude_bin is looked up in the image, and ~/.claude is not mounted, so the login comes in by name, through the sandbox's env: (CLAUDE_CODE_OAUTH_TOKEN, from claude setup-token), or as the role's key with auth: api_key, which caffeine passes in itself. caffeine doctor checks both. In a kubernetes pod, both come from the run's Secret, and the whole run is there. The prompt is sent on stdin. When CLAUDE_CODE_OAUTH_TOKEN is set, ANTHROPIC_API_KEY is removed from the agent's environment so that the token is used (unless the role sets auth: api_key, below).
API key, and the plan's API credits
Max, Ultra and Team plans come with monthly API credits for one linked Console organization. They don't cover Claude Code on your subscription login, but they do cover claude -p started with an API key from that organization. They expire at the end of each billing cycle. A role can run on them instead of on your plan's usage limits:
models:
cheap: { runner: claude, model: haiku, auth: api_key } # ANTHROPIC_API_KEY
smart: { runner: claude, model: opus, auth: api_key, api_key_env: CAFFEINE_ANTHROPIC_KEY }
default: { runner: claude } # your login, as beforeWith auth: api_key:
- the key from
api_key_env(defaultANTHROPIC_API_KEY) is passed asANTHROPIC_API_KEY, andCLAUDE_CODE_OAUTH_TOKEN,ANTHROPIC_AUTH_TOKENandCLAUDE_CODE_USE_BEDROCK/_VERTEX/_FOUNDRYare removed, so the CLI cannot fall back to the subscription; - a missing key fails the step before the CLI starts;
- the step fails if the CLI reports (
apiKeySource) that it used another credential; - "credit balance too low" is not retried: use
fallback:to a subscription role if the run must go on; - the cost shown and
max_budget_usdare real money spent from the organization's credits.
The claude.ai connectors need your claude.ai login, so a pipeline with claude_connectors: true cannot use such a role. caffeine refuses it at load. caffeine doctor tells whether each key is set, but it cannot tell whether the key belongs to the organization linked to your plan: create it in that organization (claude.ai, Settings > Billing > API credits). For scheduled runs, store it in the keychain with keychain_env (see Automation).
After the run, caffeine checks what actually ran. A tool that executed successfully without matching the allowlist makes the step fail, even if nothing broke. A refused call is fine: that is the allowlist working. ToolSearch (loading a tool's schema) is always accepted.
Writing allowed_tools
allowed_tools:
- Read
- Edit
- Grep
- Glob
- "Bash(cargo build*)" # only commands starting with "cargo build"
- "Bash(cargo test*)"
- WebFetch
- "mcp__docs__*" # every tool of the `docs` MCP serverKeep Bash entries narrow. The agent cannot chain commands past them: a compound command (a && b, pipes, redirections) has to match as a whole and is usually refused. When a step needs a sequence, write a small script in {{pack}}/checks/ and allow only that script. Making the right path easy beats telling the agent what not to do.
llm
One request to an OpenAI-compatible endpoint, no tools, no loop. That covers OpenAI, Ollama, vLLM, LM Studio, OpenRouter, Mistral and most hosted APIs.
models:
local: { runner: llm, base_url: "http://localhost:11434/v1", model: "qwen3" } - name: 05-report
prompt: prompts/report.md
model: local
inputs: [.agent/SELECTED.md, .agent/REJECTED.md]
output: .agent/REPORT.md
verify: test -s .agent/REPORT.md- The pipeline's rules and the step's skills go in the system message.
- The user message is the rendered prompt, followed by each file of
inputsunder a--- path ---header. A missing input fails the step. - The answer is written to
output, which is required. api_key_envnames the environment variable that holds the key, sent as a Bearer token.timeoutbounds the request.- The log file holds the full request and response.
Since it has no tools, it cannot change anything but its output file. Use it for text work where a strong agent would be wasted money.
cmd
Any agent CLI, or any program: caffeine writes the rules and the step's skills, followed by the rendered prompt, to <logdir>/<step>.prompt.md, and runs your command in the workspace.
models:
codex: { runner: cmd, command: "codex exec --full-auto - < {{prompt_file}}" }
gemini: { runner: cmd, command: "gemini -p \"$(cat {{prompt_file}})\"" }
aider: { runner: cmd, command: "aider --yes --message-file {{prompt_file}}" }The step succeeds when the command exits 0. Its output goes to the step's log, and the last line shows up in the terminal. timeout kills it.
caffeine cannot see or limit what a cmd agent does: that is up to the CLI's own permissions. The guard and the step's verify still run after it. See Safety.
Retries
An agent or review step is retried after a transient failure, up to retries times (2 by default), after 2, 10 then 30 seconds:
llm: no answer at all (DNS, refused, reset, timeout), or HTTP 408, 425, 429, 500, 502, 503, 504, 529;claude: an error that says overloaded, rate limit, 5xx, connection reset or network.
Anything else (a 400, a wrong answer, a failed check) is not retried: that is what fallback: is for. Each attempt has its own log (<step>.retry1.log…), and the step's cost, tokens and turns add up all attempts. Ctrl-C stops the wait.
Mixing models: roles and fallback
The cheapest reliable setup is usually:
- A script wherever the input and output formats are strict. It is free and exact.
- A cheap role for routine agent work, with a
verify:that decides deterministically. fallback:to a strong role, called only when the check fails.
- name: 02-update
prompt: prompts/update.md
model: cheap
fallback: smart
verify: cargo build -q && cargo test -qThe fallback works on the files as the first attempt left them, and its prompt includes the end of the failing check's output. The step's cost, tokens and turns add up both attempts, and summary.json records which fallback ran.
For checking content, a reviewer from another model family than the producer is worth more than the same model reading its own work: they don't make the same mistakes.