Codemod CLI
Codemod CLI is released under the temporary @next
tag while it’s in alpha. The core commands and workflow schema may change as we gather feedback. Please keep an eye on the CLI reference until we publish a stable @latest
.
Codemod CLI (new) is accessible using the npx codemod@next
command. The following commands and options are available:
workflow
— Manage workflows (see subcommands below)jssg
— JavaScript ast-grep execution (see subcommands below)init
— Initialize a new workflow projectlogin
— Login to a registrylogout
— Logout from a registrywhoami
— Show current authentication statuspublish
— Publish a workflowsearch
— Search for packages in the registryrun
— Run a codemod from the registrycache
— Manage package cache (see subcommands below)
codemod@next workflow
Manage and execute workflow YAMLs.
workflow run
Run a workflow.
Path to workflow file or directory.
Workflow parameters (format: key=value).
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@next jssg
jssg is a toolkit for running JavaScript/TypeScript codemods using the high-performance ast-grep engine. It enables fast, large-scale code transformations with a familiar API and robust language support.
jssg run
Run a jssg codemod.
Path to the 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 jssg codemod using before/after fixtures.
Path to the 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.
Quick Start Example
Quick Start Example
Write your codemod
Create a JS/TS file that exports your codemod logic.
Run your codemod
Test your codemod
Organize your tests as follows:
Then run:
Testing Framework
Testing Framework
The jssg testing framework provides robust support for before/after fixture testing.
Test Discovery & Filtering
The directory containing your tests (default: "tests"
).
A pattern to run only tests whose names match the filter.
Output & Reporting
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.
Execution Control
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.
Snapshot & Error Management
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.
Development
Enable watch mode to automatically re-run tests when files change.
Advanced Usage & Best Practices
Advanced Usage & Best Practices
- Use
—dry-run
to preview changes. - Use
—max-threads
to control concurrency. - For large codebases, filter files with
—extensions
and—include-hidden
. - Use
—update-snapshots
to automatically update your expected outputs when your codemod changes. - See the Testing Framework Details accordion for more.
codemod@next init
Initialize a new workflow project.
Project directory name.
Project name (defaults to directory name).
Project type: shell
, ast-grep-js
, ast-grep-yaml
.
Target language.
Project description.
Author name and email.
License.
Make package private.
Overwrite existing files.
Use defaults without prompts.
codemod@next login
Login to a registry.
Registry URL.
Organization or user scope for publishing.
codemod@next logout
Logout from a registry.
Registry URL to logout from.
Logout from all registries.
codemod@next whoami
Show current authentication status.
Registry URL to check.
Show detailed information including token scopes.
codemod@next publish
Publish a workflow 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.
codemod@next search
Search for packages in the registry.
codemod@next 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.