Introducing the new Codemod CLI

·2 min read

We’re excited to announce the launch of the new Codemod CLI; your all-in-one toolkit for automating large-scale code transformations, refactors, and migrations. Whether you’re wrangling a monorepo, modernizing legacy code, or rolling out sweeping changes across dozens of projects, Codemod CLI brings power, safety, and flexibility to your workflow.

NoteThis release ships under the temporary @next tag while it’s in alpha. The core commands and workflow schema may change as we gather feedback. If you try it out, keep an eye on the CLI reference until we publish a stable @latest.

What’s new?

  • First-class workflow authoring: Compose, validate, and run workflows with a single tool.
  • Self-hostable & portable: No server required. Run anywhere you have a shell.
  • Schema-validated shared state: Safely coordinate complex, multi-step migrations.
  • Parallel & resumable: Run tasks in parallel, pause for manual approval, and resume after interruptions.

Quick Start: Your First Codemod Workflow

#1 Create a New Workflow Project

Codemod CLI supports three workflow types:

  • Shell command workflow codemod: Automate any shell command or script.
  • JavaScript ast-grep codemod: Use jssg (JavaScript ast-grep) for fast, pattern-based code transformations.
  • YAML ast-grep codemod: Use YAML-based rules for language-agnostic AST transformations.

To create a new project, run:

npx codemod@next init

You’ll be prompted to choose your workflow type, project name, and other details. This sets up a ready-to-go project structure, including:

my-codemod/
├── codemod.yaml # Project metadata
├── workflow.yaml # Workflow definition
├── rules/ # ast-grep rules
├── jssg/ # jssg codemods
├── scripts/ # Custom scripts (for shell scripts)
└── tests/ # Test fixtures

#2 Build Your Transform with Codemod Studio

For ast-grep YAML and jssg codemods, Codemod Studio is your visual playground for building, testing, and refining code transformations.

  1. Open Codemod Studio in your browser.
  2. Select your language and codemod type (ast-grep YAML or jssg).
  3. Write and test your transformation rules interactively.
  4. Once satisfied, copy your rule.
  5. Paste your rule into rules/config.yml (for YAML) or jssg/codemod.ts (for jssg).

#3 Run Your Workflow with Codemod CLI

With your workflow and rules in place, you’re ready to validate and execute your codemod:

# Validate your workflow for errors
npx codemod@next workflow validate -w ./example-codemod/workflow.yaml # Replace with actual path
# Run the workflow locally
npx codemod@next workflow run -w ./example-codemod/workflow.yaml # Replace with actual path

Next steps

Find migration opportunities

Get started with Codemod Migration Analyzer now.

Get started