---
title: "jscodeshift vs ast-grep: Which to Use | Since.dev"
description: "jscodeshift vs ast-grep on the same fix: TypeScript, formatting, speed, CI checks and price, with both run on a real Node.js deprecation and timed."
canonical_url: https://since.dev/guides/jscodeshift-vs-astgrep
last_updated: 2026-11-29
---

# jscodeshift vs ast-grep: which should you use?

Use ast-grep when the change is a pattern swap: one YAML rule, many languages, and a check that fails CI if the old call comes back. Use jscodeshift when a JavaScript or TypeScript rewrite needs real logic across a file. Both are free and MIT licensed. In my run on 2,000 files, ast-grep was about 12 times faster.

Updated November 29, 2026

## Which should you use, jscodeshift or ast-grep?

Start with ast-grep, and switch to jscodeshift when the rewrite needs code to decide what to write. Here is the pick by situation:

- Pick ast-grep if the change reads as "this call becomes that call", maybe with a condition on what an argument is (a string, a number, an identifier). That's most deprecation fixes.
- Pick ast-grep if the code isn't JavaScript. Its docs list 28 built-in languages, Go, Python, Rust, Java and YAML among them. jscodeshift only reads JavaScript and TypeScript.
- Pick ast-grep if you want the rule to keep working after the migration: the same YAML file runs as a lint check that exits 1 when the old call shows up again.
- Pick jscodeshift if the rewrite has to follow the file: rename an import and every place it's used, add a require when you add a call, or choose between several rewrites based on more than one node.
- Pick jscodeshift if the migration you need already exists as a jscodeshift transform. Many libraries have shipped theirs that way for years, and you just run it.
- Pick the ast-grep JavaScript API (@ast-grep/napi) or Codemod's jssg if you want logic in JavaScript but ast-grep's speed. Both are covered below.

My recommendation: keep ast-grep in the repository for every deprecation you can describe as a pattern, and write the rule once so it fixes the code today and blocks the old call in CI afterwards. Reach for jscodeshift for the one or two migrations a year that need a real program. The trade-off: jscodeshift's API is bigger and slower to learn, and ast-grep's rules stop at what the syntax shows. Neither one knows types.

## How do jscodeshift and ast-grep compare?

They both parse code into a syntax tree and rewrite the parts that match, and they differ in how you describe the change and how far it reaches. Every cell below comes from each tool's own docs or npm page, or from my runs on this page, on Nov 29, 2026. The [ast-grep languages list](https://ast-grep.github.io/reference/languages.html) and the [jscodeshift README](https://github.com/facebook/jscodeshift) are the main sources.

jscodeshift 17.4.0 and ast-grep 0.51.3 on the same criteria, from their docs and npm, and my runs, Nov 29, 2026

| Criterion                             | jscodeshift                              | ast-grep                                                         |
| ------------------------------------- | ---------------------------------------- | ---------------------------------------------------------------- |
| Price and license                     | Free, MIT                                | Free, MIT                                                        |
| Latest version                        | 17.4.0, published July 15, 2026          | 0.51.3, published Nov 16, 2026                                   |
| npm downloads, Nov 22 to 28, 2026     | jscodeshift: 7,429,540                   | @ast-grep/cli: 2,946,948                                         |
| Languages                             | JavaScript, TypeScript, JSX, Flow        | 28 built in, including JS, TS and TSX                            |
| How you write a change                | A JavaScript transform function          | A pattern on the command line, or a YAML rule                    |
| Written in, runs on                   | JavaScript, on Node.js 16 or later       | Rust; a native binary from npm, pip, Cargo, Homebrew or MacPorts |
| Lint mode that fails CI               | No; a dry run exits 0                    | ast-grep scan exits 1 on error rules                             |
| Tests for a rule                      | Fixtures with the test utils you wire up | ast-grep test with valid and invalid cases                       |
| TypeScript by default                 | No; pass \--parser=ts or \--parser=tsx   | Yes, picked by file extension                                    |
| 2,000 files, 80,000 rewrites (my run) | 5.7 to 6.7 seconds                       | 0.4 to 0.6 seconds                                               |

## What is each one best for?

### jscodeshift

- Best for: JavaScript and TypeScript migrations that need a program, not a pattern.
- Price: free and open source under the MIT license ([npm](https://www.npmjs.com/package/jscodeshift), Nov 29, 2026).
- Pros: the full syntax tree in plain JavaScript, so a transform can look at anything in the file before it writes; a long history, so many libraries already publish jscodeshift transforms; it keeps the original style of code it doesn't touch, through recast.
- Cons: it reads TypeScript only when you pass the right parser; it exits 0 when a file fails to parse unless you add the fail flag; it has no lint mode; it was about 12 times slower than ast-grep in my run.
- Runs on: Node.js 16 or later, as an npm package. Run it with npx or install it in the project.

### ast-grep

- Best for: pattern swaps in any of its languages, and keeping the old pattern out once it's gone.
- Price: free and open source under the MIT license ([npm](https://www.npmjs.com/package/@ast-grep/cli), Nov 29, 2026).
- Pros: a pattern looks like the code it matches; constraints such as "this argument is a string" cover most conditions; the same rule file fixes, lints and tests; it was the fastest tool in my run and in Codemod's benchmark.
- Cons: its own docs say it has no type information and no control flow or data flow analysis; a rule is tied to one language, so a JavaScript rule skips .tsx files; a rewrite replaces the whole matched text, so a comment inside it can go.
- Runs on: your machine or CI, as a native binary installed from npm, pip, Cargo, Homebrew or MacPorts ([ast-grep quick start](https://ast-grep.github.io/guide/quick-start.html)). Through npm it's the @ast-grep/cli package.

## What does the same fix look like in each?

I ran both on one real deprecation: Node.js [DEP0005](https://nodejs.org/api/deprecations.html#DEP0005), the Buffer() constructor. Node 24.21.0 still runs it and prints this warning:

```
$ node -e 'new Buffer("hi")'
(node:71846) [DEP0005] DeprecationWarning:
Buffer() is deprecated due to security and
usability issues. Please use the Buffer.alloc(),
Buffer.allocUnsafe(), or Buffer.from() methods
instead.
```

Node printed the warning as one line, which I wrapped here, plus a hint line that I left out. The right fix depends on the argument: a string becomes Buffer.from, a size becomes Buffer.alloc, and a variable needs a person to look. The test file:

```
const a = new Buffer("hello");
const b = new Buffer(16);
const c = new Buffer(input);
const d = Buffer("legacy");
```

### ast-grep: two rules in one YAML file

Each rule has a pattern, a constraint on what the captured argument is, and a fix. The `kind` names come from ast-grep's syntax tree, `string` and `number` here:

```
id: buffer-from-string
language: JavaScript
severity: error
rule:
  pattern: new Buffer($S)
constraints:
  S: { kind: string }
fix: Buffer.from($S)
---
id: buffer-alloc-number
language: JavaScript
severity: error
rule:
  pattern: new Buffer($N)
constraints:
  N: { kind: number }
fix: Buffer.alloc($N)
```

```
$ npx ast-grep scan -r rule.yml \
    --report-style short src
src/buf.js:1:11: error[buffer-from-string]:
src/buf.js:2:11: error[buffer-alloc-number]:
Error: 2 error(s) found in code.
$ echo $?
1
$ npx ast-grep scan -r rule.yml -U src/buf.js
Applied 2 changes
```

I left out a help line it prints after the error count. Without `-U`, the scan prints each change as a diff and writes nothing. It rewrote lines 1 and 2, left new Buffer(input) alone, and didn't match line 4, because the pattern says `new`. Adding `Buffer($S)` as a second pattern under `any` covers it; the CI section below shows that rule.

### jscodeshift: a transform with the logic in code

```
module.exports = function (file, api) {
  const j = api.jscodeshift;
  const root = j(file.source);
  const isBuffer = { callee: { name: "Buffer" } };
  const calls = [
    ...root.find(j.NewExpression, isBuffer).paths(),
    ...root.find(j.CallExpression, isBuffer).paths(),
  ];
  for (const path of calls) {
    const [arg] = path.node.arguments;
    const kind = j.Literal.check(arg) && typeof arg.value;
    let method = null;
    if (kind === "string") method = "from";
    if (kind === "number") method = "alloc";
    if (!method) {
      const line = path.node.loc.start.line;
      api.report(`${file.path}:${line} check by hand`);
      continue;
    }
    const callee = j.memberExpression(
      j.identifier("Buffer"),
      j.identifier(method)
    );
    j(path).replaceWith(
      j.callExpression(callee, path.node.arguments)
    );
  }
  return root.toSource();
};
```

```
$ npx jscodeshift -t buffer.js src/buf.js
 REP src/buf.js src/buf.js:3 check by hand
Results:
0 errors
0 unmodified
0 skipped
1 ok
```

I left out its progress lines and the timing. It rewrote all three literal calls, the one without `new` too, and reported the variable for a person to check. One trap cost me a run. My first version checked `j.StringLiteral` and `j.NumericLiteral`, and jscodeshift matched nothing and reported all four lines. Its default parser, `babel`, gives the older `Literal` node instead. The same transform worked with `--parser=babylon`. Checking `j.Literal` and the value's type, as above, works with both.

## Which one handles TypeScript and JSX better?

ast-grep, because it picks the parser from the file extension; jscodeshift needs you to name it. I ran both on a .tsx file with a type alias, a typed variable and JSX:

```
type Props = { name: string };
export const View = ({ name }: Props) => {
  const data: Buffer = new Buffer("hi");
  return <p>{data.length}</p>;
};
```

```
$ npx jscodeshift -t buffer.js ts/view.tsx
 ERR ts/view.tsx Transformation error
   (Missing semicolon. (1:4))
1 errors
$ echo $?
0
```

I wrapped the error line and left out the stack trace. The default babel parser stops at the type alias, and the run still exits 0, so a CI job would pass with nothing changed. Add `--fail-on-error` and it exits 1. With `--parser=tsx` the same transform rewrote the call and printed 1 ok. Its default extensions already include ts and tsx; only the parser has to change.

ast-grep's `run` command read the file as TSX on its own and printed the diff. But its rules are tied to one language. My `language: JavaScript` rules ran on that file with no output and exit 0, because the [languages list](https://ast-grep.github.io/reference/languages.html) maps .tsx to Tsx and .ts to TypeScript, apart from JavaScript. In a mixed repository, copy each rule for JavaScript, TypeScript and Tsx, or the scan covers only some files and says nothing.

## Which one keeps your formatting and comments?

Neither, fully, once a comment sits inside the code being rewritten. Outside the match, both leave your code alone. I ran both on a call spread over three lines with a comment in it:

```
const buf = new Buffer(
  // the greeting
  'hello',
);
```

```
jscodeshift wrote:
const buf = Buffer.from(// the greeting
'hello');

ast-grep wrote:
const buf = Buffer.from('hello');
```

jscodeshift kept the comment and reflowed the call, because replacing a node makes recast print that node again. ast-grep dropped the comment, because the fix replaces the whole matched text and only $S was carried over. Run your formatter after either one, and grep the diff for removed comments when a migration touches multi-line calls.

## Is ast-grep faster than jscodeshift?

Yes, by about ten times or more, in my run and in Codemod's benchmark. I generated 2,000 JavaScript files of 100 lines, each with 40 deprecated Buffer calls, and ran the rules and the transform above on fresh copies, three times each, on an Apple M6 with 12 cores and Node.js 24.21.0:

- jscodeshift: 5.74, 6.61 and 6.74 seconds of wall time for 2,000 files changed.
- ast-grep scan with -U: 0.43, 0.56 and 0.56 seconds for "Applied 80000 changes".
- The output was the same in both: the two folders matched file for file afterwards.

Codemod's open [benchmark](https://github.com/codemod/benchmark) found a similar gap on 500 files: changing var to const took 41 ms and 10 MB with ast-grep and 808 ms and 157 MB with jscodeshift, the median of 3 runs on versions current in March 2026. Codemod says on that page that it sponsors ast-grep, so my run is the independent check. For a one-off migration, six seconds doesn't matter. For a pre-commit hook or a CI check on every push, it does.

## Can either one fail CI when the old call comes back?

ast-grep can; jscodeshift can't on its own. A dry run with `--dry` on a file it would change printed 1 ok and exited 0, with or without `--fail-on-error`, which only counts files that fail. ast-grep's `scan` exits 1 when a rule with `severity: error` matches, and its [test command](https://ast-grep.github.io/guide/test-rule.html) checks a rule against code it must and must not match. This rule catches both call shapes:

```
# rules/buffer-from.yml
id: buffer-from
language: JavaScript
severity: error
message: Buffer() is deprecated (DEP0005)
rule:
  any:
    - pattern: new Buffer($S)
    - pattern: Buffer($S)
constraints:
  S: { kind: string }
fix: Buffer.from($S)
```

```
# tests/buffer-from-test.yml
id: buffer-from
valid:
  - Buffer.from("ok")
  - new Buffer(input)
invalid:
  - new Buffer("hello")
  - Buffer("legacy")

```

```
# sgconfig.yml
ruleDirs: [rules]
testConfigs:
  - testDir: tests

```

```
$ npx ast-grep test --skip-snapshot-tests
Running 1 tests
PASS buffer-from  ....
test result: ok. 1 passed; 0 failed;
```

I left out its divider line. With sgconfig.yml in the repository root, a plain `npx ast-grep scan` in CI runs every rule in rules/ and fails the job while an old call is left. That's the part jscodeshift doesn't do: it fixes once, and nothing stops the old call coming back in the next pull request. To check what a dependency upgrade breaks before you write any rule, see [how to check dependencies for breaking changes](https://since.dev/guides/dependency-breaking-changes.md).

## What if you want logic in JavaScript and ast-grep's speed?

Use ast-grep's [JavaScript API](https://ast-grep.github.io/guide/api-usage/js-api.html), the @ast-grep/napi package, or Codemod's jssg, which runs JavaScript transforms on the ast-grep engine. Here is the Buffer fix with the API, with the same "check by hand" report as the jscodeshift transform:

```
import { parse, Lang } from "@ast-grep/napi";
import { readFileSync, writeFileSync } from "node:fs";

const file = process.argv[2];
const src = readFileSync(file, "utf8");
const root = parse(Lang.JavaScript, src).root();
const METHOD = { string: "from", number: "alloc" };
const edits = [];
for (const node of root.findAll("new Buffer($A)")) {
  const arg = node.getMatch("A");
  const method = METHOD[arg.kind()];
  if (!method) {
    const line = node.range().start.line + 1;
    console.log(`${file}:${line} check by hand`);
    continue;
  }
  const text = `Buffer.${method}(${arg.text()})`;
  edits.push(node.replace(text));
}
writeFileSync(file, root.commitEdits(edits));
```

```
$ node napi.mjs src/buf.js
src/buf.js:3 check by hand
```

It rewrote lines 1 and 2 and left line 4, since the pattern needs `new`. It's 20 lines against jscodeshift's 29, and you work with ast-grep patterns and node kinds instead of the ESTree API. @ast-grep/napi had 5,854,979 npm downloads from Nov 22 to 28, 2026, by [npm's download counts](https://api.npmjs.org/downloads/point/last-week/@ast-grep/napi).

Codemod calls jssg [a modern successor to jscodeshift](https://codemod.com/blog/jssg), with typed transforms, built-in tests and a workflow runner. It's part of Codemod's open-source engine in the Community plan, $0 on [Codemod's pricing page](https://codemod.com/pricing) (Nov 29, 2026). Codemod lists its paid tier, for Pro codemods and campaigns across repositories, from $1k a month. I didn't run jssg for this page, so there's no output from it here. For the wider field, Codemod's registry, OpenRewrite, go fix and Ruff, see the [best codemod tools](https://since.dev/guides/best-codemod-tools.md) guide.

## Where Since.dev fits

Since.dev doesn't run your codemods, and it isn't a replacement for either tool. It answers the question that comes before them: which deprecations and breaking releases hit your code, and where. [Scan a public repository](https://since.dev/scan.md) (free, no sign-in) and it lists the files and lines a breaking release, a deprecation, a model retirement or a runtime end of life touches, with the replacement. Your coding agent can ask the same through the [MCP server](https://since.dev/docs.md#mcp) before it upgrades a package, and package pages such as [@ast-grep/cli](https://since.dev/packages/npm/@ast-grep/cli) list what changed between versions.

For changes it can fix, it opens a fix pull request that was built and checked first, on public repositories on any plan and private ones on Pro. To compare two versions yourself, see [finding breaking changes between two versions](https://since.dev/guides/breaking-changes-between-versions.md). It reports or opens pull requests for people to review, and nothing merges or deploys.

## Questions

### Is ast-grep better than jscodeshift?

For pattern swaps, yes: it's faster, works in many languages, and the same rule can fail CI later. For JavaScript or TypeScript rewrites that need logic across a file, such as renaming an import and every use of it, jscodeshift is still the better fit. Many teams keep both.

### Does jscodeshift work with TypeScript?

Yes, if you pass the parser: `--parser=ts` for .ts files and `--parser=tsx` for .tsx. With the default babel parser, jscodeshift 17.4.0 failed on a type alias with "Missing semicolon" and still exited 0 in a test on Nov 29, 2026. Add `--fail-on-error` so a parse error fails the job.

### Is jscodeshift still maintained?

Yes. Version 17.4.0 was published on npm on July 15, 2026, and it had 7,429,540 downloads in the week of Nov 22 to 28, 2026, by npm's counts. Releases are far apart (17.3.0 came out in March 2025), and Codemod now presents its jssg runtime as a successor, but the transforms on this page ran fine on Node.js 24.21.0.

### What is the difference between ast-grep and grep?

grep matches text, so a search for Buffer also finds comments, strings and variable names. ast-grep parses the code and matches its structure, so new Buffer($S) finds only that call, with any argument, however it's spaced or split across lines. It can also rewrite what it matches.

### Can ast-grep use type information?

No. ast-grep's own comparison page says it has no type information, control flow or data flow analysis; it works on syntax only. It can tell a string literal from a number or a variable, but not what type a variable holds. jscodeshift has the same limit, so a type-dependent fix needs a person or a type-aware tool.

### What is jssg?

jssg, JavaScript ast-grep, is Codemod's codemod runtime: you write a transform in JavaScript or TypeScript, and ast-grep does the matching. Codemod presents it as a successor to jscodeshift, with built-in tests. It's in Codemod's free Community plan as part of its open-source engine.

## Related guides

### Comparisons

- [ast-grep vs Semgrep: which should you use?](https://since.dev/guides/astgrep-vs-semgrep.md)ast-grep vs Semgrep on the same deprecated call: what each finds, what each fix breaks, speed, CI exit codes, licenses and price, run and timed.
- [Best codemod tools to fix deprecated API calls](https://since.dev/guides/best-codemod-tools.md)The best codemod tools for replacing deprecated APIs, by language and job, with prices, pros and cons, and each one run on a real deprecated call.

### How-to

- [How to check your dependencies for breaking changes before you upgrade](https://since.dev/guides/dependency-breaking-changes.md)How to check dependencies for breaking changes before upgrading: the commands, a real failing upgrade, CI that fails on deprecations, and where notices appear.
- [How to find the breaking changes between two versions of a package](https://since.dev/guides/breaking-changes-between-versions.md)How to find breaking changes between two versions of a package: list the releases in between, read each changelog, diff the code. Commands for npm, PyPI, Go.
- [How to stop a coding agent from writing retired model IDs](https://since.dev/guides/stop-coding-agent-retired-model-ids.md)Coding agents write model IDs from old training data. Five guardrails, each run and tested: one models file, AGENTS.md, an MCP lookup, a hook and a CI check.

## Put your code on continuous maintenance.

Scan a public repository now, or give your agent one line.

[Scan a repository](https://since.dev/scan.md). Any public GitHub repository. No sign-in.

### Tell your agent what changed since it was trained.

`claude mcp add --transport http since https://api.since.dev/mcp`

[Get an API key](https://app.since.dev/login?mode=signup)

Codex, Cursor and any MCP client use https://api.since.dev/mcp.

---

Every page on this site as Markdown: https://since.dev/sitemap.md. For agents: https://since.dev/llms.txt.
