Skip to main content

Quickstart

New to Codemod? Follow the step-by-step guide to scaffold, test, and publish your first codemod.

Install

Run the CLI with npx, or install it globally:
Codemod 2.0 is published on npm under the next tag, and latest is still 1.x, so a plain npx codemod runs 1.x. Inside a package, add codemod as a dependency and its scripts run that version.

Command Relationships

The Codemod CLI provides different commands for different stages of development:

High-Level Commands (Production)

Use for: Production codemods, multi-step workflows, parameterized transforms

Quick Testing Commands (Development)

Use for: Rapid iteration, testing patterns, development

Package Lifecycle

When to use what: Use codemod workflow run for orchestrated, multi-step transformations with parameters. Use codemod jssg run for quick testing of a single jssg transform during development.

Telemetry

When analytics are enabled, the CLI sends product telemetry to PostHog (and a separate Scarf gateway for install/usage signals). Logged-in users are keyed by their Codemod account id. Anonymous installs use a local telemetry id and are never aliased to an account. For logged-in sessions only, the CLI may also send a separate PostHog $set with the account email so dashboards can show people instead of raw UUIDs. That update is PostHog-only (not Scarf), deduped locally, and skipped when you opt out. The first interactive run shows a one-line notice about telemetry. The CLI remembers that it showed the notice. It does not show the notice in CI, without a terminal, with --no-interactive, or in JSONL and --control mode. Use codemod telemetry off to opt out on this installation. Check your effective setting with codemod telemetry status, or restore the default with codemod telemetry on. Disable all of this for a single invocation with --disable-analytics, or by setting DISABLE_ANALYTICS=true / DISABLE_ANALYTICS=1 in the environment. DO_NOT_TRACK=1 (any value but empty, 0 or false) does the same. The flag works on explicit commands and on implicit package runs such as npx codemod@next @org/package --disable-analytics. These overrides still apply after codemod telemetry on. More detail: Telemetry compliance.

CLI Command Reference

Codemod CLI is accessible using the npx codemod@next command. The following commands and options are available:

codemod ai

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.
In an interactive terminal, bare npx codemod@next opens a launcher that asks whether to create a package or run one from the registry. In non-interactive contexts, the CLI prints next steps and exits with status 1.
Manage Master Codemod Skill (MCS) lifecycle for supported harnesses. ai Install the codemod MCS skill package, configure Codemod MCP, and install the universal /codemod entrypoint where the harness supports it.
Interactive prompts are enabled by default in TTY sessions. Use --no-interactive to skip prompts and use flags/defaults directly. With --harness auto (the default), install first checks whether it is running inside a coding agent (Claude Code, Codex, Cursor, OpenCode, Goose or Antigravity) and sets up that agent. Otherwise it looks for an agent folder or config file in the project, such as .claude, .cursor, .codex or opencode.json, and prefers Claude Code when it finds several. If it finds neither, it sets up Claude Code and warns, so pass --harness to choose another agent. The output says which agent was set up and why, marks files that a re-run left unchanged as up to date, and ends with numbered next steps for that agent, such as approving the MCP server in Claude Code or trusting the folder in Codex. Along with skill files, install writes or updates a Codemod MCP server entry. Project installs (--project) write a portable launcher pinned to the CLI version that ran the install, so the config can be committed and used on other machines and checkouts:
User installs (--user) stay on the current machine, so they launch the installed codemod executable directly. If the CLI itself was run through npx, its cached executable is temporary, so user installs fall back to codemod on PATH (outside the npx cache) or the same pinned npx launcher. Re-running ai --project repairs one known broken entry without --force: a project entry whose command is an absolute path to an executable inside npm’s npx cache (_npx), which earlier releases wrote. Every other existing codemod entry is kept and reported as a conflict, including absolute paths outside the npx cache, older pinned codemod@<version> launchers, and all user-scope entries. Re-run with --force to replace it. Prerequisites for project installs:
  • The project MCP launcher needs Node.js and npm (npx) on every machine that uses the committed config. The first launch of a pinned version downloads it from the npm registry unless it is already in the npm cache.
  • If npm is not available, use --user with an installed codemod executable instead.
  • The Claude periodic update hook runs a POSIX shell script. Claude Code runs hook commands with sh on macOS and Linux and with Git Bash on Windows, so Windows machines need Git for Windows; the hook does not run under PowerShell.
For Opencode, install writes opencode.json using the Opencode-specific mcp schema instead of mcpServers. MCP config paths by harness and scope:
  • claude: ./.mcp.json (project), ~/.claude.json (user, the same file claude mcp add -s user writes; other keys in it are kept)
  • goose: ./.goose/mcp.json (project), ~/.config/goose/mcp.json (user)
  • opencode: ./opencode.json (project), ~/.config/opencode/opencode.json (user)
  • cursor: ./.cursor/mcp.json (project), ~/.cursor/mcp.json (user)
  • codex (CLI + macOS app): ./.codex/config.toml (project), ~/.codex/config.toml (user) under [mcp_servers.codemod]
If a conflicting Codemod MCP entry already exists, re-run with --force to overwrite it. For Opencode, Codemod leaves any legacy ./.opencode/mcp.json or ~/.opencode/mcp.json file in place to avoid deleting unrelated MCP servers. ai also upserts a managed Codemod discovery section in harness discovery guides (project root for --project, home directory for --user) without duplicating entries:
  • claude: CLAUDE.md
  • goose: AGENTS.md and .goosehints
  • cursor: AGENTS.md
  • opencode: AGENTS.md
  • codex: AGENTS.md ai also installs /codemod where the harness has a native command or workflow file surface:
  • claude: ./.claude/commands/codemod.md (project), ~/.claude/commands/codemod.md (user)
  • goose: ~/.config/goose/recipes/codemod.yaml + ~/.config/goose/config.yaml registration (user only)
  • opencode: ./.opencode/commands/codemod.md (project), ~/.config/opencode/commands/codemod.md (user)
  • cursor: ./.cursor/commands/codemod.md (project), ~/.cursor/commands/codemod.md (user) The installed /codemod command routes by intent:
  • create, scaffold, or refine codemods -> codemod authoring flow
  • search, run, or apply existing codemods -> registry discovery and execution flow
The generated Codemod skill package includes these authored files:
  • SKILL.md: the main skill instructions and Codemod-specific authoring and execution defaults
  • agents/openai.yaml: the Codemod agent interface definition used by compatible harnesses
  • commands/codemod.md: the /codemod command routing rules for harnesses with a native command surface
The installed skill also points users to CLI fallbacks when MCP is unavailable or blocked. The main user-reproducible commands are:
  • npx codemod@next ai docs: list docs resources exposed through the CLI
  • npx codemod@next ai docs <resource-id>: read a specific docs resource such as codemod-cli, codemod-creation-workflow, or codemod-troubleshooting
  • npx codemod@next ai dump-ast <file> or npx codemod@next ai dump-ast --: inspect AST shape for a file or stdin
  • npx codemod@next ai node-types <language>: inspect tree-sitter node kinds for a language
  • npx codemod@next ai call validate_codemod_package --input '{"package_path":"."}': validate whether a codemod package still contains starter scaffold markers or other package-surface issues
  • npx codemod@next ai feedback --category <category> --message <message>: submit short anonymous platform feedback after consent is recorded
ai also wires a periodic, cooldown-protected update check trigger:
  • claude: hooks.SessionStart command in ./.claude/settings.json (project) or ~/.claude/settings.json (user). The project hook runs "$CLAUDE_PROJECT_DIR"/.claude/codemod/periodic-update/check-updates.sh, so it keeps working after the project is cloned or moved. Re-running ai replaces a project hook that an earlier install wrote with an absolute runner path, including one written from a different checkout. Only unmodified generated hooks with an unambiguous absolute runner command are migrated automatically. Commands containing whitespace (including old unquoted paths with spaces), quoting, arguments or shell syntax are preserved, as are hooks with custom matchers, timeouts or other fields. Review and remove obsolete preserved hooks manually when moving a checkout; install adds the portable hook without deleting those commands.
  • cursor: hooks.afterAgentResponse command in ./.cursor/hooks.json (project) or ~/.cursor/hooks.json (user)
  • opencode: plugin codemod-periodic-update.js in ./.opencode/plugins/ (project) or ~/.config/opencode/plugins/ (user), listening to session.idle
  • goose: managed codemod-periodic-update block in ./.goosehints (project) or ~/.config/goose/.goosehints (user) as fallback guidance
  • codex: notify = ["sh", "<runner>"] in ./.codex/config.toml (project) or ~/.codex/config.toml (user) Managed update policy is install-flag driven and shared by install-time reconciliation and periodic checks:
  • --update-policy <manual|notify|auto-safe> (default: auto-safe)
  • --update-source <local|registry|URL> (default: registry)
  • --require-signed-manifest or --allow-unsigned-manifest (optional override) --update-source only accepts local, registry, or an absolute http(s) URL (legacy registry:/url: aliases are rejected). Project periodic runners use the same pinned npx -y codemod@<installing CLI version> launcher as project MCP, even when another global CLI version is installed. User runners retain their local executable/PATH fallback. Periodic runs enforce signed manifest verification via --require-signed-manifest in the generated runner command. After install, restart or reload your harness session so newly installed skills and command entrypoints are picked up.
ai feedback Submit short anonymous platform feedback for Codemod AI, MCP, JSSG, workflows, docs, CLI, registry, or related surfaces. The command records anonymous feedback consent in the user-wide Codemod config, including the timestamp at which this OS user allowed feedback submission.
Recommended categories are jssg, workflow, ai-docs, mcp, cli, registry, package-validation, and other. Examples:
Feedback is anonymous. Do not include source code, secrets, auth tokens, private repository paths, user identity, or long transcripts in the message. ai update Run managed update reconciliation/apply through CLI (same policy engine used by periodic hooks).
If managed install state is missing, ai update automatically falls back to an install flow and then applies update reconciliation. ai performs internal skill validation checks during install flow. ai list List installed Codemod skills for a harness.
Use this command to inspect which Codemod-managed skills are already installed for a given harness before running codemod ai again or troubleshooting harness setup. ai dump-ast Dump AST nodes for a source file or stdin using the same parser surface exposed through Codemod MCP.
  • Omit FILE or pass - to read from stdin.
  • If you do not pass --language, the CLI infers it from the file extension when possible and otherwise defaults to tsx for stdin.
ai node-types Print tree-sitter node types for a supported language.
ai docs List, read, or search Codemod AI documentation resources from the CLI.
  • Run without a query to list available docs-backed resources.
  • Pass a resource name or URI to read it.
  • Pass a search phrase to search across available resources.
ai tools and ai tool Inspect MCP-equivalent tools exposed by the CLI.
  • ai tools lists available tool names and descriptions.
  • ai tool <name> prints metadata and the JSON input schema for a single tool.
ai call Call an MCP-equivalent tool directly from the CLI with JSON input.
  • Omit --input to pass an empty object ({}).
  • Use --input @request.json to load input from a file.
  • Use --input - to read JSON input from stdin.
ai resources and ai resource Inspect and read MCP-equivalent resources exposed by the CLI.
  • ai resources lists the available resource names and URIs.
  • ai resource reads one resource by URI or resource name.

Package skill install (prompted from package 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.
Install a package skill from registry metadata into harness skill paths. The installer copies the authored skill directory recursively from the package (agents/skill/<skill-name>/), including any additional files you add (for example extra .md references). This flow also updates managed Codemod discovery hints in harness discovery guides (CLAUDE.md for Claude, AGENTS.md and .goosehints for Goose, AGENTS.md for Cursor/OpenCode/Codex) without duplication, then prompts you to restart/reload the harness session.
In interactive TTY sessions, npx codemod@next <package-id> prompts for harness/scope/overwrite when installable skill behavior is available.
Behavior-aware package runtime:
  • Workflow-only package: npx codemod@next <package-id> runs the workflow behavior.
  • Skill-only package: npx codemod@next <package-id> does not run a no-op workflow. It returns install guidance and, in interactive terminals, can prompt to install the skill.
  • Workflow + skill package: npx codemod@next <package-id> runs workflow behavior and can optionally prompt to install skill behavior after run completion.
  • Multi-workflow package: when the package’s codemod.yaml declares multiple workflows under workflows:, the default workflow runs unless you pass --workflow <name>. In an interactive terminal with no flag, the CLI shows a picker.
AI-native error codes Example machine-readable failure (--format json):

codemod workflow

Manage and execute Codemod packages. A Codemod package is a directory containing workflow.ts (or a legacy workflow.yaml) and transformation scripts. Workflows run durable steps using different engines (jssg, YAML ast-grep, shell commands, AI agents, etc.); every step is recorded so a run can be resumed. When to use:
  • ✅ Production codemods with multiple steps
  • ✅ Parameterized transformations
  • ✅ Multi-repo orchestration
  • ✅ Resuming long migrations
Learn more: Workflow Reference workflow run Run a complete Codemod package.
  • Use npx codemod@next workflow run -w <path> for local Codemod packages and directories
  • Use npx codemod@next <package-name> to run packages directly from the Codemod Registry
A registry run (npx codemod@next <package-name>, or npx codemod@next run <package-name>) takes the same run flags as workflow run: --target, --param, --dry-run, --approve, --managed-git, --allow-dirty, --allow-ai, --no-interactive, --install-skill, --agent, --model and --format. It picks one of the package’s workflows with --workflow <NAME> instead of --workflow-name. Package runs use the 2.0 engine by default. codemod run --v1 <package> (or CODEMOD_V1=on) is a deprecated opt-in fallback to codemod 1.18.7 for eligible 1.x YAML packages.
string
required
Path to a workflow file or a package directory. In a directory, the workflow declared in codemod.yaml runs, otherwise workflow.ts, otherwise workflow.yaml.
boolean
Run every step without changing files. Later steps see what earlier steps would have changed, and the run ends by printing the diff of all of it (run_diff events with --format jsonl). Shell commands, HTTP requests (unless the step sets dryRun: "perform"), agents and skill installs are skipped, and the run is not saved.
boolean
Let the run change a target that has uncommitted changes, or that is not in a git repository. Without it, the run checks just before it first changes the target: before a step writes, renames or deletes a file, and before a shell or agent step, a workflow.yaml install-skill step, or a git step with --managed-git. An interactive run asks; an unattended one fails that step and writes nothing. A run that only reads (a check or a report) is never stopped by uncommitted changes. Dry runs are not checked. workflow resume checks only a run that stopped before it first wrote (the changes a run made itself don’t count); workflow resume --allow-dirty skips that.
boolean
Give every approval the workflow asks for: approval(...) steps and manual nodes in workflow.yaml, and the steps that run or send something (shell commands, coding agents, HTTP requests, pull requests). Give only some kinds with --approve=shell,http (written with =; the kinds are shell, agent, http, pull-request and approval).Without it, a run nobody can answer for pauses at the first approval(...) and can be continued with workflow resume --approve. What its steps run and send depends on whose workflow it is: your own (workflow run -w <file>, codemod run ./local-dir) goes ahead; a registry package’s shell, agent, HTTP and pull request steps fail without running, as do those of a registry package your workflow nests. Read what a package runs before you approve it: its commands get the job’s permissions and environment.
boolean
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.
Let ask() from codemod/ai send files to the decision model, wherever each call is sent (System One unless configured otherwise). Without it, the first ask() call that runs asks you, naming the provider, host and model it would send files to, and asks again for each other destination a call resolves to. The launcher asks on its run screen. An unattended run fails at that call instead, before anything is sent, naming the destination and this flag. A workflow whose ask() never runs (a parameter turns it off) needs neither the flag nor a key. The provider’s key comes from the environment (TYPESAFE_API_KEY, OPENAI_API_KEY); an interactive run without one asks for a key to use for that run only. workflow resume asks again.
string
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.
The coding agent agent(...) steps use (claude-code, codex, …). Defaults to the one saved in the launcher; without either, an interactive run asks when a step needs one.
string
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.
The decision model ask() uses, e.g. openai/gpt-6-luna; a bare model name is System One’s (systemone/jev-latest). It comes before the model saved in the launcher ("decisionModel" in the CLI’s config.json) and the DECISION_PROVIDER / DECISION_MODEL variables; a decision_model in the package’s codemod.yaml, or a model named in the ask() call, still comes first.
The launcher (opt-in)
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.
By default a run in a terminal prints plain lines and asks with plain prompts. With CODEMOD_LAUNCHER=1, workflow run, codemod <package> and workflow resume open a full-screen terminal UI instead. A new run starts on a setup screen (target, dry run, params, coding agent, decision model; your agent and model are saved for next time); then the screen shows the run’s steps, logs and diffs, with approvals answered in place (y approves, n rejects, which ends the run, and l stops it there to resume later). After a dry run, a runs it for real. Even with CODEMOD_LAUNCHER=1 it does not open with --no-interactive, --format jsonl, in CI, or when input or output is piped; those runs print the plain output. A run is unattended when you pass --no-interactive, when there is no terminal to ask on (input piped in), and when the CI environment variable is set (to anything but empty, 0 or false). When the CLI does ask, pressing Enter answers no: every question is about running or publishing something. See Running in CI and from agents.
boolean
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.
Let branch, commit and pullRequest steps (or branch_name, commit and pull_request in workflow.yaml) change the repository. Without it, those steps are recorded as skipped.
string
jsonl prints one JSON object per engine event (run_started, step_started, step_progress, step_log, step_retrying, step_finished, run_finished, …) on stdout. run_finished has the run’s status, its error, failed_files (how many files failed in all), and partial_steps: each step some files failed in, with its position, label, failed_files and files (how many it ran on).If a forEachFile callback or a legacy js-ast-grep transform module cannot load, the step fails and its selected files count as failed. Syntax errors in target files are different: JSSG runs on the recovered syntax tree and logs a count in text output and in a JSONL step_log event without failing those files.It also has output, what the workflow returned (or gave fail()), dry runs included, and steps: every recorded step with its position, label, status and result. An output over 1 MiB as JSON is null, with output_omitted: { bytes, limit }; step results share another 1 MiB, and one that does not fit is null with result_omitted. A saved run has all of it in workflow status --id <ID> --format json.
Every event has seq, which counts up through the whole run, also across workflow resume, and ts. Step events carry step, the step’s key (its position, or "3/0" for step 0 of the codemod that step 3 runs), and parent ("3" there, else null); step_started and step_finished also carry the step’s kind (forEachFile, approval, shell, …). run_started echoes the run’s target, params, dry_run and settings. run_log (the workflow body’s console output) has the step of the nested codemod it came from, or null. A real run reports each file a step changes as a step_diff event (path, diff, additions, deletions; a diff over 256 KiB is left out, with diff_omitted); a dry run reports run_diff at the end instead. The TypeScript types are in codemod/protocol; see Drive codemod from a program.In text format, a run that returned something ends with Output: <JSON>, cut at 200 characters.Experimental API notices go to stderr in text mode and appear as experimental events with an api field in JSONL mode. They are not part of output.
string
Let another program drive the run: it reads the events on stdout and writes commands on stdin (approve, reject, answer, stop), one JSON object per line. The first line is a hello with the run’s id. At an approval or an agent question the run waits for an answer instead of exiting, and a dry run waits too. Closing stdin pauses the run. Needs --format jsonl. See Drive codemod from a program.
string
Target directory to run the workflow on.
string
Pass key=value pairs to your workflow. Parameters reach the workflow as params (and the jssg transforms of a workflow.yaml as options.params). See Parameters.A value that parses as JSON arrives as that value (strict=true is true, level=4 is 4), and anything else as text. A parameter your workflow’s Params type declares as string (or as string literals) always arrives as text: version=4 is "4".
boolean
Experimental. In non-interactive runs, execute a workflow.yaml’s install-skill steps instead of skipping them.
string
When the package directory’s codemod.yaml declares multiple workflows under workflows:, pick which variant to run.Without this flag, the entry marked default: true runs (or the first entry if none is flagged). When stdin/stdout are interactive and no flag is given, the CLI shows a picker.
Errors out if the name doesn’t match any declared workflow, or if the source path is a workflow file (rather than a package directory) — in that case the file IS the workflow.
string
Write provider-reported nested LLM usage for the current package run to a JSON file.This output is only populated for LLM requests made by nested codemods during npx codemod@next <package-name> or other package-run flows. The file contains aggregated request counts by provider, model, outcome, and token-usage bucket, and it does not include prompts, API keys, or other request payload data.
The CLI creates parent directories as needed and overwrites the file with the current run’s data.

Exit codes

workflow run, workflow resume and codemod <package> exit with: See Exit codes for how to read them in a script.

workflow resume

Continue a run that failed, was paused (Ctrl-C) or interrupted, or is waiting for approval. A run that was canceled or rejected is over: resuming it takes --force. Steps that already finished are not run again: their recorded results are reused, in the order the steps finished the first time. If you changed the workflow, steps you left alone keep their results wherever they now are in the file; a step you added or changed runs, also when it had finished before. The run continues with what it was started with: --managed-git and --agent carry over (a new --agent or --model wins), and flags you pass add to them. A run that another process is still executing cannot be resumed; wait for it or cancel it. One run at a time changes a repository: while a run executes (started or resumed), another run on the same repository (or the same directory, outside a git repository) fails at once, naming the running run and how to workflow attach to it or workflow cancel it. A run whose process was killed holds nothing: its lock goes with the process. A run started with runWorkflow in Node.js is resumed there, not here. Each run records the codemod version that ran it (codemodVersion in workflow status --format json). Function and forEachFile steps are matched by a hash of the code the CLI builds from them, which another version may build differently. When you resume a run another version made and some finished steps no longer match, workflow resume refuses and names the version and the steps: resume it with that version (npx codemod@<version> workflow resume --id <ID>), or pass --force to run those steps again.
If the process stopped before saving the outcome of a shell, agent, git, pull request, HTTP, or nested codemod step, the step shows as started. Check what it already did before you resume. In a terminal, choose Rerun or Skip; in CI or with --no-interactive, the CLI exits 3 and prints the step’s ID and the two flags. --approve and --force do not make this decision for you.
  • --rerun-step <STEP_ID> runs the step again. It can repeat changes or send the same request twice.
  • --skip-step <STEP_ID> does not run the step again or undo what it did. The step returns null, so the workflow must be able to continue without its result.
Use the step’s numeric position from workflow status. Repeat the flags to make a choice for each interrupted step.
string
required
Run ID, from workflow list or the end of a failed run’s output.
string
Without an id: give the approval the run is waiting for, and any later ones. --trigger-all is accepted as an alias.With an id, give only that approval; the run stops again at the next one. Each approval has an id that stays the same across resumes, approval:<step> for an approval(...) step (shell:<step>, pull-request:<step> for the others). A run that waits shows it: in its last lines, as question in workflow status, and in run_finished with --format jsonl. Repeat --approve to give several.
string
Give a secret parameter again: a run doesn’t store parameters marked secret, so a resume needs them. Other parameters keep the values the run started with. Repeat for more.
boolean
Continue a run that was canceled or rejected. Steps that finished keep their results; the step that was rejected asks again. Also continues a run another codemod version made whose finished function steps no longer match: those run again.
boolean
For a run that stopped before it first wrote (for example at the check for uncommitted changes): write even if the target has uncommitted changes. A run that already wrote is not checked again.
boolean
Experimental. In non-interactive resumes, execute pending install-skill steps.
The run remembers its workflow file, target and parameters, so -w and -t are not needed. workflow validate Validate a workflow file.
workflow validate is capability-aware for codemod packages:
  • Workflow-only package: validates workflow behavior.
  • Skill-only package: validates workflow install-skill behavior plus authored skill layout (agents/skill/<skill-name>/...).
  • Workflow + skill package: validates both executable workflow and authored skill behavior.
string
required
Path to workflow file or codemod package directory.
For workflow.ts, validation builds the workflow: it parses it and checks the forEachFile callback rules, reporting errors with file, line and column. For workflow.yaml: It also lists features the translation drops (for example state.schema), refuses features 2.0 does not support yet (runtime: docker), and suggests workflow upgrade.
Why validate?Validation catches issues before execution, saving time and preventing runtime errors.
workflow validate checks that your workflow is well formed, but it cannot verify:
  • Logical correctness: Whether your workflow does what you intend
  • Runtime behavior: How your workflow behaves with real data
  • Dependencies: Whether external files/scripts exist
  • State consistency: Whether state updates are logically sound
workflow upgrade Convert workflow.yaml files to workflow.ts.
In a package directory (the current directory by default), every YAML workflow declared in codemod.yaml (or a bare workflow.yaml) is converted to a .ts file next to it, codemod.yaml is updated to point at it, and the YAML file is removed. Features the conversion drops are listed as warnings and marked in the generated file with // codemod upgrade: comments. Run it in a directory that holds several packages, such as a monorepo of recipes, and every package below it is upgraded. Directories that start with ., node_modules, target and dist are skipped. Every package is checked before anything is written: if one can’t be upgraded, the command lists each problem, writes nothing and exits with code 2. Workflow files that are symbolic links are refused, and so are two workflows whose .ts files would differ only in letter case. Each transform the new workflow.ts imports is loaded once before anything is written; a package whose transform would not load stays on YAML, with the transform and the import named. The generated file starts with // Generated from workflow.yaml by `codemod workflow upgrade`.: while it does, its transforms keep 1.x fs reads.
Transform files and their tests are not changed: codemod jssg test keeps working on them as before. To run fixtures through the whole workflow, add a test file. The generated workflow.ts references the codemod/workflow types, so tsc checks it in any project that depends on codemod. If the nearest package.json does not, upgrade suggests adding it.
boolean
Keep the YAML files.
boolean
Show the changes as a diff, without writing them.
string
text (default) or jsonl: the run’s events, one JSON object per line, ending with run_finished, whose output.upgraded lists each package and file converted.
boolean
Deprecated, and do nothing: workflow callbacks no longer get capabilities. They are accepted with a warning. Declare network requests as http() steps and commands as shell() steps; callbacks read the target without a flag. See Callbacks are pure.
boolean
Leave manual approvals unanswered. A run that reaches one waits, and its fixture fails.
workflow status Show a run and each of its recorded steps. A run is running, awaiting-approval, paused (stopped with Ctrl-C or stop), succeeded, failed, canceled or rejected. workflow resume continues the first ones and a failed run; canceled and rejected are over (--force continues them anyway). A run shown as interrupted was still running when its process was killed: resume or cancel it. A step is started, skipped, succeeded, partial, failed, canceled, awaiting-approval, rejected or waiting. A started step needs a rerun or skip decision before resume; canceled and awaiting-approval steps run again when the run is resumed.
string
required
Workflow run ID.
string
json prints the run as one JSON object: id, name, workflow, target, params, status, startedAt, endedAt, durationMs, awaiting and question (what the approval it waits for asks, and its id), error, output (what the workflow returned or gave fail()), exitCode (from fail(), else null), codemodVersion (the version that last ran it, or null if the run didn’t record one), failedFiles, and steps, each with position, label, kind, status, error, result, finishedAt, durationMs, attempts (how many times it ran, 1 unless it was retried) and files ({ failed, total } for a step that works on files: forEachFile, astGrep, a nested codemod; null for other steps).
workflow list List workflow runs. A run this version cannot read (a newer codemod wrote it) is listed as unreadable (made by codemod <version>); use that version to see or resume it.
number
Number of workflow runs to show. (default: 10)
string
json prints an array of runs, most recent first, each as workflow status --format json shows it without steps. An unreadable run has only id, status ("unreadable"), startedAt, codemodVersion and error.
workflow cancel Cancel a workflow run. A run in progress, in this or another terminal, stops the step it is on (a shell command and what it started are terminated) and writes nothing more. Any other unfinished run (failed, paused, waiting for approval, or interrupted) is marked canceled. A canceled run is over: workflow resume refuses it unless you pass --force. To stop a run you mean to continue, press Ctrl-C instead: the run is paused.
string
required
Workflow run ID.
workflow attach
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.
Print a run’s events as --format jsonl does: a hello line, every event the run has had so far, then, while the run is executing (in another terminal or process), its events as they come. It ends when the run stops executing. Every run keeps its events in the run store (dry runs excepted), so this works for runs started in any format, finished ones included. It only watches: answering a run’s questions takes its control channel, or workflow resume.
string
required
Workflow run ID.
number
Leave out the events numbered below SEQ: the ones you already have.
workflow inspect
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.
Describe a workflow without running it: what a setup form needs.
json prints workflow, language, params (each declared param’s name, type as written, optional, description from its doc comment, and default from an @default tag), modules (what it imports), capabilities (always empty: callbacks get none), requestedCapabilities (what its codemod.yaml asks for, which is ignored), uses (whether it has http, approval, agent, shell, git, codemod, install_skill (a workflow.yaml’s install-skill steps), wait calls, and ask: whether it may call ask from codemod/ai, the check --allow-ai is for; assess is the same value, kept for programs that read it) and steps: each step(...) call in the source, with its label when it is a string and its kind. A step in a loop is listed once. If inspect can’t tell which task the step will run from its source, its kind is "dynamic"; inspect does not evaluate the workflow to find out. workflow send
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.
Send an event to a workflow run. A waitForEvent step waiting for it continues with the event’s data. If no step waits for it yet, or the run is not running, the event is kept until a step takes it, and send says so. A run that has succeeded, or was canceled or rejected, takes no more events. Events do not give approvals: send to a run that waits for an approval (and has no step waiting for that event) fails, and names the workflow resume --approve <QUESTION_ID> that gives it.
string
required
The event’s name, as the workflow’s waitForEvent(name) has it: letters, digits, ., _ or -.
string
required
Workflow run ID.
string
What the waiting step resolves to, as JSON. (default: null)

codemod jssg

Run jssg (JS ast-grep) transforms directly without a workflow. jssg is the primary transformation engine for Codemod. These commands let you test jssg transforms quickly during development. When to use:
  • ✅ Quick testing of a single transform
  • ✅ Iterating on pattern matching
  • ✅ Development and debugging
When NOT to use:
  • ❌ Multi-step transformations → use codemod workflow
  • ❌ Production deployments → use codemod workflow for orchestration
Single transforms can receive parameters through repeated --param KEY=VALUE options.
For production, run the change from a workflow as a forEachFile callback, inline or imported from its file. See Workflow Reference: Imported callbacks.
Learn more: jssg documentation
1

Write your codemod

Create a JS/TS file that exports your codemod logic.
2

Run your codemod

3

Test your codemod

Organize your tests as follows:
tests
simple-transform
input.js
expected.js
multi-file-case
input
file1.js
file2.js
expected
file1.js
file2.js
Use the input/ + expected/ layout when the codemod creates or deletes files. The runner compares the whole directory snapshot but still reports results per file.Then run:
jssg run Run a JS ast-grep (jssg) codemod.
string
required
Path to the JS ast-grep (jssg) codemod file (JS/TS).
string
Target path to apply the codemod to (default: current directory).
string
required
Target language (e.g., javascript, typescript, python, java, cpp, php, kotlin, json, yaml, xml, toml, etc.).
string
Pass a transform parameter. Repeat for multiple parameters. For file selection with include/exclude globs, use forEachFile in a workflow, whose files option takes them.
number
Maximum number of concurrent threads to use.
boolean
Preview transform changes. This does not undo network requests or subprocess side effects when those capabilities are explicitly granted; see Security & Capabilities.
jssg test Test a JS ast-grep(jssg) codemod using before/after fixtures. Supports both single-file input.*/expected.* cases and directory snapshot fixtures using input/ + expected/.
string
required
Path to the JS ast-grep (jssg) codemod file, which is a JS/TS file.
string
required
Target language (e.g., javascript, typescript, python, java, cpp, php, kotlin, json, yaml, xml, toml, etc.).
string
Optional positional parent directory containing your test case subdirectories (default: "tests"). For example: npx codemod@next jssg test ./transform.ts ./tests --language tsx. Do not pass a specific test case subdirectory — use --filter instead.
boolean
The file is a forEachFile callback (its default export is (file) => ...), not a transform. It runs on each input as a forEachFile step runs it; what it returns is snapshotted in data.json. See Test a forEachFile callback.
string
A pattern to run only tests whose names match the filter. Single-file fixtures use the test case directory name. Directory snapshot fixtures are still reported per file, using names like <fixture>_<relative-path>.
string
The output format for test results. Can be console, json, or terse.
boolean
Show detailed output, including diffs for failed tests.
number
The number of context lines to show in diffs (default: 3).
boolean
Ignore whitespace differences when comparing test outputs (only applies to strict mode).
string
Comparison strictness level (default: strict):
  • strict - Exact string equality
  • cst - Compare Concrete Syntax Trees (includes all tokens, preserves ordering)
  • ast - Compare Abstract Syntax Trees (ignores formatting, preserves ordering)
  • loose - Loose AST comparison (ignores formatting and ordering of unordered nodes like object properties, imports)
Supported languages: JavaScript, TypeScript, Python, Go, Rust, JSON.
number
Test timeout in seconds (default: 30).
number
Maximum number of concurrent threads to use for running tests.
boolean
Run tests sequentially instead of in parallel.
boolean
Stop the test run on the first failure.
boolean
Create or update the expected files with the output of the codemod. For directory snapshot fixtures, this also creates missing expected files and removes stale ones. (-u is a shorthand for --update-snapshots)
string
A comma-separated list of test patterns that are expected to fail.
boolean
Enable watch mode to automatically re-run tests when files change.
  • When you need to chain multiple codemods or scripts.
  • When you want manual review, approval steps, or CI/CD integration.
  • When you want to use engines other than ast-grep (e.g., jscodeshift, YAML, or custom scripts).
ast-grep is extremely fast and robust for syntax-aware code transformations. We made it first-class in the CLI for the most common use case, but you can still use any engine via workflows.jssg replicates the ast-grep NAPI, but with a few key differences:
  • It’s built into the CLI, so you can run it directly without needing to install it separately.
  • It’s built for speed and simplicity, making ast-grep codemods a first-class experience.

codemod init

Initialize a new Codemod package project.
In interactive mode, codemod init prompts you to choose between a jssg codemod, multi-step workflow, or agent skill codemod. Without a terminal to ask on, or in CI, it behaves as --no-interactive: the values come from flags. An ast-grep-js or hybrid package keeps its workflow in src/workflow.ts, with its transform there as a forEachFile callback that parses each file with parse(file, { language }) and rewrites it. A hybrid package also has shell scripts in src/scripts/, which the workflow runs as shell`${import.meta.dirname}/scripts/setup.sh` , and ast-grep rules in src/rules/. Its tests are in tests/workflow.test.ts, which runs the workflow on each fixture in tests/fixtures with node:test; the test script runs them. You’ll also be prompted to create a GitHub Actions publishing workflow. This generates .github/workflows/publish.yml:
  • Single codemod repo: Triggers on v* tags (e.g., v1.0.0)
  • Monorepo: Triggers on *@v* tags (e.g., my-codemod@v1.0.0) and extracts the codemod name
Both workflows use trusted publishers with OIDC for secure, passwordless publishing. See the publishing guide for detailed workflow examples.
string
Project directory name.
string
Project name (defaults to directory name).Required in --no-interactive mode when the project name cannot be derived from [PATH] (for example, when [PATH] is ., .., or another path without a final directory component).
string
Workflow project type: ast-grep-js or hybrid. Mutually exclusive with --skill.Required in --no-interactive mode for workflow packages.
  • shell: Shell script-based codemods
  • ast-grep-yaml: YAML-based ast-grep codemods
boolean
Experimental. Scaffold a skill-only package with a workflow-first template (workflow.yaml with an install-skill step) and authored files under agents/skill/<skill-name>/.The generated SKILL.md uses the authored package skill markers:
  • codemod-compatibility: skill-package-v1
  • codemod-skill-version: 0.1.0
Mutually exclusive with --project-type.
string
Package manager.Required in --no-interactive mode for ast-grep-js, hybrid, and --workspace.
string
Target language.Required in --no-interactive mode.
string
Project description.Required in --no-interactive mode.
string
Author name and email.Required in --no-interactive mode.
string
License.Required in --no-interactive mode.
string
Git repository URL stored as repository in codemod.yaml.
boolean
Make package private.
boolean
Overwrite existing files.
boolean
Use defaults without prompts. In this mode, pass the values that would normally come from prompts.

codemod login

Login to a registry.
string
Authenticate using an API key. Skips the browser login & is ideal for CI.
In CI or without an interactive terminal, login uses existing valid credentials or requires --api-key. If neither is available, it exits 1 without opening a browser.
string
Registry URL.
string
Organization or user scope for publishing.
string
Print one JSON object with registry, logged_in, and user to stdout. If you need an API key to proceed, logged_in is false and user is null. Credentials are not printed.
Need a key? Generate one in the Codemod app here ->.

codemod logout

Logout from a registry.
string
Registry URL to logout from.
boolean
Logout from all registries.

codemod whoami

Show current authentication status.
string
Registry URL to check.
boolean
Show detailed information including token scopes.
string
Print registry, logged_in, and user. When signed out, logged_in is false, user is null, and the exit code is 1. With --detailed, a signed-in result also includes token metadata, never access or refresh token values.

codemod publish

Publish a Codemod package to a registry.
What .gitignore files in the package ignore is not published, nested ones included, and neither are node_modules and .git directories at any depth. A workflow.ts, and each callback and shard function it imports from its own file, is bundled with what it imports from npm packages; the modules the CLI provides (codemod/workflow, codemod/ast-grep, fs, …) stay imports, and so do the workflow’s imports of its callbacks, which the modules the build extracts import. YAML files it imports (ast-grep rules) are published as they are, and stay imports. A workflow that names a file by path where a callback or rules go does not build, so it does not publish: see Imported callbacks.
string
Path to codemod directory (defaults to current directory).
string
Print one JSON object with success, registry, tag, and package after a successful upload. On failure, read stderr and check the nonzero exit code.
Package metadata (name, version, access level, etc.) is read from codemod.yaml. See Package Structure for configuration options.

Publishing Guide

Learn about all publishing methods including API keys, trusted publishers (OIDC), and CI/CD setup.

codemod unpublish

Remove a package or selected version from the registry.
string
required
Package name (e.g., @org/my-codemod or my-codemod).
string
Specific semver to unpublish. Requires confirmation.
boolean
Unpublish all versions (irreversible). Confirmation required.
string
Target registry URL.
boolean
Show what would be removed without actually unpublishing.
boolean
Unpublish without asking for confirmation. Without a terminal to ask on (in CI, or with input piped in), unpublish refuses to run unless you pass it.
In a terminal, the CLI asks for confirmation when --version or --force is used, unless you pass --yes.
Search for packages in the registry.
string
Search query
string
Filter by programming language
string
Filter by framework
string
Filter by category
number
Number of results to return (default: 20)
number
Pagination offset (default: 0)
string
Filter by organization scope
string
Registry URL
string
Output format (default: table). Possible values: table, json, yaml
Search for codemods related to React:
Filter by language and category:
Get results in JSON format:

codemod cache

Manage the local package cache for Codemod packages. cache info Show cache information and statistics.
cache list List cached packages.
boolean
Show package details.
cache clear Clear cache for a specific package, or all packages.
string
Package name (e.g., @org/package or package).
boolean
Clear all cached packages.
cache prune Prune old or unused cache entries.
number
Maximum age in days to keep (default: 30).
boolean
Dry run - show what would be removed.