Skip to main content
A program that runs codemod for someone (a terminal UI, a coding agent, a CI wrapper) starts it as a child process with --format jsonl --control stdio. The run prints one JSON object per line on stdout, and reads commands, one JSON object per line, on stdin. When the workflow asks something (an approval(...) step, a shell command, a coding agent to pick), the run waits for the answer instead of exiting.
The TypeScript types for everything below are in the codemod npm package:

What the run prints

The first line is hello. It names the run before anything happens, so a client can attach, cancel or resume it later:
Then come the run’s events, the same as --format jsonl prints without a control channel (see --format). Each has seq, which counts up through the whole run, also across resumes, and ts. Step events name their step with step, a key that stays the same across resumes ("3"; "3/0" for step 0 of the codemod that step 3 runs, whose parent is "3"). When a workflow first uses an experimental API, an experimental event names it in api. A run emits at most one notice per API, even if it resumes. This event is part of the event stream, not the workflow result. A question looks like this:
Questions come one at a time. When one is answered, or closed because the run stops, question_closed says how: answer is "approved", "rejected" or "later" (an agent’s id, or null, for agent questions), and by is "answer", "stop" or "eof". --approve still gives approvals up front, without asking.

Commands

  • approve and reject answer an approval. answer takes "approve", "reject" or "later" (only for manual approvals and interrupted steps) for approvals, and an available agent’s id, or null for the built-in agent, for agent questions. questionId is accepted for question_id.
  • stop stops the run: "pause" (the default) leaves it paused, to resume; "cancel" ends it as canceled.
  • A command that cannot be followed (not JSON, not UTF-8, no such open question, a wrong answer) gets a control_error event with the message and the line; the run goes on, and so does reading commands.
  • Closing stdin pauses the run, as stop does, and closes the open question. Keep stdin open for as long as the run should go on.
An interrupted-step question comes before run_started. Answer "approve" to rerun that step, "reject" to skip it without rejecting the run, or "later" to leave the run as it was and exit 3. --approve does not answer these questions; use --rerun-step or --skip-step to decide up front.

How a run ends

A run paused at a question still waits for it. When you stop or close stdin while a question is open, the run is paused, and run_finished (and workflow status --format json) keep that question’s question id and awaiting message. The approval step is awaiting-approval, not canceled. Resume it with workflow resume --id <ID> --approve <question id> to give that approval, or without --approve to be asked again. A rejected approval ends the run. Nothing after it runs, steps running alongside stop, and what earlier steps changed stays changed. The process exits with 1, as it does for paused and canceled, and with 3 for awaiting-approval (see exit codes); run_finished has the status. A dry run with a control channel waits at its questions like a real run, and approve lets it go on and report its diff. Without one, a dry run that reaches an approval exits with 1: it is not saved, so it cannot wait to be resumed.

Attach to a run

Experimental. This can change in a minor release of the CLI, but not in a patch. Pin the CLI version (npx codemod@<version>) if you build on it.
Every saved run keeps its events in the run store. workflow attach prints them, after a hello (with "mode":"attach" and no commands), and follows the run while another process executes it:
It ends when the run stops executing. It only watches: the questions are answered by the process that has the control channel.

Read runs and workflows

  • workflow list --format json and workflow status --id <ID> --format json print runs; status has question, the approval a waiting run needs. If the run pauses while a question is open (for example, stop or closed stdin), it keeps that question.
  • Experimental: workflow inspect -w <file|dir> --format json describes a workflow for a setup form: declared params with their types, doc comments and @defaults, imports, which declared steps reach outside the target (http, shell, agent, …), and its step(...) calls. See workflow inspect.