← 返回 CLI 目录 抓取的
ripgrep
$ rg 社区开源 低风险 BurntSushi (OSS) · 文件检索与编辑 · MIT / Unlicense · macos / linux / windows
ripgrep(rg)是几乎所有主流编码 Agent 底座共同依赖的本地代码搜索标准触手:零副作用、Rust 毫秒级启动、自动过滤 .gitignore 并原生支持结构化 --json 匹配事件输出。
FCRS-1.0 综合评分
98 /100
极佳 (Excellent)
高置信度 (实测)
零摩擦安装命令
brew install ripgrep CLI vs MCP 选型建议 优先选 CLI
本地 rg 毫秒级扫描数千个文件且零 RPC 开销;完全没有必要把本地文本检索包装成 MCP Server。
Agent 友好度体检单
本地探针实测证据 ✓ 原生 JSON 输出
— 字段裁剪
✓ 无头非交互
— 支持 Dry-Run
✓ 只读模式开关
✓ 支持 NO_COLOR
— 自省/Schema 发现
— 官方 SKILL.md
实测版本
ripgrep 14.1.1
冷启动耗时
16 ms
退出码 (help / 非法参数)
0 / 2
NO_COLOR 无色码污染 / 无 TTY 不挂起
Yes / Safe
抓取的 --help 摘要
ripgrep 14.1.1 Andrew Gallant <[email protected]> ripgrep (rg) recursively searches the current directory for lines matching a regex pattern. By default, ripgrep will respect gitignore rules and automatically skip hidden files/directories and binary files. Use -h for short descriptions and --help for more details. Project home page: https://github.com/BurntSushi/ripgrep USAGE: rg [OPTIONS] PATTERN [PATH ...] rg [OPTIONS] -e PATTERN ... [PATH ...] rg [OPTIONS] -f PATTERNFILE ... [PATH ...] rg [OPTIONS] --files [PATH ...] rg [OPTIONS] --type-list command | rg [OPTIONS] PATTERN rg [OPTIONS] --help rg [OPTIONS] --version POSITIONAL ARGUMENTS: <PATTERN> A regular expression used for searching. To match a pattern beginning with a dash, use the -e/--regexp flag. For example, to search for the literal '-foo', you can use this flag: rg -e -foo You can also use the special '--' delimiter to indicate that no more flags will be provided. Namely, the following is equivalent to the above: rg -- -foo <PATH>... A file or directory to search. Directories are searched recursively. File paths specified on the command line override glob and ignore rules. INPUT OPTIONS: -e PATTERN, --regexp=PATTERN A pattern to search for. This option can be provided multiple times, where all patterns given are searched, in addition to any patterns provided by -f/--file. Lines matching at least one of the provided patterns are printed. This flag can also be used when searching for patterns that start with a dash. For example, to search for the literal -foo: rg -e -foo You can also use the special -- delimiter to indicate that no more flags will be provided. Namely, the following is equivalent to the above: rg -- -foo When -f/--file or -e/--regexp is used, then ripgrep treats all positional arguments as files or directories to search. -f PATTERNFILE, --file=PATTERNFILE Search for patterns from the given file, with one pattern per line. When this flag is used multiple times or in combination with the -e/--regexp flag, then all patterns provided are searched. Empty pattern lines will match all input lines, and the newline is not counted as part of the pattern. A line is printed if
FCRS-1.0 六维评分拆解
Agent 友好度 24 / 25
支持 --json NDJSON 输出、--color never / NO_COLOR、非 TTY 自动纯文本以及规范退出码(0 命中、1 未命中、2 错误)。
- Native
--jsonNDJSON format and non-TTY plain stdout detection - Distinguishes no-match (exit 1) from syntax/IO errors (exit 2)
安全与权限边界 25 / 25
严格本地只读、零网络请求、零凭证需求,且默认跳过 .gitignore 与二进制文件。
- Pure local read-only binary; no write or network side effects
安装与运行摩擦 15 / 15
零依赖 Rust 静态二进制,全平台覆盖 brew、apt、cargo、winget。
- Single static binary across macOS, Linux, and Windows
能力覆盖与边际价值 15 / 15
通过 -l、--max-count 与 glob 过滤实现极致的检索速度与 Token 效率。
- Industry-standard codebase search tool for AI coding agents
维护与来源背书 10 / 10
久经考验的开源基石项目(BurntSushi/ripgrep),稳定性极高。
- Widely adopted OSS project under MIT/Unlicense
文档与可验证性 9 / 10
具备完备的 --help、man 手册与 GUIDE.md。
- Detailed GUIDE.md and man page
安全边界、鉴权与放权指南
鉴权方式
无需鉴权
凭证存储位置
无需任何凭证;仅以只读方式扫描本地可读文件。
潜在副作用
只读查询
费用与配额提示
100% 免费、离线且以 MIT / Unlicense 开源。
可复制到 CLAUDE.md / AGENTS.md 的安全护栏
# ripgrep (rg) Agent Rules - Prefer `rg -l` first when scoping broad searches, then read targeted line ranges. - Use `--json` or `--vimgrep` when parsing structured positions programmatically. - Pass `--max-count` or `head` bounds on huge monorepos to avoid context bloat.
Agent 高频安全命令配方
只读查询(安全推荐)
输出结构化 NDJSON 匹配事件
rg --json "export function" src/
逐行输出包含精确文件路径、行号与子匹配位置的 JSON 对象。
仅列出命中文件路径(最省 Token)
rg -l "TODO" src/
只返回文件名列表,防止大范围检索把匹配行直接灌满上下文。
核心优势
- + 零风险纯只读本地触手,冷启动仅毫秒级。
- + 管道输出时自动剥离 ANSI 色彩,并提供
--jsonNDJSON 结构化结果。 - + 默认遵循
.gitignore,自动把node_modules与忽略文件挡在上下文之外。
注意事项与踩坑点
- ! 未匹配任何内容时返回退出码
1(标准 grep 约定——Agent 不应将其误判为程序崩溃)。
已验证兼容的 Agent 宿主
Claude Code Codex CLI Gemini CLI