Skip to content
Agentmart
Submit a tool

ast-grep-refactor

Structural refactoring and safe code rewrites with ast-grep across supported languages.

Skill by seruman

IndexedMIT★ 1
Write a review

Install

Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.

npx agentmarket install skill/seruman-ast-grep-refactor

Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.

Get the weekly diff

The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.

We use your email only for this newsletter. Privacy

About

Structural refactoring and safe code rewrites with ast-grep across supported languages. Use for codemods, removing or replacing AST nodes (imports, docstrings, arguments), pattern-based migrations, and multi-file transformations when plain text search/replace is likely to be unsafe.

No reviews yet. Installed it? Reviews come from verified installers only. How reviews work

Permissions

What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.

Tools
No tools found
Secrets
None asked for
Install scripts
None found

Network hosts it talks to 1

  • codeload.github.com · found in install command

Files it touches

  • ~/.claude/skills/ast-grep-refactor

What's inside

Skill name
ast-grep-refactor
Description
Structural refactoring and safe code rewrites with ast-grep across supported languages. Use for codemods, removing or replacing AST nodes (imports, docstrings, arguments), pattern-based migrations, and multi-file transformations when plain text search/replace is likely to be unsafe.
License
MIT
Instructions
54 lines in SKILL.md · view on GitHub

Files (8)

  • SKILL.md
  • examples.md · references/
  • fix-expand.md · references/
  • rewrite.md · references/
  • rewriter.md · references/
  • rule-basics.md · references/
  • transform.md · references/
  • troubleshooting.md · references/

SKILL.md (first lines)

# ast-grep Refactor

Use ast-grep to refactor by AST, not by text. Keep rules small, test on samples, then scale to the codebase.

## Quick workflow

1. Inspect AST for the target pattern.
2. Write a rule that matches only what you intend.
3. Dry-run on small files and review diffs.
4. Apply at scale only after review or tests.
5. Format and run checks.

```bash
ast-grep run --pattern '...' --lang <language> --debug-query=ast path/to/file
ast-grep scan -r rule.yml path/to/file
ast-grep scan -r rule.yml --update-all path/glob/**
```

Review matches via `ast-grep scan` output, `--interactive`, or `git diff` before `--update-all`.

## Decide the rule shape

- Use `pattern` for simple rewrites with metavariables.
- Use `kind` plus relational rules (`inside`, `has`, `nthChild`) for structural or positional changes.
- Use `fix` string for direct replacement; use `FixConfig` when you must remove punctuation or neighbors.
- Use `transform` to change captured strings; use `rewriters` to rewrite different subnodes differently.

## Rule files

- Separate multiple rules with `---`.
- Keep rules focused and composable.
- For repeatable or risky changes, add rule tests and run `ast-grep test`.

## References

- Rule basics and selection: `references/rule-basics.md`
- Rewrite and `fix`: `references/rewrite.md`
- FixConfig expansion: `references/fix-expand.md`
- Transformations: `references/transform.md`
- Rewriters: `references/rewriter.md`
- Troubleshooting: `references/troubleshooting.md`
- Examples: `references/examples.md`

## When to skip ast-grep

- Very small, one-off edits where manual editing is faster.
- Pure text replacement where AST structure does not matter.
- Changes requiring type-aware or semantic analysis.

## Links

- [ast-grep](https://github.com/ast-grep/ast-grep)

From seruman/pi-things, MIT.

More from seruman/pi-things

Signals

Stars
1
Forks
0
Open issues
0
Last commit (this folder)
May 6, 2026 (5 months ago)

From GitHub (fetched Oct 24, 2026).

Details

License
MIT
First seen
Oct 24, 2026
Last checked
Oct 24, 2026

More from seruman

Cite this page

ast-grep-refactor skill. Agent Mart. https://agentmart.dev/skills/seruman-ast-grep-refactor (last updated 2026-10-24)