{"id":13477621,"url":"https://github.com/ast-grep/ast-grep","last_synced_at":"2026-03-16T05:24:11.038Z","repository":{"id":41456019,"uuid":"509566212","full_name":"ast-grep/ast-grep","owner":"ast-grep","description":"⚡A CLI tool for code structural search, lint and rewriting. Written in Rust","archived":false,"fork":false,"pushed_at":"2025-05-01T00:04:33.000Z","size":7142,"stargazers_count":8583,"open_issues_count":56,"forks_count":217,"subscribers_count":24,"default_branch":"main","last_synced_at":"2025-05-01T13:47:43.920Z","etag":null,"topics":["ast","babel","codemod","codereview","command-line","command-line-tool","grep","linter","refactoring","rust","search","static-analysis","structural-search","tree-sitter","typescript"],"latest_commit_sha":null,"homepage":"https://ast-grep.github.io/","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ast-grep.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"HerringtonDarkholme"}},"created_at":"2022-07-01T19:21:00.000Z","updated_at":"2025-05-01T12:08:21.000Z","dependencies_parsed_at":"2023-10-27T08:29:12.419Z","dependency_job_id":"8b6f16e0-29c0-4f12-84e0-8bad48e47ea3","html_url":"https://github.com/ast-grep/ast-grep","commit_stats":{"total_commits":2731,"total_committers":53,"mean_commits":"51.528301886792455","dds":"0.28084950567557676","last_synced_commit":"d9014f979fd7ee34cd9f449449a32f25296c34f4"},"previous_names":[],"tags_count":181,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ast-grep%2Fast-grep","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ast-grep%2Fast-grep/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ast-grep%2Fast-grep/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ast-grep%2Fast-grep/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ast-grep","download_url":"https://codeload.github.com/ast-grep/ast-grep/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":251914922,"owners_count":21664447,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["ast","babel","codemod","codereview","command-line","command-line-tool","grep","linter","refactoring","rust","search","static-analysis","structural-search","tree-sitter","typescript"],"created_at":"2024-07-31T16:01:45.227Z","updated_at":"2026-03-16T05:24:11.031Z","avatar_url":"https://github.com/ast-grep.png","language":"Rust","readme":"\u003cp align=center\u003e\n  \u003cimg src=\"https://ast-grep.github.io/logo.svg\" alt=\"ast-grep\"/\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n   \u003cimg src=\"https://github.com/ast-grep/ast-grep/actions/workflows/coverage.yaml/badge.svg\" alt=\"coverage badge\"/\u003e\n   \u003ca href=\"https://app.codecov.io/gh/ast-grep/ast-grep\"\u003e\u003cimg src=\"https://codecov.io/gh/ast-grep/ast-grep/branch/main/graph/badge.svg?token=37VX8H2EWV\"/\u003e\u003c/a\u003e\n   \u003ca href=\"https://discord.gg/4YZjf6htSQ\" target=\"_blank\"\u003e\u003cimg alt=\"Discord\" src=\"https://img.shields.io/discord/1107749847722889217?label=Discord\"\u003e\u003c/a\u003e\n   \u003ca href=\"https://repology.org/project/ast-grep/versions\" target=\"_blank\"\u003e\u003cimg alt=\"Repology\" src=\"https://repology.org/badge/tiny-repos/ast-grep.svg\"\u003e\u003c/a\u003e\n   \u003ca href=\"https://github.com/ast-grep/ast-grep/stargazers\"\u003e\u003cimg src=\"https://img.shields.io/github/stars/ast-grep/ast-grep?style=social\" alt=\"Badge\"\u003e\u003c/a\u003e   \n   \u003ca href=\"https://github.com/ast-grep/ast-grep/network/members\"\u003e\u003cimg src=\"https://img.shields.io/github/forks/ast-grep/ast-grep?style=social\" alt=\"Badge\"\u003e\u003c/a\u003e\n   \u003ca href=\"https://github.com/sponsors/HerringtonDarkholme\"\u003e\u003cimg alt=\"GitHub Sponsors\" src=\"https://img.shields.io/github/sponsors/HerringtonDarkholme?style=social\"\u003e\u003c/a\u003e\n   \u003ca href=\"https://gurubase.io/g/ast-grep\"\u003e\u003cimg alt=\"Gurubase\" src=\"https://img.shields.io/badge/Gurubase-Ask%20ast--grep%20Guru-006BFF\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n## ast-grep(sg)\n\nast-grep(sg) is a CLI tool for code structural search, lint, and rewriting.\n\n## Introduction\nast-grep is an [abstract syntax tree](https://dev.to/balapriya/abstract-syntax-tree-ast-explained-in-plain-english-1h38) based tool to search code by pattern code. Think of it as your old-friend [`grep`](https://en.wikipedia.org/wiki/Grep#:~:text=grep%20is%20a%20command%2Dline,which%20has%20the%20same%20effect.), but matching AST nodes instead of text.\nYou can write patterns as if you are writing ordinary code. It will match all code that has the same syntactical structure.\nYou can use `$` sign + upper case letters as a [wildcard](https://en.wikipedia.org/wiki/Wildcard_character), e.g. `$MATCH`, to match any single AST node. Think of it as [regular expression dot](https://regexone.com/lesson/wildcards_dot) `.`, except it is not textual.\n\nTry the [online playground](https://ast-grep.github.io/playground.html) for a taste!\n\n## Screenshot\n![demo](https://ast-grep.github.io/image/search-replace.png)\n\nSee more screenshots on the [website](https://ast-grep.github.io/).\n\n## Installation\nYou can install it from [npm](https://docs.npmjs.com/downloading-and-installing-node-js-and-npm), [pip](https://pypi.org/), [cargo](https://doc.rust-lang.org/cargo/getting-started/installation.html),  [cargo-binstall](https://github.com/cargo-bins/cargo-binstall), [homebrew](https://brew.sh/), [scoop](https://scoop.sh/), [mise](https://github.com/jdx/mise) or [MacPorts](https://www.macports.org)!\n\n```bash\nnpm install --global @ast-grep/cli\npip install ast-grep-cli\nbrew install ast-grep\n```\n\n\n\u003cdetails\u003e\n\u003csummary\u003eClick for more installation methods\u003c/summary\u003e\n\n```bash\ncargo install ast-grep --locked\ncargo binstall ast-grep\n\n# install via scoop, thank @brian6932\nscoop install main/ast-grep\n\n# install via MacPorts\nsudo port install ast-grep\n\n# try ast-grep in nix-shell\nnix-shell -p ast-grep\n\n# try ast-grep with mise\nmise use -g ast-grep\n```\n\u003c/details\u003e\n\nOr you can build ast-grep from source. You need to install rustup, clone the repository and then\n```bash\ncargo install --path ./crates/cli --locked\n```\n[Packages](https://repology.org/project/ast-grep/versions) are available on other platforms too.\n\n\n## Command line usage example\n\nast-grep has following form.\n```\nast-grep --pattern 'var code = $PATTERN' --rewrite 'let code = new $PATTERN' --lang ts\n```\n\n### Example\n\n* [Rewrite code in null coalescing operator](https://twitter.com/Hchan_mgn/status/1547061516993699841?s=20\u0026t=ldDoj4U2nq-FRKQkU5GWXA)\n\n```bash\nast-grep -p '$A \u0026\u0026 $A()' -l ts -r '$A?.()'\n```\n\n* [Rewrite](https://twitter.com/Hchan_mgn/status/1561802312846278657) [Zodios](https://github.com/ecyrbe/zodios#migrate-to-v8)\n```bash\nast-grep -p 'new Zodios($URL,  $CONF as const,)' -l ts -r 'new Zodios($URL, $CONF)' -i\n```\n\n* [Implement eslint rule using YAML.](https://twitter.com/Hchan_mgn/status/1560108625460355073)\n\n\n## Sponsor\n![Sponsors](https://raw.githubusercontent.com/HerringtonDarkholme/sponsors/main/sponsorkit/sponsors.svg)\n\nIf you find ast-grep interesting and useful for your work, please [buy me a coffee](https://github.com/sponsors/HerringtonDarkholme)\nso I can spend more time on the project!\n\n## Feature Highlight\n\nast-grep's core is an algorithm to search and replace code based on abstract syntax tree produced by tree-sitter.\nIt can help you to do lightweight static analysis and massive scale code manipulation in an intuitive way.\n\nKey highlights:\n\n* An intuitive pattern to find and replace AST.\nast-grep's pattern looks like ordinary code you would write every day (you could say the pattern is isomorphic to code).\n\n* jQuery like API for AST traversal and manipulation.\n\n* YAML configuration to write new linting rules or code modification.\n\n* Written in compiled language, with tree-sitter based parsing and utilizing multiple cores.\n\n* Beautiful command line interface :)\n\nast-grep's vision is to democratize abstract syntax tree magic and to liberate one from cumbersome AST programming!\n\n* If you are an open-source library author, ast-grep can help your library users adopt breaking changes more easily.\n* if you are a tech lead in your team, ast-grep can help you enforce code best practice tailored to your business need.\n* If you are a security researcher, ast-grep can help you write rules much faster.\n","funding_links":["https://github.com/sponsors/HerringtonDarkholme"],"categories":["Rust","Files and Directories","Applications","Rust 程序设计","babel","\u003ca name=\"text-search\"\u003e\u003c/a\u003eText search (alternatives to grep)"],"sub_categories":["Search","Productivity","网络服务_其他"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fast-grep%2Fast-grep","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fast-grep%2Fast-grep","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fast-grep%2Fast-grep/lists"}