ast-grep vs jscodeshift
Which should you use? A side-by-side look at what each one does, who it suits, what it costs, how hard it is to set up, and where each falls short.
Open source · MIT
A command-line tool that searches, lints, and rewrites code by its syntax structure, not plain text.
Open source · MIT
A toolkit for running automated code-rewriting scripts (codemods) across many JavaScript or TypeScript files.
The short answer
Choose ast-grep if you need…
- Developers who want grep-like searching that understands code structure
- Library authors migrating users across breaking API changes
- Tech leads who want to enforce custom code practices with lint rules
- Engineers doing large-scale, consistent code rewrites
Choose jscodeshift if you need…
- Engineers migrating a large JavaScript or TypeScript codebase to a new API or syntax
- Teams that need the same mechanical refactor applied consistently across many files
- Developers who want a dry run to see how many files a change would affect before committing to it
- Maintainers writing reusable codemods to share with other projects
Side-by-side
| ast-grep | jscodeshift | |
|---|---|---|
| Type | CLI | Dev tool |
| Price | Free and open source | Free and open source |
| Licence | MIT | MIT |
| GitHub stars | 16.4k | 10k |
| Setup difficulty | Beginner | Intermediate |
| How you get it | Install with a package manager | Install with a package manager |
| Main language | Rust | JavaScript |
| Last code update | 4 days ago | 9 days ago |
What each one is
ast-grep
ast-grep is a command-line tool that searches code by matching its syntax tree rather than raw text, so a pattern written like ordinary code can find every place that shares the same structure. It can also rewrite matches and run YAML-defined lint rules. People use it to find usages, migrate code across breaking changes, or enforce team coding standards.
jscodeshift
jscodeshift lets you write a small transform script that automatically changes source code, then runs that script across many files at once. It includes a runner that applies the transform to each file and reports how many were changed, plus a wrapper around the recast library that offers a jQuery-like way to search and edit the code's syntax tree. It is aimed at large codebases where the same change needs to be made in many places.
Best for
ast-grep
- Developers who want grep-like searching that understands code structure
- Library authors migrating users across breaking API changes
- Tech leads who want to enforce custom code practices with lint rules
- Engineers doing large-scale, consistent code rewrites
jscodeshift
- Engineers migrating a large JavaScript or TypeScript codebase to a new API or syntax
- Teams that need the same mechanical refactor applied consistently across many files
- Developers who want a dry run to see how many files a change would affect before committing to it
- Maintainers writing reusable codemods to share with other projects
Strengths
ast-grep
- Patterns look like the code you already write
- Matches by syntax tree, so it ignores formatting differences
- Installable through many package managers including npm, pip, Homebrew, and cargo
jscodeshift
- Runs one transform over many files and summarizes the results (ok, unmodified, skipped, errors)
- Built on recast, which tries to preserve the original code style as much as possible
- Supports multiple parsers, including babel, flow, ts, and tsx
Not ideal for
ast-grep
- People who only need simple text search, since plain grep or ripgrep is simpler for that
- Non-programmers, because patterns assume familiarity with code syntax
- Languages not supported by its tree-sitter parsers, which the README does not fully list
jscodeshift
- People who only need to edit a handful of files by hand, since writing a transform is more work than the edit itself
- Users who want a ready-made app with a graphical interface; the README describes a command-line toolkit
- Those unfamiliar with abstract syntax trees, since the README says understanding recast and ASTs is needed to use the API well
Trade-offs
ast-grep
- Its matching depends on the language grammars it supports, so coverage varies by language
- The README is truncated and does not describe every feature or limitation in detail
jscodeshift
- Writing a transform requires understanding ASTs and the jscodeshift/recast API, which has a learning curve
- The README is truncated here, so detailed API documentation is only referenced via the external website
Getting started
ast-grep
Install via npm
npm install --global @ast-grep/cliInstall via pip
pip install ast-grep-clijscodeshift
Install globally from npm
$ npm install -g jscodeshiftFrequently asked questions
What is the difference between ast-grep and jscodeshift?
ast-grep: A command-line tool that searches, lints, and rewrites code by its syntax structure, not plain text. jscodeshift: A toolkit for running automated code-rewriting scripts (codemods) across many JavaScript or TypeScript files. ast-grep suits developers who want grep-like searching that understands code structure, while jscodeshift suits engineers migrating a large javascript or typescript codebase to a new api or syntax.
Are ast-grep and jscodeshift free?
ast-grep: Free and open source. jscodeshift: Free and open source.
Which is easier to set up, ast-grep or jscodeshift?
ast-grep is easier to get started with (rated beginner); jscodeshift is rated intermediate and usually needs more setup.
Is ast-grep or jscodeshift more popular?
ast-grep has more GitHub stars (16.4k) than jscodeshift (10k). Popularity isn't the same as fit — check which one matches your use case above.
What are other alternatives to ast-grep and jscodeshift?
Other options people compare them with include Ruff, broot.
Keep comparing
Built from our catalogue entries for both products: open-source details come from each project's README (AI-assisted, refreshed weekly) and GitHub data; AI-tool details are editorial. Spotted something wrong? Let us know from either product's page.