- How you use it
- A setting in your project
- What it can do
- installs software · writes files · network · runs shell
- What's inside
The option
| Option | 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
Useridentifiers 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.
-Uwrites 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
- 01 · YouPaste the line from Try it into your agent.
- 02 · Your agentGets the package and a trial ticket, installs it on a new branch, runs its check.
- 03 · YouApprove a one-line report. Nothing is posted without you.