ast-grep

scriptablepopularlocal-onlyshell utilitiesbrew

ast-grep · Structural search and replace for code, not just text.

$ brew install ast-grep
One-liner to try
$ sg --pattern 'console.log($$$)' src

Agent pack

Copy into an agent

A markdown-ready setup brief with install, verify, safe starting commands, and guardrails for AI agents.

Open .mdJSON
Readiness
Great for agents · 85/100
Verify
sg --version
Agent URL
/cli/ast-grep/agent.md

Quick reference

Install
brew install ast-grep
Verify
sg --version
First command
sg --pattern 'console.log($$$)' src
Machine JSON
/cli/ast-grep.json

About

Structural search and replace for code, not just text. Built by ast-grep. Start with `sg --pattern 'console.log($$$)' src` and go from there. Supports structured output — good for scripts and agents. Runs entirely on your machine.

Example workflow

1. sg --pattern 'console.log($$$)' src
2. sg --pattern 'console.log($$$)' --rewrite 'logger.debug($$$)' --dry-run src
3. sg scan

Alternatives worth considering