Codemod CLI hero banner

The Codemod command-line interface (CLI) allows you to interact with Codemod platform using a terminal or through an automated system.

The Codemod CLI accepts a variety of subcommands and options to explore, publish, and run codemods.

The Codemod CLI requires Node.js v16+.


npm i -g codemod

List available codemods

The command can be used to list the codemods available in the Codemod Registry and optionally search for a specific codemod using its name or tags.

codemod list [optional search query]

Running codemods

You can use the codemod command to run codemods.

This command uses the following format:

codemod [codemod name]

When using the codemod command, Codemod CLI will attempt to run a codemod as long as it is not followed by a reserved command name.

Available options

The following options can be used to change the default behavior of the Codemod CLI.

--include (-i)
glob pattern
default: "Defined by the codemod engine"

Can be used to specify the files to be targeted by the codemod.

codemod [codemod name] -i "certain_file" -i "entire_folder/" -i "*.js"
Folders should be defined with a trailing slash, for example node_modules/. Every other entry will be treated as a file. We don’t check whether the paths under a certain glob pattern are directories or not for performance reasons.
--exclude (-e)
glob pattern
default: "node_modules/, dist/, build/, .next/, .git/"

While running a codemod, you may want to prevent changes from occurring to specific parts of your project. The --exclude option can be used to specify a glob pattern of the files to be ignored by the codemod.

codemod [codemod name] -e "certain_file" -e "entire_folder/" -e "*.py"
By default, Codemod CLI would also look for your project’s root .gitignore file and exclude the patterns defined in it. The trailing slash rule mentioned in --include command description also applies to the --exclude option.
--target (-t)

Can be used to specify the directory of your project that the CLI should target while running codemods. This option is set as the current directory by default.

codemod [codemod name] -t [path]
--source (-s)

Can be used to specify the path to the codemod package folder stored locally that you want to run using the Codemod CLI.

If your local codemod follows the recommended codemod package structure, it will include a .codemodrc.json file. By default, Codemod CLI will attempt using the engine specified in .codemodrc.json. Otherwise, you will need to specify the codemod engine manually.

codemod -s [path]
--dry (-d)

Can be used to switch to dry run mode. Dry running codemods helps you see the changes the codemod will make without affecting the project files.

codemod [codemod name] --dry

Can be used to disable prettier formatting to the files affected by the codemod.

codemod [codemod name] --no-format

Can be used to disable caching downloaded codemod files.

codemod [codemod name] --no-cache
Disabling cache can ensure you are getting the freshest results. While keeping the cache enabled can help you save bandwidth and time for repetitive use of the same codemods.

Can be used to disable dependencies installation after codemod run.

codemod [codemod name] --no-install
Some codemods may install or remove dependencies after running. This option allows you to disable that behavior and handle dependency upgrades manually.

Can be used to disable CLI telemetry data collection.

codemod [codemod name] --no-telemetry
--json (-j)

Can be used to switch the CLI responses to JSON format.

codemod [codemod name] --json
--threads (-n)
default: "4"

Can be used to specify the number of worker threads the CLI uses while running codemods.

codemod [codemod name] -n [number of threads]

Generate codemod from file diff

The learn command uses the diff of the latest edited file to automatically build a codemod using Codemod Studio.

After running this command, if any git diff exists, the Codemod Engine will use the diff as before/after snippets in Codemod Studio.

codemod learn

Login to Codemod platform

The login command can be used to login to Codemod platform.

codemod login

Logout from Codemod platform

The logout command can be used to logout from Codemod platform.

codemod logout

Creating a codemod package

The init command can be used to scaffold a new codemod package.

codemod init

Building a codemod package

The build command can be used to build a JavaScript codemod package. If you are using any of the supported JavaScript codemod engines, you can use the CLI to build the main executable file.

codemod build

Publishing codemods

The publish command can be used to publish a codemod to the Codemod Registry. Publishing codemods requires logging in to Codemod platform.

codemod publish

Help commands


Can be used to show a list of all available commands and options for Codemod CLI.

codemod --help

You can also use this flag in combination with a particular CLI command to display usage information relevant to that command.

codemod login --help
--version (-v)

Can be used to show the currently active version of Codemod CLI.

codemod --version