Skip to main content
The CLI has two ways to run:
  • For people, in a terminal: it prints progress lines and asks before it does something you should approve (an approval(...) step, a shell command, a coding agent, an HTTP request, writing to a repository with uncommitted changes).
  • For programs, in CI, scripts and coding agents: it never asks. It prints plain text or JSON lines, and its exit code says how the run ended.
This page is about the second. Pass --no-interactive, or run where there is no terminal: the CLI also turns prompts off when CI is set, when input or output is piped, and with --format jsonl.

Run in CI

Or a registry package:
What changes without a person:
  • Approvals don’t block. A run that reaches an approval(...) step stops there, saves itself and exits. The exit code is 3. Pass --approve to give every approval up front.
  • Your own workflow runs its steps; a registry package’s need --approve. shell(...), agent(...), http(...) and pullRequest(...) steps ask a person first. With nobody to ask, a workflow file or local directory you run yourself (workflow run -w <file>, codemod run ./dir) is trusted and goes ahead. A package from the registry is not: the step fails, naming itself and the flag. That also holds for a registry package your own workflow nests with codemod(...). Read what the package runs (codemod workflow inspect, or its source), then pass --approve, or only the kinds it needs, such as --approve=shell,http: its commands run with the job’s permissions and environment, secrets included.
  • A target with uncommitted changes fails the run at its first write, before anything is written. Commit first, or pass --allow-dirty. A run that only reads isn’t stopped.
  • Capabilities are not granted. A step that needs one the run wasn’t given fails. Grant them with --allow-fs or --allow-child-process, or in the package’s codemod.yaml.
Check the result with the exit code: 0 finished, 1 failed or stopped, 2 finished with failed files or fail(), 3 waiting at an approval.

A GitHub Actions job

.github/workflows/codemod.yml
Pin the CLI version in CI, so a new release doesn’t change the job.

Turn off telemetry

Set DISABLE_ANALYTICS=1, or DO_NOT_TRACK=1, in the job’s environment.

Read the output

Plain text is meant for logs. For a program, use --format jsonl: one JSON object per line on stdout.
The last line is run_finished, with status, output (what the workflow returned), error and question. After the run, read it again any time:
workflow status has the run’s status, output, exitCode, question and each step’s result. See Build a report that fails CI.

Continue a run that waits

A run stopped at an approval is saved. Approve it from the next CI job, a person’s terminal, or a script:
--approve approval:1 gives that approval only; the run stops at the next one. --approve alone gives every approval left. Finished steps are not run again.

Drive a run from a program

A coding agent or a wrapper that wants to answer questions as they come, in the same process, uses --control stdio with --format jsonl. The run prints events on stdout, reads commands on stdin, and waits at each question for an answer:
Closing stdin pauses the run. Approvals and CI has a 20-line Node.js driver, and Drive codemod from a program has the full protocol.

Tips for agents

  • Always pass --no-interactive (or --control stdio). A run that asks with nobody to answer would wait.
  • Start with --dry-run: it changes nothing and prints the diff it would apply. A dry run that reaches an approval exits 1; add --approve to see past it.
  • Use workflow inspect -w <workflow> --format json to see a workflow’s parameters, their types and defaults before you run it.
  • Pass parameters with --param key=value. A parameter declared as string stays a string.
  • Read results from workflow status --format json, not from the text output.