FormingConfigclaude-codecodexcursorpublished fresh until

ast-grep: how do I give my agent syntax-tree rewrites for big renames?

Summary As of November 2026, ast-grep 0.51.3 can preview and apply syntax-tree rewrites across a repository. The November 2 release fixes skipped-file diagnostics and rewrite-template handling. Do first: preview matches and inspect skipped files before applying a migration.

Not for splitting a big refactor PR; see agent-rewrite-pr-too-big-to-review-split-into-stacked-branches

For your agent
claude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp

Read-only, no account. Sign-in is only for trial reports: /connect.md

The option

Option
AConfig · v0.51.0+wwfix.1ast-grep CLI 0.51.0
How you use itA setting in your project
What it can doinstalls software · writes files · network · runs shell
What's inside
AConfig · v0.51.0+wwfix.1ast-grep CLI 0.51.0
How you use it
A setting in your project
What it can do
installs software · writes files · network · runs shell
What's inside

What this thread does

As of November 2026, use ast-grep 0.51.3 for repeatable syntactic rewrites, and inspect skipped files before treating a match count as complete.

Do first: preview a small rule with ast-grep run; add --inspect entity to expose skipped files. The CLI reference documents the flags, and the 0.51.1 release dated November 2 adds skipped-file reasons.

ast-grep run -l ts -p 'fetchUser($ID, $OPTS)' -r 'getUser({ id: $ID, ...$OPTS })' --inspect entity

This is an illustrative migration pattern: adapt the function and argument shape to your API. Review the diff before adding -U, which writes the changes. The rewrite guide, read November 3, documents code-shaped patterns, $ metavariables, replacements, and interactive versus automatic application. For reusable migrations, keep the rule and its fix in YAML and run ast-grep scan.

The idea

Dev Agrawal argued on 12 Aug 2026 that agents see text while codemods see structure, and that agents need a layer that knows syntax, bindings and imports: the tool provides the guarantees, the model provides the judgement.

ast-grep is the easiest such layer to hand an agent today. It parses code with tree-sitter and matches patterns written like code with placeholders:

ast-grep run -l ts -p 'fetchUser($ID, $OPTS)' -r 'getUser({ id: $ID, ...$OPTS })'

That prints a diff; add -U to apply it. For bigger migrations the agent writes YAML rules (with inside, has, not constraints) and runs ast-grep scan, so the rule file itself is reviewable and reusable in CI.

A good loop for agents

1. Ask the agent to write the pattern and run it in report mode first; check the match count and a sample. 2. Refine with constraints until the matches are exactly the intended call sites. 3. Apply with -U, run the type checker and tests, and leave the odd cases for manual edits. 4. Keep the rule in rules/ if the old API must not come back.

Alternatives

  • jscodeshift (JS/TS): full programmatic transforms; more power, more code to write.
  • OpenRewrite (Java and JVM, Apache-2.0): type-aware recipes for framework upgrades.
  • Language-server renames (tsserver, rust-analyzer, Pyright): the only option here that resolves bindings and imports. ast-grep is syntactic: it does not know that two User identifiers refer to different types, so check rewrites with the compiler.
  • ast-grep's own agent skill teaches agents to write rules, but its repo has no licence file as of October 2026, so it is not packaged here.
  • For large migrations run by many agents in parallel, see the thread on Asana's migration.

Caveats (as of November 2026)

  • Patterns must parse as valid code in the target language; very generic patterns can match too much.
  • -U writes files directly; commit first.

Primary source

Primary sources: the ast-grep site and its rewrite guide, plus the GitHub API for ast-grep/ast-grep (read 18 October 2026). Checked: ast-grep is a structural search, lint and rewrite tool that works on syntax trees, with code-like patterns using $ meta variables; ast-grep run with pattern and rewrite flags previews a diff, and --update-all or -U applies without confirmation; YAML rules with a fix key run with ast-grep scan; MIT license; version 0.51.0 was published 15 October 2026 (read on 18 October). The agent-skill repository showed no license in the GitHub API. Not verified: that ast-grep builds on tree-sitter beyond the site's tree-sitter parser mention, the rule constraints inside, has and not (not read), the Dev Agrawal post, and the jscodeshift and OpenRewrite comparisons.

Update, November 2026

0.51.1 replaces 0.51.0. Besides diagnostics, it fixes literal dollar signs followed by digits in replacement templates and utility-rule binding with --inline-rules and --rules. These fixes matter when the rewrite itself is an artifact you intend to reuse.

Evidence: eZioPan's October 6 report, #2990, describes a GBK-encoded Rust file disappearing from search results while its UTF-8 equivalent matched. HerringtonDarkholme's fix #3044, merged November 2 and included in 0.51.1, adds a reason under --inspect entity. It adds visibility; it does not add support for searching every encoding.

Limits

A structural match is not proof that every occurrence refers to the same binding. Review representative matches, then run the project's compiler and relevant tests after applying the rule. A replacement must still be appropriate for the target program. Non-UTF-8 files need separate handling.

Not for: automatically resolving symbol identity and imports like a language-server rename, or splitting an oversized refactor PR; see agent-rewrite-pr-too-big-to-review-split-into-stacked-branches.

checked 2026-11-03

Started from a post by @devagrawal09, packaged by the editor. Original post

  1. 01 · YouPaste the line from Try it into your agent.
  2. 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
  3. 03 · YouApprove a one-line report. Nothing is posted without you.

Subjects

More in agent workflows

For agents

Copy a short instruction for an agent that has WhatWorks connected, or open this page as Markdown.

# ast-grep: how do I give my agent syntax-tree rewrites for big renames?
Summary: As of November 2026, ast-grep 0.51.3 can preview and apply syntax-tree rewrites across a repository. The November 2 release fixes skipped-file diagnostics and rewrite-template handling. Do first: preview matches and inspect skipped files before applying a migration.

## Options
- A · ast-grep CLI 0.51.0 · early, no verdict yet · installs software · writes files · network · runs shell
Copy for agent
get the whatworks thread ast-grep-structural-rewrites-for-agents and help me try it

Follow this thread

Following tells you when the verdict changes, a new version ships or a new option is added. Your agent mentions it the next time you ask WhatWorks.

Sign in with GitHub to follow. Nothing is posted for you.

Sign in with GitHub

Or ask your agent
follow the whatworks thread ast-grep-structural-rewrites-for-agents

How the verdict is calculated

We count trial reports at Tested and above, weighted by evidence: Verified counts ×1.5 and Platform ×2. A report that worked partly counts as half.

Under 10 trials no verdict is shown. The option asks for founding testers instead.

Ask your agent
how does whatworks decide a verdict

A · ast-grep CLI 0.51.0

Structural search, lint and rewrite tool (MIT) built on tree-sitter. Agents write code-shaped patterns with placeholders or YAML rules, preview the matches, then apply rewrites across the repo in one pass.

Format
Config
Source
github:ast-grep/ast-grep#npm
Pinned
v0.51.0+wwfix.1 · 48b54b3120b7
Content hash
48b54b3120b70fa9
Audit
scan passed
Can do
installs software · writes files · network · runs shell
Works with
claude-code · codex · cursor
Check
ast-grep 0.51.0 installed in the project; ast-grep CLI runs without a download; A structural pattern match works (exits 1 when nothing matches); The agent instruction is in AGENTS.md or CLAUDE.md
Author
@ast-grep
Kudos
0
Are you @ast-grep? Sign in with GitHub to claim it.
Ask your agent
show me the whatworks package ast-grep-cli before installing

A · Files

Read from the package source at the pinned version. Shown as is; nothing here runs.

Loading files…

Ask your agent
show me the files of the whatworks package ast-grep-cli
WhatWorks

Connect your agent MCP

Paste this into your agent

Connect me to WhatWorks: add https://whatworks.dev/mcp for anonymous reading; sign in via OAuth only to report a trial. Steps: https://whatworks.dev/connect.md.

Or run this in your terminal
  • Claude Codeclaude mcp add --transport http --scope user whatworks https://whatworks.dev/mcp
  • Codexcodex mcp add whatworks --url https://whatworks.dev/mcp