Headless mode and automation
waibee run runs the agent with no interface: a prompt goes in, and the result comes out on stdout. There is no TUI, so you can call the agent from a Makefile, a git hook, a CI step, or another program, including another agent.
Compaction while idle does not run here. With Anthropic models and waibee/auto, waibee run always uses a five-minute prompt cache, whatever context.prompt_cache is set to. See Context window.
waibee run "explain what calc.py does in one sentence"cat task.md | waibee run - # prompt from stdingit diff | waibee run "review this diff" # prompt and data from stdinwaibee "..." with no subcommand does the same in text format. waibee -p "..." (or --print) also means waibee run: -p goes before the subcommand, and --continue and --resume <id> work with it. The other subcommands are listed in CLI subcommands.
A word that matches a subcommand runs that subcommand: waibee doctor checks the environment instead of sending a prompt. A single word that looks like a subcommand (waibee sesions) and a single word starting with - don’t reach the agent either: the run exits with code 2 and suggests what you meant. To send such a word as a prompt, put -- before it: waibee -- doctor.
The agent works in your real project: it reads files, runs commands, and edits code. With no --mode flag and no permissions.mode in settings, the run uses trust mode: edits and most commands go through without asking. The run never asks anything and never waits for a person. A call that needs approval is rejected: the agent gets the denial and keeps working, and the denial is recorded in permission_denials. See Permissions in headless mode.
Input from stdin
Section titled “Input from stdin”- in place of the prompt reads the prompt from stdin, up to 1 MiB. If stdin is a terminal or nothing ever arrives on it, the run exits with code 2.
If you give a prompt and stdin is not a terminal, whatever arrives on stdin reaches the agent as a separate block after the prompt. That is how git diff | waibee run "review this diff" gives the agent both the request and the diff. This block is also capped at 1 MiB. An empty, closed stdin is skipped silently; an open stream with no data is skipped after three seconds with a warning on stderr. < /dev/null removes the wait. A stream that never closes (tail -f log | waibee run "...") is read for a limited time; then the run goes ahead with what it has read and says so on stderr.
The run inherits the shell’s stdin. In the loop while read -r f; do waibee run "fix $f"; done < files.txt, the first run takes the rest of files.txt as data for its prompt, and the loop ends after the first file. Write waibee run "fix $f" < /dev/null and the list stays with the loop.
Output formats
Section titled “Output formats”waibee run "..." # reply textwaibee run --output-format json "..." # one final recordwaibee run --output-format stream-json "..." # event stream, one record per lineWithout the flag, the output is text. --format json is the old spelling of the event stream, the same as --output-format stream-json; the two flags are not accepted together. waibee -p --output-format json "..." also prints one record.
Single record: json
Section titled “Single record: json”--output-format json prints one line when the run finishes. A shortened example:
{"type":"result","result":"`calc.py` defines an `add(a, b)` function and, when run as a script, adds the two numbers given as command-line arguments and prints the result.","session_id":"s1","agent_id":"a1","num_turns":3,"stop_reason":"end_of_turn","is_error":false,"duration_ms":6855,"ttft_ms":2729,"permission_denials":[],"usage":[{"model":"anthropic/claude-sonnet-5.5","purpose":"turn","input_tokens":8,"output_tokens":154,"cache_creation_input_tokens":0,"cache_read_input_tokens":45306}]}result holds the main agent’s last reply: the text it wrote after its last tool call or, if it replied once more without a tool (for example, after the goal check), only that last reply. num_turns counts the turns the main agent started, including a final interrupted or failed turn and the schema correction of the reply; subagent turns and internal context updates are not counted. The other fields are the same as in done in the stream below, and usage holds the models rows from the usage event. To get the reply: waibee run --output-format json "..." | jq -r .result.
Event stream: stream-json
Section titled “Event stream: stream-json”Below is a shortened example of the stream; events may carry extra fields.
{"type":"meta","protocol":"waibee/1","session_id":"s1","model":"anthropic/claude-sonnet-5.5","permission_mode":"default","sandbox":{"profile":"workspace-write","reason":"command line or WAIBEE_SANDBOX","mechanism":"macos/seatbelt","verdict":"engages"},"tools":["Read","Glob","Grep"],"bare":true}{"type":"text","agent_id":"a1","text":"`calc.py` defines an `add` function for two floats and, when run as a script, prints the sum of its first two command-line arguments."}{"type":"usage","models":[{"model":"anthropic/claude-sonnet-5.5","purpose":"turn","input_tokens":8,"output_tokens":148,"cache_creation_input_tokens":3284,"cache_read_input_tokens":6214}]}{"type":"result","session_id":"s1","agent_id":"a1","result":"`calc.py` defines an `add` function for two floats and, when run as a script, prints the sum of its first two command-line arguments.","num_turns":3,"stop_reason":"end_of_turn","is_error":false,"duration_ms":6156,"ttft_ms":2329,"permission_denials":[],"usage":[{"model":"anthropic/claude-sonnet-5.5","purpose":"turn","input_tokens":8,"output_tokens":148,"cache_creation_input_tokens":3284,"cache_read_input_tokens":6214}]}{"type":"done","session_id":"s1","agent_id":"a1","num_turns":3,"stop_reason":"end_of_turn","is_error":false,"duration_ms":6156,"ttft_ms":2329,"permission_denials":[]}After a successful start, the stream opens with meta. Its sandbox field holds the outcome of turning on the sandbox, and waibee config check checks the sandbox in advance. tools lists the tools available at start, and bare shows whether the run without extensions is on.
At the end come usage, then one result (as in the single-record format), and right after it one done. Take the final reply from result.result: the text events joined together can contain intermediate replies. For example: jq -r 'select(.type == "result") | .result' events.jsonl. How the stream ends on a startup error or a signal is described below.
| Event | Fields | Meaning |
|---|---|---|
meta | protocol, session_id, model, permission_mode, cwd, started_at, version, platform, sandbox, tools, bare | The run started |
text | agent_id, text | A fragment of the agent’s reply |
tool_call | agent_id, call_id, tool, args | A tool call. For an MCP tool called through CallTool, this holds the name and arguments of the tool itself |
tool_result | agent_id, call_id, content, is_error, elapsed_ms, sources | The result of the call with the same call_id. sources is present if the tool returned sources, as web search does |
injected | agent_id, text, origin | A message to the agent that did not come from the prompt: a reply from a Stop hook, a notice that a background command or subagent finished, and the like |
reminder | agent_id, text | An internal note added to the agent’s context |
sub_agent_started | agent_id, parent_agent_id, call_id, task, model, agent_name, depth | A subagent started |
sub_agent_done | agent_id, call_id, summary, usage, duration_ms, is_error, ended | A subagent finished |
goal_changed | agent_id, condition | A goal was set or cleared (condition: null) |
goal_evaluated | agent_id, decision (met or not_met), reason | The result of a goal check |
goal_achieved | agent_id, duration_secs | The goal was met |
goal_aborted | agent_id, reason | The goal was dropped without being met |
error | agent_id, class, message, retryable | An error. class names its kind, for example startup if the run never reached the agent’s work, or execution if work already under way failed; retryable says whether a retry makes sense. An error on its own does not necessarily end the run |
usage | models | Token usage by model, see below |
result | as in done, plus result, usage, and structured_output | The outcome of the run |
done | agent_id, session_id, stop_reason, is_error, num_turns, duration_ms, ttft_ms, permission_denials, and the stop-reason fields | The last line of the stream |
ttft_ms is the time to the first text, reasoning fragment, or tool call; it is null if there were none. Reasoning does not appear in the output. Ignore unknown event types and extra fields.
stop_reason in result and done tells you how the work ended:
| Value | What happened |
|---|---|
end_of_turn | The agent finished its reply on its own |
max_turns | The turn limit ran out; the number is in the turn_limit field |
input_budget, output_budget, time_budget | A run limit ran out. The amount used and the limit are in neighboring fields: billable_input_tokens and billable_input_limit, output_tokens and output_limit, elapsed_seconds and elapsed_limit |
cut_short | The work was stopped; the reason is in stop_class, see below |
cancelled | A signal interrupted the run |
error | An error, including a goal that was not met or a reply that failed schema validation when the turn ended normally |
stop_class | Reason |
|---|---|
loop | The agent went in circles |
hook | A PostToolUse hook stopped the work, see Hooks |
max_tokens | The model’s reply kept hitting the length limit |
stream_interrupted | The model’s response stream kept breaking off |
content_filter | The provider’s content filter blocked the reply |
tool_call_lost | The model ended its reply with a tool call that never arrived |
empty_response | The model returned an empty reply several times in a row |
is_error: true means the process exits with a nonzero code, see Exit codes.
A subagent run shows up as sub_agent_started and sub_agent_done lines. Both carry the call_id of the Agent call that started the subagent, and the subagent’s own text, tool_call, and tool_result carry its agent_id, so you can nest its work under the call. sub_agent_done has no ended field if the subagent finished on its own; otherwise ended holds the reason: failed (then is_error: true), cancelled, max_turns, or a value from the tables above. Every sub_agent_started gets a sub_agent_done before done, including a background subagent the run did not wait for. Text mode prints only the main agent’s reply.
While a goal is active, goal_* events show its progress. In text format, the same information goes to stderr as lines; see the example in Goal mode.
The usage line comes before result when counters are available. models has one row per pair of model and purpose. The purpose is turn for turns of the agent and its subagents; helper calls carry their own purpose: compaction (history compaction), session_title (the title), memory_extraction and memory_consolidation (memory), goal_evaluation and goal_suggestion (checking and suggesting a goal), page_distillation (a page summary for WebFetch), web_search (web search). input_tokens is fresh input; the cache is counted separately. null in a cache counter means there is no data, not zero usage.
Output that follows a JSON Schema
Section titled “Output that follows a JSON Schema”--json-schema <JSON or path> validates the final reply. The schema is parsed before the first request to the model; invalid JSON or an invalid schema ends the run with code 2. A reply wrapped entirely in one code block, with no language or with json, is read without the wrapper.
{ "type": "object", "properties": { "summary": {"type": "string"}, "files": {"type": "array", "items": {"type": "string"}} }, "required": ["summary", "files"], "additionalProperties": false}waibee run --once --output-format json --json-schema alert-schema.json \ "Describe the purpose of the project and list the main files" < /dev/nullIf the reply is JSON and matches the schema, the result object gets a structured_output field. On a mismatch, the agent gets the validation error and corrects its reply once. If the reply still fails validation, result and done get schema_error and is_error: true, and the process exits with code 1. A real stop_reason, such as max_turns or time_budget, is kept; only a normal end_of_turn becomes error. The correction draws on the shared turn and time limits; if a limit has already been reached, no new request is made.
Last reply to a file
Section titled “Last reply to a file”-o <file> or --output-last-message <file> atomically writes only the text from result.result. The stdout format stays the same. On an error, the reply the agent managed to get is written too, if the write fits within the shutdown time; after an interruption, the file is not guaranteed to exist.
stdout, stderr, and the log
Section titled “stdout, stderr, and the log”Only the result goes to stdout. stderr gets the permission mode at the start of the run (in text format), what was skipped in an untrusted folder, and the progress of the goal check. The program’s own warnings go to the log in logs/ in the data directory; with RUST_LOG or DEBUG=1 in the environment, they are also printed to stderr. That is why $(waibee run ...) captures only the reply.
Exit codes
Section titled “Exit codes”| Code | Meaning |
|---|---|
0 | The work is done: the goal was met or, with no goal, the agent finished its reply on its own (stop_reason: end_of_turn) or a hook stopped or blocked it |
1 | The work failed: the goal was not met, a limit was hit, the work was cut short (cut_short, except a stop by a hook), a model or agent error occurred, or the final reply failed schema validation or could not be written to the file |
2 | An invocation, environment, or authentication error: an unknown flag or flag value (including --effort and --max-turns 0), an unknown model in -m or --goal-model, an unknown name in --tools, a rule in --allowed-tools or --disallowed-tools that does not parse, a --cwd folder that does not exist, --no-session-persistence together with --resume or --continue, an invalid schema, a missing or rejected router key, a session that is not found or is in use, empty stdin with -, an invalid WAIBEE_DATA_DIR, a managed settings error, or an unavailable required sandbox. The reason is written to stderr |
130 | The first SIGINT, including Ctrl+C |
143 | SIGTERM |
In a pipeline, --goal defines what counts as success, and the exit code decides whether the step fails. See Goal mode.
Data policy and provider filter stops
Section titled “Data policy and provider filter stops”A message your organisation’s DLP policy lets through once its sensitive data is confirmed is sent, and waibee run goes on, as the terminal does. A blocked request ends with “not sent: your organisation’s data policy blocks what this request holds”. See Data protection.
If the provider’s content filter stops a reply before anything was shown, Waibee Code retries once. Otherwise, the text shown so far stays, tool calls in that reply do not run, and the turn ends with “The provider’s filter stopped this reply. /again to retry, /model to switch models.” A goal does not continue after it, and waibee run exits with code 1.
Signals and shutdown
Section titled “Signals and shutdown”SIGINT and SIGTERM interrupt reading stdin, preparing the run, the agent’s work, and shutdown. The stream ends with one result and one done with stop_reason: cancelled and is_error: true; the single-record format prints one result. Startup errors go through the same output, but with stop_reason: error and their own exit code. Before preparation finishes, there may be no meta event.
Shutdown has a time limit, so a hung MCP server or hook cannot hold the process. SIGKILL gives the program no chance to print the final records.
One pass or a checked result
Section titled “One pass or a checked result”By default, the agent tries not to stop at its first reply: it picks a completion condition for the task and checks whether the condition is met. The extra calls cost time and tokens, and a check by a model does not replace tests. How the automatic goal works is described in Goal mode.
waibee run "move the auth module to the new client" # works until the result passes a checkwaibee run --once "explain what this file does" # one pass, no checkUse --once for questions and one-off lookups: there is nothing to check.
Flags and argument order
Section titled “Flags and argument order”Global flags can go before or after run. Flags that belong to run go after the subcommand:
waibee -m haiku run --once "summarize the README in three points"waibee -C ~/projects/api run --output-format stream-json "which endpoints are declared?"waibee run -m haiku --once "summarize the README" works too.
| Flag | Where | Purpose |
|---|---|---|
-m, --model | before or after run | Model: an alias (haiku) or a full ID |
-c, -C, --cwd | before or after run | The project’s working folder |
--mode, --permission-mode | before or after run | Permission mode: default, acceptEdits, trust, bypassPermissions |
--dangerously-skip-permissions, --yolo | before or after run | bypassPermissions mode. Not accepted together with --mode |
--sandbox | before or after run | The sandbox profile for this run: off, workspace-write, or restricted; the managed profile takes precedence |
--no-audit | before or after run | Don’t write the audit log for this run |
--bare | before or after run | Run without extensions and instructions, see Unattended runs |
--output-format | after run | Text (text), a single record (json), or a stream (stream-json), see Output formats |
--json-schema <JSON or path> | after run | Validate the final JSON |
-o, --output-last-message <file> | after run | Write the last reply |
--no-session-persistence, --ephemeral | after run | Don’t save the session, see Unattended runs |
--effort | after run | Reasoning level for this run, from none to max; the /effort choice in settings stays as it is |
--resume <id> | after run | Continue the session with this ID, see Continuing a session |
--continue | after run | Continue the last session in this folder |
--append-system-prompt <text> | after run | Append instructions to the end of the system prompt |
--tools <names> | after run | Choose the set of built-in tools |
--allowed-tools <rule> | after run | An allow rule for this run, for example 'Bash(npm test:*)'. The flag can be repeated, and tools can be listed with commas: 'Read,Grep' |
--disallowed-tools <rule> | after run | A deny rule for this run; a name without a pattern removes the tool. The flag can be repeated, and tools can be listed with commas: 'Bash,Write' |
--max-turns, --max-input-tokens, --max-output-tokens, --max-seconds | after run | Run limits, see Run limits |
--once | after run | Turn off the automatic goal; a goal set explicitly or restored with the session still applies |
--goal | after run | Completion condition, see Goal mode |
--goal-max-iterations | after run | The cap on turns with a goal check, including the first; also applies to an automatically picked goal |
--goal-model | after run | The checker model; also applies to an automatically picked goal |
Continuing a session
Section titled “Continuing a session”waibee run --continue "now add tests for empty input"waibee run --resume 3f2a "what is left to do?"--continue continues the last session in this folder or, if there is none, starts a new one. --resume finds a session by the beginning of its ID, taken from waibee sessions or from the session_id field of the output. An empty ID or a prefix shared by two sessions is rejected, and a session that is not found ends the run with code 2: no new session is started in its place. A session open in another process, such as in a terminal tab, also gives code 2. A continued run works in the folder where the session ran; if that folder no longer exists, the run uses the folder it was started from and says so on stderr.
How the model is chosen on resume is described in Choosing a model.
Run limits
Section titled “Run limits”By default, neither tokens nor time stop a run; only the turn cap max_turns does. If you need a limit, set it with a flag:
waibee run --max-seconds 900 --max-output-tokens 200000 "move the auth module to the new client"| Flag | What it limits |
|---|---|
--max-turns | Turns of the main agent; any integer from 1. The value 0 is rejected with code 2, even though max_turns: 0 in settings means the default cap |
--max-input-tokens | Billable input tokens: fresh input and cache writes, not cache reads |
--max-output-tokens | Output tokens |
--max-seconds | Time limit from the start of the run; preparation and reading stdin can take up to 10 more seconds |
The flag applies to this run and overrides the setting. The same limits for every message are set in settings, see Per-message limits.
Token limits count the turns of the main agent and its subagents. Helper calls (history compaction, the title, memory, the goal check, page summaries, web search) don’t count toward them, though they use tokens too; their usage shows in the usage line under its own purpose.
When a turn or token limit is hit, the final record holds the reply the agent managed to get. --max-seconds cancels the model request and external commands at the deadline, without a separate final turn; preparation and reading stdin are allowed up to 10 more seconds. Without the flag, this deadline comes from max_run_seconds in settings.
In these cases result and done have is_error: true, and stop_reason names the limit: max_turns, input_budget, output_budget, or time_budget. A hard deadline always gives code 1; cleanup time is limited, see Signals and shutdown.
Permissions in headless mode
Section titled “Permissions in headless mode”waibee run picks the mode by the headless rule, including with --resume and --continue: with no --mode and no permissions.mode in settings, the mode is trust. The mode is named at the start of the run: as a permission mode: <mode> line on stderr in text format, and as the permission_mode field of meta in stream-json format.
The run never waits for an answer. An action that needs approval is rejected: the agent gets the denial as the call result and keeps working. result and done list each such denial in permission_denials: the tool (tool), call_id, the arguments (args), and the reason (reason); with no denials, the list is []. The reason may suggest a broader mode, no higher than trust, in which the call would have gone through; bypassPermissions is never suggested. There is no folder trust question either: in an untrusted folder, the folder’s hooks, MCP servers, and plugin don’t start, and stderr says what was skipped. The details, including what is rejected in every mode, are in Permissions.
What this means for automation:
- Allow what the task needs up front.
allowrules insettings.json, or--allowed-toolsfor a single run, remove the question for specific commands without opening up everything. After the run, checkpermission_denials: it shows what the agent was missing. - Set a step timeout. It caps the total time of the task and its external commands.
- Restrict permissions separately from the prompt. Asking the agent to “only analyze” does not technically prevent writes. For a review, run with
--mode default: changes that need approval are rejected. Also check forallowrules that may permit writes. - Run edits in a disposable copy. A separate clone, a worktree, or a CI container: nothing is lost there if the agent does the wrong thing.
- Deny dangerous actions explicitly.
denyrules and--disallowed-tools(for example,'Bash(git push:*)') apply in every mode. - Limit turns and time.
--goal-max-iterations,--max-turns, and--max-secondskeep the work from dragging on until the runner times out.
Unattended runs
Section titled “Unattended runs”--bare turns off skills, custom commands and agents, plugins, MCP servers, hooks, instruction files (WAIBEE.md, CLAUDE.md, AGENTS.md), and memory from the project and the home folder, including .claude. This applies to the main agent and to subagents. The built-in waibee skill, which describes the program itself, stays. Settings from the data directory, authentication, and managed policy stay; project settings and compatible settings files are not read.
deny rules from the repository settings don’t apply in such a run: set the denials you need with --disallowed-tools or in the data directory settings. No MCP servers connect at all, including those from global settings, and there is no flag to connect a server for a single run.
--no-session-persistence (also --ephemeral) writes no history, internal files, or session lock, and generates no title or memory. It cannot be combined with --resume or --continue. The audit log stays on according to its own settings; --no-audit turns it off separately.
Tool set
Section titled “Tool set”--tools chooses the built-in tools once, at start: names separated by spaces or commas ("Read,Grep,Glob"), default for the usual set, or "" for no built-in tools. An unknown name gives code 2. This flag does not change MCP tools. --allowed-tools allows calls without approval and does not define the tool set. Removing a tool with deny is covered in Denying a tool.
Example: triaging an alert
Section titled “Example: triaging an alert”Pass the alert text on stdin. The agent only needs to read the project and query the monitoring system. Commands run in the restricted sandbox, which lets them reach only allowed domains, and an allow rule removes the question for curl. Save the schema from the example above to alert-schema.json. Set the WAIBEE_API_KEY key through your pipeline secrets.
export WAIBEE_NO_UPDATE_CHECK=1export WAIBEE_DATA_DIR="$(mktemp -d)"cat > "$WAIBEE_DATA_DIR/settings.json" <<'EOF'{ "sandbox": { "network": { "allowed_domains": ["prometheus.example.com"] } } }EOF
waibee --bare --sandbox restricted config check --json > config-check.jsonif ! jq -e '.sandbox.profile == "restricted" and .sandbox.verdict == "engages"' config-check.json > /dev/null; then jq .sandbox config-check.json >&2 exit 2fi
rc=0waibee run --once --bare --no-session-persistence \ --mode default --sandbox restricted --tools "Read,Grep,Glob,Bash" \ --allowed-tools 'Bash(curl:*)' \ --max-turns 12 --max-seconds 300 \ --output-format stream-json --json-schema alert-schema.json \ -o alert-answer.json \ --append-system-prompt "Triage the alert and find the code related to it. Query metrics with curl against https://prometheus.example.com. In summary, give the cause and what to check; in files, list the paths. Keep confirmed facts separate from assumptions." \ - < alert.txt > events.jsonl || rc=$?
jq -r 'select(.type == "result") | "stop_reason: \(.stop_reason) \(.stop_class // "")"' events.jsonl >&2jq -c 'select(.type == "result") | .permission_denials[]' events.jsonl >&2[ "$rc" -eq 0 ] || exit "$rc"
jq 'select(.type == "result") | .structured_output' events.jsonl > alert-report.jsonevents.jsonl holds the progress of the work, alert-answer.json the last text, and alert-report.json the validated object for the next step. The agent’s exit code is saved in rc instead of ending the script, so the stop reason and the permission denials make it into the step log; then the script exits with the same code. Code 1 means the run did not succeed, and 2 means an invocation, environment, or authentication error; either can happen after work has started, see Exit codes.
Allowed domains can be set only in settings, so the script writes them to a separate data directory: --bare reads settings from there, not from the repository. The preliminary check confirms the resulting profile with managed policy taken into account. The agent’s own network traffic, including requests to the model, is outside the sandbox. Turning off automatic update checks is covered in settings.
In a container or a Kubernetes pod on Linux, the restricted profile needs the following from the environment:
- a kernel with Landlock ABI V4 enabled (usually 6.7 or newer) on x86_64 or aarch64;
- user namespaces allowed, along with the
unshareandsetnssystem calls for the user and network namespaces. Docker’s default seccomp profile blocks them: you need a profile that allows them, or--security-opt seccomp=unconfined. In Kubernetes, this is the pod’s or container’ssecurityContext.seccompProfile, and unprivileged user namespaces must be enabled on the node; - egress from the pod to
api.waibee.comfor the agent itself, and to the domains inallowed_domainsfor commands.
waibee config check verifies this in advance: where namespaces are blocked, sandbox.verdict is refuses, and the reason names what to allow. If a required sandbox mechanism is unavailable, the run exits with code 2 and names the mechanism. List internal services with private IP addresses in allowed_domains by address, see network restrictions. Addresses are checked at request time. A pod NetworkPolicy does not replace this check: it restricts the whole pod, while the sandbox restricts the agent’s commands inside it.
Use cases
Section titled “Use cases”| Task | How to set it up |
|---|---|
| Reviewing a PR diff | git diff origin/main | waibee run "check this diff for risks", result to a file or a comment |
| Investigating a failing test | A prompt with the command that runs it: the agent reproduces the failure and explains the cause |
| Drafting a CHANGELOG | A prompt over git log between tags, output to the release file |
| Bulk edits over a list of files | A bash loop with one call per file; try it on two or three files first |
| Overnight task with a check | --goal "make lint and make test pass"; the exit code decides whether to keep fixing |
| Triaging an alert or a log | The log text in the prompt; out comes a hypothesis and a place in the code |
| A tool inside another agent | --once --output-format json, the reply in the result field (example below) |
| Pre-commit check | A git hook with a read-only prompt that returns a nonzero code when there are findings |
Keep the prompts for these use cases in custom commands in .waibee/commands/ rather than in the shell: that way they are versioned with the project.
Calling from another program
Section titled “Calling from another program”The agent is an ordinary process: start it, read stdout, and parse the JSON.
import jsonimport subprocess
TIMEOUT_SECONDS = 600
def ask(prompt: str, cwd: str = ".") -> str: process = subprocess.run( ["waibee", "run", "--once", "--output-format", "json", prompt], cwd=cwd, stdin=subprocess.DEVNULL, capture_output=True, text=True, timeout=TIMEOUT_SECONDS, ) if process.returncode != 0: raise RuntimeError(f"waibee run exited with code {process.returncode}: " f"{process.stderr.strip()[-500:]}") return json.loads(process.stdout)["result"]
print(ask("In one sentence: what does calc.py do?"))stdin=subprocess.DEVNULL keeps the agent from reading the calling program’s stdin as data for the prompt.
This is how the agent is plugged into another agent or a service as a tool. It can do what the caller cannot: work in another repository, with its files, commands, and tests.
For a conversation that keeps context between runs instead of one-off calls, see ACP in the terminal.
- name: Install the agent run: curl -fsSL https://raw.githubusercontent.com/waibee-main/waibee-code/main/install.sh | bash
- name: Review the diff env: WAIBEE_API_KEY: ${{ secrets.WAIBEE_API_KEY }} WAIBEE_NO_UPDATE_CHECK: "1" run: | git diff origin/${{ github.base_ref }}...HEAD | \ waibee run --once --bare --mode default --tools "Read,Grep,Glob" \ --max-seconds 600 \ "List the risks in this diff: logic errors, data loss, broken contracts. Only findings that matter, no retelling of the diff." \ > review.md cat review.md >> $GITHUB_STEP_SUMMARYA diff from someone else’s branch is untrusted input, so the step is locked down: --mode default rejects anything that would need approval, --tools limits the agent to reading and search, --bare skips hooks, MCP servers, and instructions from the repository, and --max-seconds ends the work before the step times out.
What to keep in mind in CI:
- Pass the key only through secrets.
WAIBEE_API_KEYgoes in the step environment, never in code. - Set a step timeout. Keep
--max-secondscomfortably below it so the agent can print its final records before the runner kills the step, see Run limits. - A fresh clone is not trusted. Hooks, MCP servers, and the plugin from the repository don’t start in an untrusted folder, and
waibee rundoes not ask about it: stderr gets a line saying what was skipped. If you need them, runwaibee config trustbefore the run, see Folder trust. - Servers with interactive authentication won’t connect in CI. The reason goes to the log, not to the step output;
DEBUG=1shows it on stderr. Keep a separate config for CI without them, see MCP. - Don’t mix reading and writing in one step. Let the review only read; make edits in a separate step that commits the result explicitly.
Next steps
Section titled “Next steps”- Goal mode: the completion condition and exit codes.
- Permissions:
allowanddenyrules. - Best practices: wording that leaves the agent nothing to guess.