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
Path to workflow file or directory.
Target directory to run the workflow on.
Pass key=value pairs to your workflow. Parameters are exposed to jssg transforms via
options.params.workflow resume
Resume a paused workflow.
Workflow run ID.
Task ID to trigger (can be specified multiple times).
Trigger all awaiting tasks.
workflow validate
Validate a workflow file.
Path to workflow file.
| Check | Ensures |
|---|---|
| Schema validation | YAML matches the workflow spec |
| Unique IDs | Node & template IDs are unique |
| Dependency validation | Every depends_on exists |
| Cyclic dependency detection | DAG has no cycles |
| Template references | All template: IDs exist |
| Matrix validation | from_state matches schema |
| State schema validation | state.schema is valid |
| Variable syntax | ${{…}} uses params, env, state |
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 run ID.
workflow list
List workflow runs.
Number of workflow runs to show. (default: 10)
workflow cancel
Cancel a workflow run.
Workflow run ID.
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.
Path to the JS ast-grep (jssg) codemod file (JS/TS).
Directory to apply the codemod to.
Target language (e.g.,
javascript, typescript, python, java, cpp, php, kotlin, etc.).Comma-separated list of file extensions to process.
Do not respect
.gitignore files.Include hidden files and directories in the scan.
Maximum number of concurrent threads to use.
Perform a dry-run to see the changes without applying them.
jssg test
Test a JS ast-grep(jssg) codemod using before/after fixtures.
Path to the JS ast-grep (jssg) codemod file, which is a JS/TS file.
Target language (e.g.,
javascript, typescript, python, java, cpp, php, kotlin, etc.).The directory containing your tests (default:
"tests").A pattern to run only tests whose names match the filter.
The output format for test results. Can be
console, json, or terse.Show detailed output, including diffs for failed tests.
The number of context lines to show in diffs (default: 3).
Ignore whitespace differences when comparing test outputs.
Test timeout in seconds (default: 30).
Maximum number of concurrent threads to use for running tests.
Run tests sequentially instead of in parallel.
Stop the test run on the first failure.
Create or update the
expected files with the output of the codemod. (-u is a shorthand for --update-snapshots)A comma-separated list of test patterns that are expected to fail.
Enable watch mode to automatically re-run tests when files change.
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 directory name.
Project name (defaults to directory name).
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
Target language.
Project description.
Author name and email.
License.
Make package private.
Overwrite existing files.
Use defaults without prompts.
codemod login
Login to a registry.
Authenticate using an API key. Skips the browser login & is ideal for CI.
Registry URL.
Organization or user scope for publishing.
codemod logout
Logout from a registry.
Registry URL to logout from.
Logout from all registries.
codemod whoami
Show current authentication status.
Registry URL to check.
Show detailed information including token scopes.
codemod publish
Publish a Codemod package to a registry.
Path to codemod directory.
Explicit version override.
Target registry URL.
Tag for the release.
Access level (
public, private).Validate and pack without uploading.
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.
Package name (e.g.,
@org/my-codemod or my-codemod).Specific semver to unpublish. Requires confirmation.
Unpublish all versions (irreversible). Confirmation required.
Target registry URL.
Show what would be removed without actually unpublishing.
Examples
Examples
codemod search
Search for packages in the registry.
Search query
Filter by programming language
Filter by framework
Filter by category
Number of results to return (default: 20)
Pagination offset (default: 0)
Filter by organization scope
Registry URL
Output format (default: table). Possible values: table, json, yaml
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.
Show package details.
cache clear
Clear cache for a specific package, or all packages.
Package name (e.g.,
@org/package or package).Clear all cached packages.
cache prune
Prune old or unused cache entries.
Maximum age in days to keep (default: 30).
Dry run - show what would be removed.