Skip to main content
Back to Blog
•Rafael Gonzalez

The Cursor ast-grep stack: structural rewrite and Graphify

Cursor writes the example. ast-grep matches syntax instead of regex. Graphify shows what still depends on the old shape. How the three actually hand off.

Use this stack as a page: the Cursor ast-grep stack.

Regex-driven “rename this identifier” in a 2026 repo is how you rewrite a string in a comment, miss the type, and ship. Cursor can apply a patch. It should not be the engine for a thousand-file mechanical edit.

The stack that stuck:

  1. Cursor — one example edit you have actually read.
  2. ast-grep — AST search and rewrite.
  3. Graphify — what still depends on the old symbol.

Same-job compare if you are choosing how the agent sees the repo: ast-grep vs Graphify. ast-grep is structural grep. Graphify is a graph. Use both.

Why the agent’s search is the wrong layer

Cursor’s search is for you to jump. The agent will happily rg a name that appears in generated code, snapshots, and a Markdown doc. ast-grep matches syntax trees. That is the difference between “replace foo” and “replace the identifier foo in a call expression.”

Graphify then answers the question regex cannot: after the rewrite, what still imports the old module?

The three roles

Cursor owns the example

Write one after-shape in the editor. Read it. That is the spec. Do not start with a repo-wide agent loop that “finds all the foos.”

ast-grep owns the rewrite

npm install -g @ast-grep/cli. Turn the example into a rule. Dry-run. Then write. Do not use it as a replacement for Graphify’s “who calls this.”

Graphify owns the blast radius

Ask what still depends on the old name before you apply, and again after if the rule was partial. Do not ask Graphify to perform the rewrite.

One job, four steps

  1. Write one example edit in Cursor so you know the after shape.
  2. Turn that shape into an ast-grep rule and run it dry before you write.
  3. Ask Graphify what still depends on the old symbol.
  4. Apply the rewrite. Review the diff in Cursor, not in the grep output.

Add-ons for this host: Cursor add-ons. Architecture maps are a different stack: Cursor + Graphify + Archify.