Skip to main content
workflow.yaml is the legacy workflow format. It still runs: the CLI translates it into the equivalent workflow.ts before running it. New workflows should use TypeScript. Convert an existing package with:
In a repository with many packages, run it once at the root to upgrade them all. See Migrate from workflow.yaml.

What changed in the compatibility layer

  • js-ast-grep steps get file-scope semantic analysis unless semantic_analysis: none is set, as codemod jssg run and codemod jssg test do.
  • state.schema is accepted but not used. State is not validated.
  • runtime: docker and runtime: podman are not supported yet: a workflow with them is refused before it runs. Use the opt-in 1.x fallback if it needs those runtimes.
  • A step if: condition that fails to evaluate still skips the step, and the run’s log now says so.
  • Fields that never had an effect (codemod.args, codemod.env, codemod.working_dir, unused ai options, template outputs) are reported as warnings by codemod workflow validate and codemod workflow upgrade.
  • Runs are resumed with codemod workflow resume --id <run-id>; manual nodes become approval steps, resumed with --approve.
This reference documents the complete workflow.yaml specification.

Complete Example

This example demonstrates all five step types working together in a migration workflow:
workflow.yaml

Workflow Structure

A workflow has four top-level keys:
workflow.yaml

Nodes

Nodes are execution units in your workflow. They can be automatic or manual, depend on other nodes, and may define strategy (matrix), trigger, runtime, env, and an ordered list of steps.
string
required
Unique identifier within the workflow.
string
required
Display name shown in logs and UI.
string
default:"automatic"
automatic or manual.
string[]
Upstream node IDs that must complete before this node runs. See Cyclic Dependencies.
object
{ type: manual } creates an approval gate. See Manual Triggers.
object
Matrix configuration for parallel fan-out. See Matrix Strategy.
array
required
Ordered list of steps to execute.
object
Environment variables for all steps in this node.

Git Automation (Campaign/Cloud Runs)

In Campaign/cloud runs, each task executes on its own git branch. Codemod creates that branch before the node’s steps run, can create commits after successful steps, and pushes the branch plus opens a pull request when the node ends with commits. All tasks share one checkout, so the tasks of a matrix node that uses git run one at a time, and two nodes that use git must not run at the same time.
These git automation fields are only used in Campaign/cloud runs. Local codemod workflow run execution does not create branches, commits, or pull requests automatically.
string
Branch name template for Campaign/cloud runs. The branch is created before the node’s steps run. If omitted, Codemod uses codemod-<task.signature>.
object
Pull request customization for Campaign/cloud runs. If the node ends with commits, Codemod pushes the task branch and attempts to create a pull request. This field customizes the PR metadata; omitting it does not disable PR creation.
string
required
Pull request title template.
string
Optional pull request body template.
boolean
default:"false"
Create the pull request as a draft.
string
Base branch to merge into. If omitted, Codemod auto-detects the remote default branch.
Default Campaign/cloud behavior:If the node ends with commits and pull_request is omitted, Codemod attempts to open a pull request using the node name as the default title. If no explicit commit checkpoint was created and changes remain at the end of the node, Codemod attempts a fallback commit using the node name before pushing and opening the pull request.

Steps

Steps are atomic actions inside a node. They run sequentially and each step performs one transformation or action.

Common Step Fields

All step types support name, if, env, and commit.
string
required
Step label.
string
Conditional expression to gate step execution. Current runtime support for generic step conditions includes params.x, state.x, and matrix.x. See Variable Resolution.
object
Step-level environment variables applied to the process environment.
object
Optional commit checkpoint for Campaign/cloud runs. After a successful step, Codemod stages the configured paths and creates a git commit. If no step creates a commit but changes remain at the end of the node, Codemod attempts to create a fallback commit using the node name before pushing and opening the pull request.
string
required
Commit message template.
string[]
Paths to stage before committing. If omitted, Codemod stages the entire working tree for that task branch.
boolean
default:"true"
If true, skip the checkpoint when nothing is staged. If false, the step fails when there are no staged changes to commit.
Commit checkpoints are Campaign/cloud-only. They run after successful steps on the task branch created for the node.

JSSG Step

Executes a JavaScript/TypeScript codemod using ast-grep for pattern matching and AST manipulation.
JSSG Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. Supports params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||. See Variable Resolution.
string
required
Path to the JS/TS file that implements the codemod.
string
Target language (e.g., typescript, tsx, javascript, jsx).
string[]
Include glob patterns.
string[]
Exclude glob patterns.
string
Base path for resolving globs.
number
Maximum concurrent threads.
boolean
default:"false"
Perform a dry run without applying changes.

JSSG Documentation

Learn how to write JavaScript/TypeScript codemods.

AI Step

Calls an AI agent with a prompt for LLM-powered transformations.
AI Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. See Variable Resolution.
string
required
Prompt to send to the AI agent.
string
default:"gpt-4o"
Model identifier. Overrides LLM_MODEL if set.
string
System prompt to scope the AI agent’s behavior.
number
default:"30"
Maximum number of agent steps before stopping.
string
default:"openai"
LLM provider/protocol. Supported: openai, anthropic, google_ai, azure_openai.
string
LLM base URL. Defaults to the provider’s standard endpoint.
string
API key for LLM access.
Environment variables for AI steps

Install Skill Step

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.
Installs package skill behavior into a supported harness via the Codemod CLI. Use this in skill-only or workflow + skill packages when you want authored skill files from the package to be installable for coding-agent workflows.
In dry-run mode, this step is skipped. In non-interactive runs, it is also skipped by default unless the workflow is run with --install-skill. See CLI reference. The target package must expose an authored SKILL.md with valid frontmatter and the authored-package markers:
If you see mcs-v1, that is the marker for the built-in Codemod core skill profile, not for authored package skills installed by this workflow step. Install Skill Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. See Variable Resolution.
string
required
Package identifier to install, for example @codemod/jest-to-vitest.
string
Optional authored skill source path inside the package. Defaults to the conventional agents/skill/<skill-name>/SKILL.md layout.
string
default:"auto"
Target harness adapter: auto, claude, goose, opencode, cursor, or codex.
string
default:"project"
Install scope: project or user.
boolean
default:"false"
Overwrite existing skill files if needed.

YAML ast-grep Step

Executes ast-grep using declarative YAML rules for simple, fast pattern matching.
When to use YAML ast-grep vs JSSG
  • YAML ast-grep: Simple find/replace, no conditional logic, fastest to write
  • JSSG: Conditional logic, complex AST manipulations, cross-file coordination
YAML ast-grep Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. See Variable Resolution.
string
required
Path to the ast-grep configuration file (.yaml).
string[]
Include glob patterns.
string[]
Exclude glob patterns.
string
Base path for resolving globs.
number
Maximum concurrent threads.

Codemod Registry Step

Runs another codemod by package name or local path.
Codemod Registry Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. See Variable Resolution.
string
required
Codemod source (registry package or local path). Supports version pinning: @scope/pkg@1.2.3. A local path that starts with ./ or ../ is relative to the directory that contains the workflow file with the step, not to the directory you run the CLI from.
string[]
CLI arguments passed to the codemod.
object
Environment variables used during execution.
string
Working directory for execution.
You can aggregate multiple codemods by adding multiple codemod steps in the same node. Steps run sequentially from top to bottom.

Shell Command Step

Runs shell commands on the host for setup, cleanup, or external tools.
On macOS and Linux, use $CODEMOD_PATH to run a shell script bundled with your codemod package. It points to the package root. Quote the script path so it works when the package directory contains spaces:
workflow.yaml
Shell Command Step Parameters:
string
required
Step label.
string
Conditional expression to gate step execution. See Variable Resolution.
string
required
Inline shell command to execute. It runs with sh -c on macOS and Linux, and as a batch file with cmd.exe on Windows. Use the CODEMOD_PATH environment variable for scripts or files bundled with the codemod package.
On Windows, every line runs in order and the step’s exit code is the last command’s, as with sh. Batch-file rules apply: write a literal % as %% (for example in a URL, %%20) and for loop variables as %%i. A command that is itself a batch file, such as npm, npx or pnpm, is run with call automatically at the start of a line or after &, && or ||, so the lines after it still run. Inside if or for, write call npm ... yourself.
object
Step-level environment variables applied to the process environment.

Shard Step

Evaluates file shards and writes results to workflow state for use with matrix strategies. Supports built-in grouping algorithms (directory, codeowner) and custom shard functions.
Shard Step Parameters:
string
required
Step label.
object
required
Sharding method. Either { type: "directory" | "codeowner", max_files_per_shard: N } for built-in methods, or { function: "path/to/shard.ts" } for custom logic.
string
default:"."
Root directory to scan for files. Defaults to the workflow run target.
string
required
State key to write shard results to.
object
JSSG codemod configuration for pre-filtering. Dry-runs the codemod and only shards files where the transform produces changes.
string
Glob pattern for eligible files (used when js-ast-grep is not set).

Sharding Guide

Full guide covering built-in methods, custom functions, re-evaluation, and examples.

Matrix Strategy

Matrix strategies fan out a node into multiple parallel tasks. Use them to shard work by team, directory, or configuration.
The from_state field references an array in your workflow’s state schema. Each array item spawns a parallel task. A matrix node with branch_name, pull_request or a step commit runs its tasks one at a time instead: they share one git checkout. Accessing Matrix Values: In JSSG transforms via options.matrixValues:
In shell steps as environment variables:
Dynamic Matrix Task Recompilation: When the array referenced by from_state changes:
  1. New tasks are created for new items
  2. Tasks are marked WontDo if their item is removed
  3. Existing tasks remain untouched if their item persists
Matrix nodes have a master task that tracks all generated tasks.

Manual Triggers

Add approval gates to pause execution until manual intervention:
Resume a run waiting for approval:
The 1.x resume flags --tasks_ids and --dry-run are gone: --approve <question-id> replaces --tasks_ids, and a dry run is not saved, so it can’t be resumed. See Upgrade from 1.x.

Shared State

State enables workflows to persist data across runs and coordinate work:
You can also use object map syntax:

State Updates

A line splits at its first =, so a value may contain =, and its key can’t be empty or start or end with a space. A value that parses as JSON is stored as JSON (10 is a number, true a boolean); anything else is stored as a string. Updates are applied only if the step exits successfully.
State belongs to one workflow run. A nested codemod: step runs the other package as its own workflow, with its own state: it doesn’t see the parent’s state, and what it writes doesn’t come back. Pass values to it with params instead. JSSG transforms cannot read or set workflow state; codemod workflow upgrade flags each transform step in a workflow that uses state.

Parameters

Parameters make workflows configurable and reusable:

Accessing Parameters

In JSSG transforms via options.params:
In shell steps as PARAM_ prefixed environment variables:
In codemod steps forwarded with env_ prefix:

Advanced Parameter Usage

Complete parameter patterns and examples in JSSG.

Variable Resolution

Workflow expressions are evaluated in a few different runtime contexts today. The available variables are not identical across all of them.

Template interpolation

${{ ... }} interpolation is used in:
  • run
  • ai.prompt
  • branch_name
  • commit.message
  • pull_request.title
  • pull_request.body
Current variable availability:
In matrix tasks, each object key becomes an environment variable (e.g., $team, $shardId). Inside steps, matrix variables are unprefixed.
${{ env.x }} and generic steps.<id>.outputs.* interpolation are not wired into workflow runtime expression resolution.

if Conditions

Current generic workflow if evaluation receives:
  • params.*
  • state.*
  • matrix.*
Current generic workflow if evaluation does not receive:
  • task.*
  • env.*
  • steps.<id>.outputs.*
Operators supported in if conditions: ==, !=, >, <, >=, <=, &&, ||

Task Statuses

Local workflow failures do not roll back earlier writes or shell-command changes. Start from a clean commit or another recoverable baseline, then review git diff and git status after a failure before retrying.

Cyclic Dependencies

Workflows cannot have circular dependencies:
This produces an error:

Templates

Templates define reusable step blocks. Invoke one with use.template and pass values through use.inputs; these values merge into params, overriding same-named workflow parameters for the template’s steps. Conditions on template steps use those merged parameters.
workflow.yaml
Supply the values needed by the template explicitly in use.inputs; the example prints Ready for review. This shell example uses a fixed, trusted message: do not interpolate untrusted values into shell commands. A condition on the invoking step can also skip the entire template.

Next Steps

Package Structure

Directory layout and codemod.yaml reference.

CLI Reference

Validate and run workflows from the command line.

JSSG

Write JavaScript/TypeScript codemods.

Publishing

Share your codemod via the Registry.