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
string
required
Path to workflow file or directory.
string
Target directory to run the workflow on.
string
Pass key=value pairs to your workflow. Parameters are exposed to jssg transforms via
options.params.workflow resume
Resume a paused workflow.
string
required
Workflow run ID.
string
Task ID to trigger (can be specified multiple times).
boolean
Trigger all awaiting tasks.
workflow validate
Validate a workflow file.
string
required
Path to 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.
string
required
Workflow run ID.
workflow list
List workflow runs.
number
Number of workflow runs to show. (default: 10)
workflow cancel
Cancel a workflow run.
string
required
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.
string
required
Path to the JS ast-grep (jssg) codemod file (JS/TS).
string
required
Directory to apply the codemod to.
string
required
Target language (e.g.,
javascript, typescript, python, java, cpp, php, kotlin, etc.).string
Comma-separated list of file extensions to process.
boolean
Do not respect
.gitignore files.Include hidden files and directories in the scan.
number
Maximum number of concurrent threads to use.
boolean
Perform a dry-run to see the changes without applying them.
jssg test
Test a JS ast-grep(jssg) codemod using before/after fixtures.
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, etc.).string
The directory containing your tests (default:
"tests").string
A pattern to run only tests whose names match the filter.
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.
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. (-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 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.
string
Project directory name.
string
Project name (defaults to directory name).
string
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
string
Target language.
string
Project description.
string
Author name and email.
string
License.
boolean
Make package private.
boolean
Overwrite existing files.
boolean
Use defaults without prompts.
codemod login
Login to a registry.
string
Authenticate using an API key. Skips the browser login & is ideal for CI.
string
Registry URL.
string
Organization or user scope for publishing.
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.
codemod publish
Publish a Codemod package to a registry.
string
Path to codemod directory.
string
Explicit version override.
string
Target registry URL.
string
Tag for the release.
string
Access level (
public, private).boolean
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.
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.
Examples
Examples
codemod search
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
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.
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.