Skip to main content
This page tells a coding agent such as Claude Code, Codex or Cursor how to test and fix an AI agent with the Ancha CLI, version 0.1.4. The same text is at /coding-agents.md as Markdown, and the whole site is at /llms-full.txt.

Install

Ancha needs Node.js 24 or later. Check the install with ancha --version. It prints 0.1.4.
With npx, use the full package name, @ancha-labs/cli. There is no ancha package on npm. The instruction files ancha init writes say the same: run every command as npx -y @ancha-labs/cli <command> until the CLI is installed, then as ancha <command>.

The three commands

Run every command from the project root, where ancha.yaml lives. ancha doctor --json checks the setup between steps 1 and 2. It runs the agent once and confirms it reached each tool. A tool the agent did not call is a warning, not a failure, and doctor exits 0. Every command ends with next: <exact command> in text, and with a next list in JSON. Follow it. To prove a fix, save the failing run, change the agent, and compare:
Exit code 0 means every check passed and no scene and no check got worse than before.

How your agent reaches the tools

Ancha starts the agent with tool URLs and fake credentials in environment variables, for example SLACK_API_URL and SLACK_BOT_TOKEN. The agent must use them instead of real service URLs. ancha connect <tool> --lang ts (or --lang py) prints SDK settings for a tool. See Environment variables for the full list. The agent runs as a process on this computer with this computer’s network. Its environment holds a base set (PATH, HOME, locale and the like), Ancha’s variables and the tools’ variables. Anything else from the shell, such as a provider key, reaches it only through agent.pass_env in ancha.yaml or --pass-env NAME. For a sealed run, set agent.execution: { mode: container, image: node:24-slim } in ancha.yaml; it needs Docker. See ancha run.

JSON output

Add --json to any command for machine-readable output on stdout, or set ANCHA_JSON=1, which acts as --json on every command.
  • ancha run --json, ancha wait --json and ancha logs --json print newline-delimited JSON (NDJSON): one event per line, ending with run_finished. Do not parse stdout as a single JSON object.
  • Every other command prints one JSON object.
  • Errors print one object with an error key, and the process exits with the code in the table below.
  • ancha schema <kind> --json prints the JSON Schema of ancha.yaml, scene files and these outputs: run_started, run_finished, explain, world_up, check and error.
Error
Events from ancha run --json, in order:
ancha run --json (failing run)

Retrying safely

If your command can time out, give ancha run an --idempotency-key <key>. Running it again with the same key returns the same run instead of starting another, with replayed: true. While the first run is still going, the retry fails with SESSION_CONFLICT and a hint to ancha wait <id>. Use a new key for a new run. ancha run --detach --json returns a run ID at once; follow it with ancha logs <id> --follow --json, which exits with the run’s exit code.

Exit codes

When several apply, 3 wins over 4, and 4 wins over 1. ancha explain exits 0 even when it lists failures, so read the exit code of ancha run.

Read a verdict

The run_finished summary holds the verdict. These fields matter most: Read it in this order:
  1. Exit 2 or 3: fix the setup or retry. Do not change the agent yet.
  2. agentIssues is not empty: the agent crashed or timed out. ancha explain shows the end of agent.log.
  3. failures is not empty: compare expected with actual, then read the trace. Many bugs only appear with the world’s data, so read the evidence before guessing from the code.
  4. coverageGaps is not empty: the replica answered with an error because it does not implement that call. Check ancha twins coverage <tool> before you change working code.
  5. agentEnvironment.withheld is not zero and the agent needs one of those variables, such as a provider key: pass it with --pass-env NAME or agent.pass_env.
A clean process exit does not mean the task passed. Only checks decide that.

Rules for coding agents

  • Fix the agent’s code. Do not edit ancha.yaml, the scenes or their checks to make a run pass. The exception is a check that is wrong for the real API, such as a method the official SDK never sends: tell the user, show the evidence from ancha explain and the vendor’s documentation, and change it only with their agreement.
  • Never point the agent at real SaaS URLs, and never give it real credentials.
  • Never give the agent under test the scenes, checks, seeds or reference companions (oracle.mjs, null.mjs).
  • Use --compare against a saved baseline to prove a fix. Never compare a run with itself.
  • Keep --json on every command, and read the exit code.
The starter scene only proves the agent can reach each tool. Replace it with a scene that checks real work. Its checks accept any HTTP method (* /api/*.* for Slack), so an agent built on an official SDK passes them as it is.

Hosted workspace

If the user has an Ancha workspace, ancha login asks them to approve this computer once in the browser; ask them to do it. A signed-in ancha run still runs the agent and its worlds on this computer, and its first line names the workspace. ancha run --upload sends the finished run to that workspace, where the console shows it. ANCHA_SERVER_URL, server.url in ancha.yaml or --server-url put the worlds in the workspace instead, and --local keeps a command on this computer. ancha whoami --json shows which workspace commands use. In CI, ANCHA_SERVER_URL and ANCHA_API_KEY replace the login, and ancha run --local --upload keeps the worlds on the runner and sends the results to the workspace. See Hosted workspace and Results in your workspace.

Your own harness

To start the agent yourself, start a world instead of a run:
ancha world trace --env <envId> --json shows the calls so far. See World lifecycle. ancha world gen "<description>" --json writes a world file from a description; it needs OPENROUTER_API_KEY. See ancha world gen.

What ancha init writes for coding agents

See ancha init.

Prompt for your coding agent

Paste this into Claude Code, Codex, Cursor or another coding agent, in the repo of the agent you want to test:
Prompt

Discover the CLI

  • ancha --help is one page; ancha advanced lists the rest; ancha --help --json prints every command and flag as one JSON tree.
  • ancha <command> --help prints one command’s flags and defaults.
  • ancha schema --json prints every schema; ancha docs <topic> prints the bundled guide.
  • CLI reference documents every command in 0.1.4.
  • Errors lists every error code.