- Visual parameter configuration - Edit workflow parameters through the UI instead of YAML
- Centralized state management - Coordinate migrations with persistent state across repos and teams
- Multi-repo orchestration - Run workflows across your entire codebase with progress tracking
- Business insights - Track migration progress with custom metrics and dashboards
Package Structure
Directory Layout
npx codemod workflow run -w ./my-codemod-package/.
scripts/ and rules/ folders are conventional, not required—use any paths and reference them from workflow.yaml.workflow.yaml and any scripts, rules, or assets referenced by your workflow.
Scaffolding packages
Validating workflows
Running workflows
Package Metadata (codemod.yaml)
Thecodemod.yaml file defines your Codemod package’s metadata and configuration.
Example codemod.yaml file:
Available codemod.yaml fields
Available codemod.yaml fields
/^[a-z0-9-_/]+$/ (lowercase letters, numbers, hyphens, underscores, and / for scope separation only)Not allowed: uppercase letters, dots, commas, spaces, or other special charactersValid examples:-
remove-console-logs @scope/remove-console-logs(using@organization-or-project-scope/nameprovides better discoverability in the Codemod Registry)
Jane Doe <jane@example.com>.MIT.codemod init; editable later).keywords: ["react", "v18-to-v19", "migration"]Best practices and conventions
Best practices and conventions
- Keep tags concise (1–2 words).
- Use lowercase for consistency.
- Don’t overload with tags — 2–4 per codemod is ideal.
- Prioritize transformation type + framework/library + version (if relevant).
1. Transformation Type TagsConsider these categories when describing why the codemod exists:
upgrade– helps upgrade code to newer versions (encompasses both breaking changes and feature adoption). You may also consider adding one of the following tags:breaking-change– adapts code to framework/library breaking API changes.feature-adoption– helps adoption of new optional or incremental features.
security– addresses known vulnerabilities or unsafe patterns.cross-migration– replaces one library/framework with another.i18n– internationalization migrations or improvements.a11y– accessibility improvements and compliance.standardization– unifies patterns, conventions, or APIs across a codebase.code-mining– identifies, flags, or extracts patterns without transforming. Use if codemod is for detection-only.
breaking-change and feature-adoption in the same codemod.2. Target Version TagsUse these to indicate the framework/library version the codemod prepares for.
- Format:
vXorvX-to-vY(for upgrades). - Examples:
v17-to-v18(React 17 → 18)v5-to-v6(React Router 5 → 6)v16(Angular 16 breaking changes)
3. Framework / Library / SDK TagsAlways add the ecosystem name to improve discoverability.
- Examples:
reactnextjsnodejsangularmswi18next
4. Example Tag SetsHere are some examples to illustrate how tags combine:
- React Root API Upgrade (17 → 18)
- Tags:
upgrade,breaking-change,v17-to-v18,react
- Tags:
- Adopt React Hooks
- Tags:
upgrade,feature-adoption,react
- Tags:
- Migrate from Moment.js to Day.js
- Tags:
cross-migration,momentjs,dayjs
- Tags:
- Remove Hardcoded Strings for i18n
- Tags:
i18n,i18next
- Tags:
- Add ARIA labels for accessibility
- Tags:
a11y,react
- Tags:
- Detect Insecure crypto API usage
- Tags:
security,nodejs,crypto
- Tags:
- public: Anyone can run the codemod.
- private: Only the owner can run the codemod.
- pro: Only Pro plan users can run the codemod.
- public: Everyone can see the package in the Registry.
- private: Only the owner can see the package.
- org: Members of the package’s organization scope can see the package.
- user: Visible only to the publishing user (user-scoped visibility).
public/private based on —private. You can change to any supported value above when publishing.Workflow File (workflow.yaml)
Theworkflow.yaml file defines your Codemod package’s workflow. A workflow is a collection of nodes that are executed in order. A workflow has four top-level keys:
Nodes & Steps
Nodes
Nodes are execution units in your workflow. They can be automatic or manual, depend on other nodes, and may define strategy (e.g., matrix), trigger, runtime, env, and an ordered list of steps.automatic (default) or manual.Steps
Steps are the atomic actions inside a node. They run sequentially and each step performs one transformation or action using a specific engine:js-ast-grep- Primary transformation engine: JavaScript/TypeScript codemods using ast-grepast-grep- Declarative pattern matching with YAML rulesrun- Shell commands for external tools and setupai- LLM-powered transformations and reviewscodemod- Compose other published codemods
jssg (JS ast-grep) step
Runs JavaScript/TypeScript codemods with full programmatic control over AST transformations. Use jssg for:- Complex transformations requiring logic (loops, conditions, functions)
- AST manipulations beyond find/replace
- Cross-file analysis or coordination
- Type-safe transformations with TypeScript
Create a jssg codemod:
scripts/ folder, create a new jssg codemod.Add a jssg step to your workflow:
Available parameters
Available parameters
params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||.typescript, javascript, etc.).AI step
Calls an AI agent with a prompt. This is helpful when your workflow requires leveraging LLM intelligence for more complex tasks for capabilities beyond deterministic transformations. To use a AI step:Set the environment variables:
Add an AI step to your workflow:
Available parameters
Available parameters
params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||.LLM_MODEL if set.openai, anthropic, azure_openai.YAML ast-grep step
Executes ast-grep using declarative YAML rules. Use for simple, fast pattern matching when you don’t need programmatic logic. When to use YAML ast-grep:- Simple find/replace transformations
- No conditional logic needed
- Fastest to write for basic patterns
- Need conditional logic or loops
- Complex AST manipulations
- Cross-file coordination
Create a YAML ast-grep rules file:
rules/ folder, create a new YAML ast-grep rules file.Add a YAML ast-grep step to your workflow:
Available parameters
Available parameters
params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||.Codemod Registry step
Runs another codemod by package name (or local path). Use to compose larger migrations by chaining codemods. To use a Codemod Registry step:Find or publish a codemod to the Codemod Registry:
- find and use an existing codemod in Codemod Registry, or
- publish a Codemod package to Codemod Registry.
Add a Codemod Registry step to your workflow:
Available parameters
Available parameters
params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||.codemod steps, these are forwarded to the invoked workflow as parameters with an env_ prefix (e.g., FOO → env_FOO). They are not applied to the OS environment of the nested workflow.codemod step in the same node. A Codemod package may itself orchestrate other codemods, enabling nested compositions for larger upgrades.- Steps in a node run sequentially from top to bottom.
- Use
depends_onor a matrixstrategyacross multiple nodes for gating/parallelism. - If a step fails, the node fails and subsequent steps in that node are skipped.
Shell command step
Runs shell commands on the host. Use for setup/cleanup, invoking external tools, or glue logic between transformations.Available parameters
Available parameters
params.x, state.x, and matrix value keys. Operators: ==, !=, >, <, &&, ||.run step.Shared State
State enables workflows to persist data across runs and coordinate work across repositories and teams:- Sharding: Distribute work across teams or repositories
- Progress tracking: Resume interrupted migrations without losing work
- Coordination: Maintain consistency across related codebases
Parameters
Parameters make workflows configurable and reusable across different projects and teams. Define them in your workflow with a schema:Accessing Parameters in Steps
Parameters are exposed differently depending on the step type: In jssg transforms - access viaoptions.params:
PARAM_ prefix:
env_ prefix:
- Sharding configuration: Method (
directory,codeowner) and targets - PR settings: Size limits, auto AI review, pre/post run scripts
Matrix Strategy
Dynamic Matrix Task Recompilation
Dynamic Matrix Task Recompilation
from_state changes, Codemod CLI:- Creates new tasks for new items.
- Marks tasks as
WontDoif their item is removed. - Leaves existing tasks untouched if their item remains.
Accessing Matrix Values in Steps
Matrix values are exposed differently per step type: In jssg transforms - access viaoptions.matrixValues:
Manual Trigger
Task UUIDs & Resume
Task UUIDs & Resume
-
All paused tasks:
-
A specific task:
State Updates
Container Runtimes
Container Runtimes
State Management & Persistence
State Management & Persistence
Matrix Master Task
Matrix Master Task
If all child tasks complete, the master is
Completed. If any fail, the master is Failed.Cyclic Dependency Example
Cyclic Dependency Example
npx codemod workflow validate or npx codemod workflow run on a workflow with a cyclic dependency.Task Statuses
Variable Resolution
- Parameter:
${{params.branch}}— Supplied at runtime - Environment:
${{env.CI}}— Host env var - Shared State:
${{state.counter}}— Live JSON value
Roadmap
Container runtime support
runtime: docker and other container runtimes, allowing tasks to run in isolated environments.Nested matrix strategies