{"schemaVersion":"opencli.cli.v1","slug":"ast-grep","name":"ast-grep","shortName":"sg","binaryName":"sg","maker":{"slug":"ast-grep","name":"ast-grep","type":"small-team","url":"https://ast-grep.github.io","officialPlatformMaker":false,"featuredBuilder":true},"category":"Shell Utilities","description":"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.","tagline":"Structural search and replace for code, not just text.","install":{"packageManager":"brew","command":"brew install ast-grep","packageName":null,"npmPackage":null,"brewFormula":"ast-grep","brewCask":null,"crateName":null,"pypiPackage":null,"goPackage":null,"dockerImage":null},"verify":{"command":"sg --version","signal":"sg responds locally and is ready for the first real command."},"quickStart":"sg --pattern 'console.log($$$)' src","exampleWorkflow":["sg --pattern 'console.log($$$)' src","sg --pattern 'console.log($$$)' --rewrite 'logger.debug($$$)' --dry-run src","sg scan"],"agent":{"readiness":{"label":"Great for agents","score":85,"reasons":["Structured output is available for parsing.","Supports non-interactive/scripted use.","Works well in CI or repeatable automation.","Can run locally with less credential exposure."],"guardrails":["Start read-only, then ask before mutations."]},"packUrl":"https://opencli.co/cli/ast-grep/agent.md","packMarkdown":"# OpenCLI Agent Pack: ast-grep\n\nUse this when an AI agent needs to work with `sg`.\n\n## What this CLI is for\nStructural 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.\n\nBest for: Finding and rewriting code by AST pattern — what ripgrep cannot see.\n\n## Agent readiness\nGreat for agents (85/100)\n- Structured output is available for parsing.\n- Supports non-interactive/scripted use.\n- Works well in CI or repeatable automation.\n- Can run locally with less credential exposure.\n\n## Install\n```sh\nbrew install ast-grep\n```\n\n## Verify before real work\n```sh\nsg --version\n```\nExpected signal: sg responds locally and is ready for the first real command.\n\n## Safe starting commands\n```sh\nsg --version\n```\n\n```sh\nsg --pattern 'console.log($$$)' src\n```\n\n```sh\nsg --pattern 'console.log($$$)' --rewrite 'logger.debug($$$)' --dry-run src\n```\n\n```sh\nsg scan\n```\n\n## Guardrails for agents\n- Start read-only, then ask before mutations.\n\n## Suggested agent instruction\nYou may use ast-grep (`sg`) for finding and rewriting code by ast pattern — what ripgrep cannot see.. First install it if missing, then run the verify command. Start with read-only or inspection commands. Summarize what you found before changing anything. Ask for confirmation before commands that mutate remote state, spend money, deploy, delete data, merge code, or expose secrets.\n\nSource: OpenCLI\n"},"fit":{"bestFor":"Finding and rewriting code by AST pattern — what ripgrep cannot see.","useThisIf":"You want an agent to refactor or audit code by syntax, not regex.","skipIf":"You only need plain-text search — use ripgrep.","whatHappensNext":"Run `sg --pattern 'console.log($$$)' --rewrite 'logger.debug($$$)' --dry-run src` to see it in action."},"capabilities":{"agentFriendly":true,"supportsJsonOutput":true,"supportsNonInteractive":true,"supportsDryRun":false,"requiresAuth":false,"requiresNetwork":false,"ciFriendly":true,"localFirst":true,"destructivePotential":"medium"},"taxonomy":{"useCases":["Structural search","Codemods","Refactoring"],"aliases":["sg","ast grep"],"keywords":["ast grep refactor search replace"],"tags":["builder","agent-friendly","json-output","local-first"]},"links":{"website":"https://ast-grep.github.io","github":"https://github.com/ast-grep/ast-grep","docs":"https://ast-grep.github.io/guide/quick-start.html","opencli":"https://opencli.co/cli/ast-grep","markdown":"https://opencli.co/cli/ast-grep/agent.md","json":"https://opencli.co/cli/ast-grep.json"},"metrics":{"githubStars":15895,"latestRelease":"2026-08-31T01:42:23Z","license":"MIT","metricLabel":null,"metricValue":null,"metricSource":null,"metricAsOf":"2026-09-14"}}