Automation and AI agents
What to know when using co from scripts, CI and AI agents: non-interactive runs, JSON output, token login, agent footer
co serves human terminals, scripts and AI agents with the same commands. Only a few rules differ. The computer the agent uses also needs co installed and logged in first. See the Quick start.
Teaching an AI agent about co
co guide prints recipes by topic: which commands to run, in which order, for a given situation. Put the line below in the agent's project instructions (CLAUDE.md, AGENTS.md and so on), and the agent follows the commands and options of the installed co version.
Before using co, run co guide and read it. Check a command's options with co <command> --help.co guide # all topics at once (good for an agent to read once and get the map)
co guide --list # list of topics
co guide cr # one topicThe output is plain text without color. Topics for features not available on the CollabOps you are connected to are not listed.
Reading output
| Rule | Details |
|---|---|
| Tables are for people | They contain colors and truncation (…), so do not parse them |
--json is for machines | Commands that support it emit fixed fields, so jq can read them reliably |
| stdout / stderr | Data goes to stdout, progress and hints to stderr |
| Messages | They switch between Korean and English with the language setting. Do not grep messages. Decide by exit code and --json |
| Exit code | Each kind of failure has its own exit code. See Exit codes and errors below |
co cr list -s merged -l 0 --json | jq -r '.items[].key'
co issue list --scope workspace --open --jsonExit codes and errors
co exits with a different code depending on why it failed. Scripts that only check for non-zero keep working.
| Code | Meaning | Next step |
|---|---|---|
| 0 | Success (warnings included) | |
| 1 | Any other failure, including when co refused before sending | Read the message |
| 2 | Wrong option, argument or command | See --help |
| 3 | Fix the input (400, 422) | Fix it and send again |
| 4 | The state changed in between (409) | Read it again and decide. Do not resend as is |
| 5 | Not logged in or no permission (401, 403) | Log in, or ask someone who may |
| 6 | Not found (404) | Check the key and the scope |
| 7 | Server error, timeout or network (408, 429, 5xx) | Try again later. For a write, check the result first |
When a command run with --json fails, stderr gets one line of JSON instead of the error: line, and stdout stays empty.
{"error": {
"status": 409, // HTTP status (null when co refused before sending)
"code": "...", // the server's error code
"reason": "stale_version", // machine-readable reason ("" when none)
"title": "...", "message": "...",
"exit_code": 4,
"retryable": false, // true only when sending again cannot apply a write twice
"details": [{"path": "...", "location": "...", "message": "...", "kind": "...", "params": {}}]
}}details[].kind is the reason the server sent (for example manual_run_recent or duplicate_pipeline_name), else its error code. reason is set when there is one problem and it has a reason. A write that timed out may have reached the server, so retryable is false; check the result before sending again. What to do for each reason in pipeline commands is in Do the same with co.
co pipeline apply -f p.yml 42 --if-version 3 --json 2> err.json
echo $? # 4
jq -r .error.reason err.json # stale_versionLanguage
When an AI agent runs co, its messages, errors and --help are in English regardless of the user's language setting. Claude Code is detected automatically through CLAUDECODE=1, and for other agents CO_AS_BOT=1 does the same. If the agent needs Korean, give it CO_LANG=ko. The order in which the language is decided is under "Language" in Environments and settings.
Non-interactive runs
Without a terminal, co does not ask. It fails and tells you which options it needs. For example, co issue create requires -t, -b (or -F), --type and --priority, and delete commands require --yes. Automatic updates and the Git setup offer also do not run without a terminal.
Log in
Where there is no browser, log in with a token. Passing it on standard input keeps it out of your shell history.
echo "$COLLABOPS_TOKEN" | co auth login --token -For self-hosted CollabOps, also give --host https://<your address>. Without a terminal and without an address, co logs in to collabops.ai.
Inside a CollabOps pipeline, clone with co repo clone <repo> --https and git authenticates with the credentials the pipeline provides (COLLABOPS_JOB_TOKEN). co calls the API to find the repository, so a co login is also needed.
Marking CRs created by an agent
When an AI agent creates a CR, co adds a footer at the end of the description saying which agent and model created it. It is added automatically when the environment variable CLAUDECODE=1 or CO_AS_BOT=1 is set, and --bot forces it. Give the model name with CO_BOT_MODEL.
CO_BOT_MODEL="<model>" co cr create --bot -t "<title>" -B main -F body.mdDebugging
With CO_DEBUG=1, every HTTP request and response is printed to stderr. Secret values in headers are masked.
CO_DEBUG=1 co cr list