面向 15 种编程语言的快速 AST 索引型代码搜索 CLI,采用原生 Rust 实现,支持与 Claude Code / Cursor 深度集成。
ast-index 是一个面向 15 种编程语言的快速 AST 索引型代码搜索 CLI 工具,采用原生 Rust 实现。它使用 tree-sitter 进行多语言 AST 解析,结合 SQLite FTS5 全文索引,在大型代码库中实现毫秒级符号搜索。
核心技术栈
- grep-searcher(ripgrep 内核)用于快速文本搜索
- SQLite + FTS5 用于全文搜索索引存储
- rayon 用于并行文件解析
- tree-sitter 用于 12 种语言的 AST 解析
主要功能
索引型搜索命令(需先执行 ast-index rebuild 建立索引)
search- 通用符号搜索class- 类/接口/协议搜索symbol- 任意符号搜索implementations- 查找接口/抽象类的实现hierarchy- 类继承树usages- 符号用法(引用点)
Grep 型搜索命令(无需索引)
todo- TODO/FIXME/HACK 注释callers- 函数调用点composables- @Composable 函数deprecated- @Deprecated 项inject- @Inject/@Autowired 注入点annotations- 带注解的类extensions- 扩展函数flows- Flow/StateFlow/SharedFlow
模块依赖分析
module/deps/dependents- 模块及其依赖关系unused-deps- 未使用的依赖(含传递依赖、XML、资源检查)api- 模块公开 API
XML & 资源分析
xml-usages- XML 布局中类用法resource-usages- 资源用法及未使用资源检测
iOS 专用命令
storyboard-usages/asset-usages/swiftui/async-funcs/publishers/main-actor
性能基准(~29k 文件, ~300k 符号的大型 Android 项目)
| 命令 | ast-index | grep | 加速倍数 |
|---|---|---|---|
| imports | 0.3ms | 90ms | 260x |
| dependents | 2ms | 100ms | 100x |
| deps | 3ms | 90ms | 90x |
| class | 1ms | 90ms | 90x |
| search | 11ms | 280ms | 14x |
| usages | 8ms | 90ms | 12x |
性能优化机制
- 批量索引:500 文件分块解析和写入
- 线程池限制:最多 8 线程控制内存峰值
- 跳过大文件(> 1 MB)和长行(> 2000 字符)
- SQLite 缓存:8 MB
- 硬编码目录排除:node_modules, pycache, build, dist, target, vendor, .gradle, Pods, DerivedData 等
安装方式
# Homebrew (macOS/Linux)
brew tap defendend/ast-index
brew install ast-index
# 从源码构建
git clone https://github.com/defendend/Claude-ast-index-search.git
cd Claude-ast-index-search
cargo build --release
Claude Code 集成
claude plugin marketplace add defendend/Claude-ast-index-search
claude plugin install ast-index
支持语言 Kotlin, Java, Swift, Objective-C, TypeScript, JavaScript, Rust, C#, Python, Go, C++, Scala, Ruby, Perl, Dart/Flutter,以及 Protocol Buffers, WSDL/XSD
项目信息
- 许可证:MIT License
- 最新版本:v3.20.0(48 个版本发布)
- 二进制大小:~4.4 MB