Quick Start
1
Initialize a new codemod project
2
Run and test your codemod
3
Publish your codemod
4
Run the published codemod
Command Relationships
The Codemod CLI provides different commands for different stages of development:High-Level Commands (Production)
Quick Testing Commands (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.CLI Command Reference
Codemod CLI is accessible using thenpx codemod command. The following commands and options are available:
codemod workflow
Manage and execute Codemod packages.
A Codemod package is a directory containing workflow.yaml and transformation scripts. Workflows orchestrate multiple steps using different engines (jssg, YAML ast-grep, shell commands, AI, etc.).
When to use:
- ✅ Production codemods with multiple steps
- ✅ Parameterized transformations
- ✅ Multi-repo orchestration
- ✅ State management and resumption
workflow run
Run a complete Codemod package.
- Use
npx codemod workflow run -w <path>for local Codemod packages and directories - Use
npx codemod <package-name>to run packages directly from the Codemod Registry
Pass key=value pairs to your workflow. Parameters are exposed to jssg transforms via
options.params.workflow resume
Resume a paused workflow.
workflow validate
Validate a workflow file.
Why validate?Validation catches issues before execution, saving time and preventing runtime errors.
Validation vs. Logical Correctness
Validation vs. Logical Correctness
The
workflow validate command ensures your YAML is syntactically correct and follows the schema, 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 status
Show workflow run status.
workflow list
List workflow runs.
workflow cancel
Cancel a workflow run.
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
- ❌ Multi-step transformations → use
codemod workflow - ❌ Parameterized transforms → use
codemod workflowwith--param - ❌ Production deployments → use
codemod workflowfor orchestration
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:Then run:
jssg run
Run a JS ast-grep (jssg) codemod.
Include hidden files and directories in the scan.
jssg test
Test a JS ast-grep(jssg) codemod using before/after fixtures.
Create or update the
expected files with the output of the codemod. (-u is a shorthand for --update-snapshots)When should I define a workflow instead?
When should I define a workflow instead?
- 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).
Why ast-grep?
Why ast-grep?
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.
Project type:
ast-grep-js.More package types (advanced)
More package types (advanced)
shell: Shell script-based codemodsast-grep-yaml: YAML-based ast-grep codemods
codemod login
Login to a registry.
codemod logout
Logout from a registry.
codemod whoami
Show current authentication status.
codemod publish
Publish a Codemod package to a registry.
Publishing from CI or on behalf of an organization? Install the Codemod GitHub App on the target repos.
Publishing from CI (w/ GitHub App)
Publishing from CI (w/ GitHub App)
Use this method when your organization has installed the Codemod GitHub App. The app injects
CODEMOD_TOKEN automatically—no separate login step needed.Publishing from CI (w/ API key)
Publishing from CI (w/ API key)
Use this flow when the GitHub App isn’t installed. Requires login
--api-key; works for publishing new versions of existing codemods (the first publish must be interactive).Example action using a Codemod API key:
Examples
Examples
codemod unpublish
Remove a package or selected version from the registry.
Examples
Examples
codemod search
Search for packages in the registry.
Examples
Examples
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.
cache clear
Clear cache for a specific package, or all packages.
cache prune
Prune old or unused cache entries.