ripgrep

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Ripgrep Skill

Ripgrep 技能

<identity> Enhanced code search with ripgrep binary. NOTE: Prefer `pnpm search:code` for discovery/ranking and smaller output payloads; prefer raw `rg` for fastest exact literal matching. </identity> <capabilities> - **DEPRECATED**: Use `pnpm search:code "query"` instead (hybrid ripgrep + embeddings) - Raw ripgrep access for advanced regex patterns (PCRE2 with -P flag) - Custom file type definitions via .ripgreprc - Integration with .gitignore and custom ignore patterns </capabilities>
<identity> 基于ripgrep二进制的增强型代码搜索工具。注意:如需发现/排序功能和更小的输出负载,优先使用`pnpm search:code`;如需最快的精确字面匹配,优先使用原生`rg`命令。 </identity> <capabilities> - **已废弃**:请改用`pnpm search:code "query"`(混合ripgrep + 向量嵌入) - 原生ripgrep访问,支持高级正则模式(带-P标志的PCRE2) - 通过.ripgreprc自定义文件类型定义 - 与.gitignore和自定义忽略模式集成 </capabilities>

⚡ RECOMMENDED: Hybrid Lazy Code Search (Instant, No Batch Indexing)

⚡ 推荐:混合惰性代码搜索(即时响应,无需批量索引)

Use the hybrid lazy search system for day-to-day code discovery:
  • Instant: search works immediately with no warm-up indexing pass
  • No upfront indexing: Search immediately with no multi-hour batch index build
  • Lazy embeddings: Semantic vectors update incrementally in background as files are edited
  • Hybrid scoring: Reciprocal Rank Fusion (RRF) combines text matches + semantic similarity
日常代码发现工作请使用混合惰性搜索系统:
  • 即时响应:搜索无需预热索引,立即生效
  • 无前置索引:无需耗时数小时的批量索引构建,可立即搜索
  • 惰性嵌入:语义向量在文件编辑时于后台增量更新
  • 混合评分:采用Reciprocal Rank Fusion (RRF) 结合文本匹配与语义相似度

Search Commands

搜索命令

bash
undefined
bash
undefined

Search code instantly (ripgrep-based)

即时搜索代码(基于ripgrep)

pnpm search:code "authentication logic" pnpm search:code "export class User" pnpm search:code "import react"
pnpm search:code "authentication logic" pnpm search:code "export class User" pnpm search:code "import react"

View project structure

查看项目结构

pnpm search:structure
pnpm search:structure

Get file content with line numbers

获取带行号的文件内容

pnpm search:file src/auth.ts 1 50
undefined
pnpm search:file src/auth.ts 1 50
undefined

Search Mode Contract (Deterministic)

搜索模式约定(确定性)

| Mode | Use when | Latency tendency | Determinism | Output/token impact | | -------------------------------- | ------------------------------------------------- | ------------------------------ | ----------- | ------------------------------- | -------------------- | |
pnpm search:code "query"
| Concept discovery, unknown implementation paths | Fast | High | Compact ranked output | |
pnpm search:code "ast:pattern"
| Structural pattern intent (AST shape) | Moderate | High | Compact + structure-aware | |
pnpm search:structure
| System map: entrypoints, dependencies, boundaries | Fast | High | Very low | |
rg -F "literal"
| Exact symbol/literal lookup and anchor checks | Fastest | Highest | Potentially large unless scoped | |
rga "query"
| Non-code assets (pdf/docs/archive) | Slower than
rg
| High | Can be high noise | |
rg                              | rga -> fzf
| Manual narrowing and selection | Interactive | Operator-dependent | Good human triage UX |
Required selection behavior:
  • Agents must default to
    pnpm search:code
    for discovery.
  • Agents must use
    rg -F
    before edits/refactors to validate exact anchors.
  • Agents should use
    ast:
    only for explicitly structural requests.
  • fzf
    stays optional for human-in-the-loop workflows; do not require it for automation.
模式使用场景延迟趋势确定性输出/Token影响
pnpm search:code "query"
概念发现、未知实现路径探索紧凑的排序输出
pnpm search:code "ast:pattern"
结构化模式匹配(AST形状)中等紧凑且感知结构的输出
pnpm search:structure
系统映射:入口点、依赖关系、边界输出量极低
rg -F "literal"
精确符号/字面量查找和锚点校验最快最高除非限定范围,否则输出量可能很大
rga "query"
非代码资产(PDF/文档/归档文件)
rg
可能存在大量噪声
rg | rga -> fzf
手动筛选和选择交互式依赖操作者良好的人工筛选体验
必须遵循的选择规则:
  • Agent进行发现工作时,默认使用
    pnpm search:code
  • 编辑/重构前,必须使用
    rg -F
    验证精确锚点
  • 仅在明确需要结构匹配时使用
    ast:
    模式
  • fzf
    仅用于人工介入的工作流,自动化流程中不强制要求

Interactive Narrowing with fzf (Operator UX)

结合fzf进行交互式筛选(操作者体验)

When result sets are large, use
fzf
to interactively narrow
rg
/
rga
output.
bash
undefined
当结果集较大时,使用
fzf
rg
/
rga
输出进行交互式筛选。
bash
undefined

rg + fzf + file preview

rg + fzf + 文件预览

rg --line-number --no-heading --color=always "auth|token|session" .
| fzf --ansi --delimiter ":"
--preview "bat --color=always --style=numbers --highlight-line {2} {1}"
rg --line-number --no-heading --color=always "auth|token|session" . \ | fzf --ansi --delimiter ":" \ --preview "bat --color=always --style=numbers --highlight-line {2} {1}"

rga (documents/archives) + fzf

rga(文档/归档)+ fzf

rga --line-number --no-heading --color=always "invoice|receipt|policy" .
| fzf --ansi --delimiter ":"
--preview "bat --color=always --style=numbers --line-range=:300 {1}"

Advanced interactive ripgrep launcher pattern:

```bash
: | rg_prefix='rg --column --line-number --no-heading --color=always --smart-case' \
  fzf --ansi --disabled \
      --bind 'start:reload:$rg_prefix ""' \
      --bind 'change:reload:$rg_prefix {q} || true'
Usage contract:
  • Use
    fzf
    for operator selection/narrowing, not as a replacement for search backends.
  • Keep
    pnpm search:code
    as default for agent discovery/ranking workflows.
  • Use
    rg
    /
    rga
    +
    fzf
    for interactive triage and manual result picking.
Structural + interactive workflow (human triage):
bash
undefined
rga --line-number --no-heading --color=always "invoice|receipt|policy" . \ | fzf --ansi --delimiter ":" \ --preview "bat --color=always --style=numbers --line-range=:300 {1}"

高级交互式ripgrep启动器模式:

```bash
: | rg_prefix='rg --column --line-number --no-heading --color=always --smart-case' \\
  fzf --ansi --disabled \\
      --bind 'start:reload:$rg_prefix ""' \\
      --bind 'change:reload:$rg_prefix {q} || true'
使用约定:
  • fzf
    用于操作者选择/筛选,而非替代搜索后端
  • Agent发现/排序工作流中,默认使用
    pnpm search:code
  • 交互式筛选和手动结果选择使用
    rg
    /
    rga
    +
    fzf
结构化+交互式工作流(人工筛选):
bash
undefined

Structural candidates (ast-grep)

结构化候选(ast-grep)

ast-grep -p 'function $NAME($$$) { $$$ }' --lang javascript --files-with-matches .
ast-grep -p 'function $NAME($$$) { $$$ }' --lang javascript --files-with-matches .

Narrow candidates interactively

交互式筛选候选

ast-grep -p 'function $NAME($$$) { $$$ }' --lang javascript --files-with-matches .
| fzf --ansi --delimiter ":"
--preview "bat --color=always --style=numbers --line-range=:220 {}"
undefined
ast-grep -p 'function $NAME($$$) { $$$ }' --lang javascript --files-with-matches . \ | fzf --ansi --delimiter ":" \ --preview "bat --color=always --style=numbers --line-range=:220 {}"
undefined

How It Works

工作原理

  1. Pre-prompt hook analyzes repository structure using ripgrep (~0.5s)
  2. search:code
    executes fast text matching via ripgrep
  3. Optional semantic embeddings add similarity-based ranking
  4. Post-edit hook incrementally embeds only changed files
  5. RRF merges text and semantic rankings into a single ordered result set
  1. 预提示钩子使用ripgrep分析仓库结构(约0.5秒)
  2. search:code
    通过ripgrep执行快速文本匹配
  3. 可选的语义嵌入添加基于相似度的排序
  4. 编辑后钩子仅增量嵌入已更改的文件
  5. RRF将文本匹配和语义排序合并为单一有序结果集

Configuration

配置

bash
undefined
bash
undefined

Optional binary overrides (normally auto-detected)

可选二进制覆盖(通常自动检测)

RG_BIN=/path/to/rg AST_GREP_BIN=/path/to/ast-grep RGA_BIN=/path/to/rga FZF_BIN=/path/to/fzf
RG_BIN=/path/to/rg AST_GREP_BIN=/path/to/ast-grep RGA_BIN=/path/to/rga FZF_BIN=/path/to/fzf

Disable semantic search (text-only, fastest)

禁用语义搜索(仅文本,速度最快)

HYBRID_EMBEDDINGS=off
HYBRID_EMBEDDINGS=off

Enable semantic search (requires LanceDB)

启用语义搜索(需要LanceDB)

HYBRID_EMBEDDINGS=on
HYBRID_EMBEDDINGS=on

Disable daemon transport (direct CLI execution)

禁用守护进程传输(直接CLI执行)

HYBRID_SEARCH_DAEMON=off
HYBRID_SEARCH_DAEMON=off

Auto-prewarm daemon on startup

启动时自动预热守护进程

HYBRID_DAEMON_PREWARM=true
HYBRID_DAEMON_PREWARM=true

Daemon idle timeout in ms (default 600000)

守护进程空闲超时(毫秒,默认600000)

HYBRID_DAEMON_IDLE_MS=600000
undefined
HYBRID_DAEMON_IDLE_MS=600000
undefined

Daemon + Prewarm Runbook

守护进程+预热操作手册

bash
undefined
bash
undefined

Start, verify, prewarm

启动、验证、预热

pnpm search:daemon:start pnpm search:daemon:status pnpm search:daemon:prewarm
pnpm search:daemon:start pnpm search:daemon:status pnpm search:daemon:prewarm

Search (daemon path)

搜索(通过守护进程)

pnpm search:code "authentication logic"
pnpm search:code "authentication logic"

Stop daemon

停止守护进程

pnpm search:daemon:stop

Expected latency profile on this repository:

- Cold daemon first query (no prewarm): ~1.35s avg
- First query after prewarm: ~0.40s avg
- Warm repeated daemon queries: ~0.18-0.19s
- Direct mode (`HYBRID_SEARCH_DAEMON=off`): ~0.73s avg for repeated CLI calls
pnpm search:daemon:stop

本仓库的预期延迟表现:

- 冷启动守护进程首次查询(未预热):平均约1.35秒
- 预热后首次查询:平均约0.40秒
- 预热后重复查询:约0.18-0.19秒
- 直接模式(`HYBRID_SEARCH_DAEMON=off`):重复CLI调用平均约0.73秒

Comparison with Batch Indexing

与批量索引的对比

ApproachStartupFirst SearchMemoryDisk
Old Batch Indexing2+ hoursInstant after index8-16GB2-5GB
Hybrid Lazy Search0 seconds~0.5s<500MB<100MB
方法启动时间首次搜索速度内存占用磁盘占用
旧批量索引2小时以上索引完成后即时响应8-16GB2-5GB
混合惰性搜索0秒约0.5秒<500MB<100MB

Measured Performance and Output (This Repo)

实测性能与输出(本仓库)

Using the same 5 queries on this repository:
ModeAvg LatencyAvg Output BytesBest Use Case
pnpm search:code
(
HYBRID_EMBEDDINGS=off
)
~227ms~461 bytesFast discovery with compact output
pnpm search:code
(
HYBRID_EMBEDDINGS=on
)
~734ms~512 bytesSemantic/concept queries
Raw
rg
literal search
~35ms~2478 bytesExact symbol/literal lookup
Interpretation:
  • Raw
    rg
    is fastest for exact literal/symbol lookups
  • Hybrid search returns significantly smaller output payloads (often lower token pressure)
  • Embeddings improve semantic recall, but add latency
在本仓库中使用相同的5个查询测试:
模式平均延迟平均输出字节数最佳使用场景
pnpm search:code
HYBRID_EMBEDDINGS=off
~227ms~461字节快速发现,输出紧凑
pnpm search:code
HYBRID_EMBEDDINGS=on
~734ms~512字节语义/概念查询
原生
rg
字面搜索
~35ms~2478字节精确符号/字面量查找
结论:
  • 原生
    rg
    是精确字面量/符号查找的最快方式
  • 混合搜索返回的输出负载显著更小(通常Token压力更低)
  • 向量嵌入提升语义召回率,但会增加延迟

Decision Rule (Practical)

实用决策规则

Use
pnpm search:code
when:
  • Query is conceptual/natural language (
    "auth flow for refresh tokens"
    )
  • You need ranked results and concise context for agent prompts
  • You want lower output volume by default
Use raw
rg
when:
  • Query is an exact symbol/literal (
    TaskUpdate(
    ,
    HybridLazyIndexer
    , exact export names)
  • You need the fastest possible lookup time
  • You need advanced regex/PCRE2 behavior
当以下情况时使用
pnpm search:code
  • 查询为概念性/自然语言(如
    "auth flow for refresh tokens"
  • 需要排序结果和用于Agent提示的简洁上下文
  • 默认希望输出量更小
当以下情况时使用原生
rg
  • 查询为精确符号/字面量(如
    TaskUpdate(
    HybridLazyIndexer
    、精确导出名称)
  • 需要最快的查找速度
  • 需要高级正则/PCRE2特性

Measured by File Size (This Repo)

按文件大小实测(本仓库)

Sample size: 4 small files (0.5-5KB), 4 large files (30-109KB), literal token queries.
Bucket
search:code
off
search:code
on
rg_repo
rg_file
Small files~230ms / ~2707B~600ms / ~2965B~34ms / ~17075B~15ms / ~1156B
Large files~228ms / ~2354B~475ms / ~2847B~35ms / ~17811B~15ms / ~6564B
Takeaways:
  • rg_file
    is fastest and best for targeted file-level checks.
  • rg_repo
    remains fastest for repo-wide literal scans, but emits much larger output payloads.
  • search:code
    has steadier latency across file sizes and typically lower output volume for prompt usage.
样本:4个小文件(0.5-5KB),4个大文件(30-109KB),字面量Token查询。
文件分类
search:code
关闭
search:code
开启
rg_repo
rg_file
小文件~230ms / ~2707B~600ms / ~2965B~34ms / ~17075B~15ms / ~1156B
大文件~228ms / ~2354B~475ms / ~2847B~35ms / ~17811B~15ms / ~6564B
结论:
  • rg_file
    是针对目标文件检查的最快方式。
  • rg_repo
    仍是仓库范围字面量扫描的最快方式,但会产生大得多的输出负载。
  • search:code
    在不同文件大小下的延迟更稳定,且通常输出量更小,适合提示使用。

Real-World Scenario Playbook (Tested Patterns)

真实场景使用指南(已测试模式)

Use these scenario patterns to choose the right search path quickly.
使用以下场景模式快速选择合适的搜索方式。

Scenario 1: Incident Triage (Unknown Root Cause)

场景1:事件排查(未知根因)

Goal: find likely hotspots for a production symptom quickly without flooding context.
bash
undefined
目标:快速找到生产问题的可能热点,避免上下文过载。
bash
undefined

1) Start broad and semantic

1) 先进行宽泛的语义搜索

pnpm search:code "task status not updating after completion"
pnpm search:code "任务完成后状态未更新"

2) Pivot to exact symbol checks once candidates appear

2) 出现候选结果后,转向精确符号校验

pnpm search:code "TaskUpdate("

Pattern:

- Start with `search:code` for intent-level recall.
- Narrow with literal/symbol queries once candidate files are identified.
pnpm search:code "TaskUpdate("

模式:

- 先用`search:code`进行意图级召回
- 确定候选文件后,使用字面量/符号查询缩小范围

Scenario 2: Fast Exact Lookup (You Know the Identifier)

场景2:快速精确查找(已知标识符)

Goal: locate exact definitions/usages as fast as possible.
bash
undefined
目标:尽快定位精确定义/用法。
bash
undefined

Repo-wide exact literal (stable example in this repo)

仓库范围精确字面量(本仓库稳定示例)

rg -F "TaskUpdate(" -g ".cjs" -g ".js" -g "*.ts" .
rg -F "TaskUpdate(" -g ".cjs" -g ".js" -g "*.ts" .

Single-file exact lookup (fastest path)

单文件精确查找(最快路径)

rg -F "spawnSync" .claude/skills/skill-creator/scripts/create.cjs

Pattern:

- Use raw `rg -F` for exact symbol searches, especially for large files or known paths.
rg -F "spawnSync" .claude/skills/skill-creator/scripts/create.cjs

模式:

- 对于精确符号搜索,尤其是大文件或已知路径,使用原生`rg -F`

Scenario 3: Safe Refactor Prep

场景3:安全重构准备

Goal: enumerate callsites before renaming or behavior changes.
bash
undefined
目标:在重命名或行为变更前枚举所有调用点。
bash
undefined

1) Gather broad callsites

1) 收集所有相关调用点

pnpm search:code "TaskUpdate completed status workflow"
pnpm search:code "TaskUpdate completed status workflow"

2) Confirm exact callsites and edge usage

2) 确认精确调用点和边缘用法

rg -F "TaskUpdate(" -g ".cjs" -g ".js" -g "*.ts"

Pattern:

- Hybrid first to find semantic variants.
- Raw `rg` second for deterministic callsite inventory.
rg -F "TaskUpdate(" -g ".cjs" -g ".js" -g "*.ts"

模式:

- 先用混合搜索找到语义变体
- 再用原生`rg`进行确定性调用点盘点

Scenario 4: Security Audit Sweep

场景4:安全审计扫描

Goal: detect risky patterns and confirm exact high-confidence matches.
bash
undefined
目标:检测风险模式并确认高可信度的精确匹配。
bash
undefined

Concept discovery (broad)

概念发现(宽泛)

pnpm search:code "command injection shell true spawn"
pnpm search:code "command injection shell true spawn"

Exact dangerous usage checks

精确危险用法校验

rg -F "shell: true" -g ".cjs" -g ".js" rg -F "spawnSync(" -g ".cjs" -g ".js"

Pattern:

- Hybrid surfaces related risky code.
- Exact `rg` validates actionable matches for remediation.
rg -F "shell: true" -g ".cjs" -g ".js" rg -F "spawnSync(" -g ".cjs" -g ".js"

模式:

- 混合搜索找出相关风险代码
- 精确`rg`验证可修复的匹配项

Scenario 5: Architecture Onboarding (New Contributor/Agent)

场景5:架构入门(新贡献者/Agent)

Goal: understand structure before making changes.
bash
undefined
目标:在修改前理解系统结构。
bash
undefined

High-level map

高层级映射

pnpm search:structure
pnpm search:structure

Focused concept entry points

聚焦概念入口点

pnpm search:code "routing guard task lifecycle" pnpm search:code "memory scheduler session context"

Pattern:

- Use structure first, then concept search by subsystem intent.
pnpm search:code "routing guard task lifecycle" pnpm search:code "memory scheduler session context"

模式:

- 先查看结构,再按子系统意图进行概念搜索

Scenario 6: Token-Constrained Agent Workflow

场景6:Token受限的Agent工作流

Goal: minimize prompt/context bloat while maintaining retrieval quality.
bash
undefined
目标:在保持检索质量的同时最小化提示/上下文膨胀。
bash
undefined

Keep semantic off by default for speed and concise output

默认关闭语义搜索,追求速度和简洁输出

HYBRID_EMBEDDINGS=off pnpm search:code "workflow task completion guard"
HYBRID_EMBEDDINGS=off pnpm search:code "workflow task completion guard"

Enable semantic only when lexical matches are weak

仅在词汇匹配效果差时启用语义搜索

HYBRID_EMBEDDINGS=on pnpm search:code "why task completion silently fails"

Pattern:

- Default to `HYBRID_EMBEDDINGS=off`.
- Turn on embeddings only for intent-heavy or poor lexical queries.
- If `HYBRID_EMBEDDINGS=off` returns no hits, re-run immediately with `HYBRID_EMBEDDINGS=on`.
HYBRID_EMBEDDINGS=on pnpm search:code "why task completion silently fails"

模式:

- 默认使用`HYBRID_EMBEDDINGS=off`
- 仅针对意图性强或词汇匹配效果差的查询开启向量嵌入
- 如果`HYBRID_EMBEDDINGS=off`无结果,立即用`HYBRID_EMBEDDINGS=on`重新运行

Reusable Query Patterns

可复用查询模式

  • Concept query:
    "authentication flow refresh token validation"
  • Mixed query:
    "TaskUpdate completed status"
  • Exact query:
    "TaskUpdate("
    (prefer
    rg -F
    when speed is critical)
  • Structure query: use
    pnpm search:structure
    before large edits
  • File drill-down:
    pnpm search:file <path> <startLine> <endLine>
Only use raw ripgrep (below) for:
  • Advanced PCRE2 regex patterns (lookahead/lookbehind)
  • Custom file type filtering not supported by
    search:code
  • Pipeline integration with other CLI tools
<instructions> <execution_process>
  • 概念查询:
    "authentication flow refresh token validation"
  • 混合查询:
    "TaskUpdate completed status"
  • 精确查询:
    "TaskUpdate("
    (追求速度时优先用
    rg -F
  • 结构查询:在大型编辑前使用
    pnpm search:structure
  • 文件钻取:
    pnpm search:file <path> <startLine> <endLine>
仅在以下情况使用原生ripgrep:
  • 高级PCRE2正则模式(正向/反向预查)
  • search:code
    不支持的自定义文件类型过滤
  • 与其他CLI工具集成的流水线操作
<instructions> <execution_process>

Overview

概述

This skill provides access to ripgrep (rg) via the
@vscode/ripgrep
npm package, which automatically downloads the correct binary for your platform (Windows, Linux, macOS). Enhanced file type support for modern JavaScript/TypeScript projects.
Binary Source:
@vscode/ripgrep
npm package (cross-platform, auto-installed)
  • Automatically handles Windows, Linux, macOS binaries
  • No manual binary management required
Optional Config:
bin/.ripgreprc
(if present, automatically used)
本技能通过
@vscode/ripgrep
npm包提供ripgrep(rg)访问,该包会自动为你的平台(Windows、Linux、macOS)下载正确的二进制文件。增强了对现代JavaScript/TypeScript项目的文件类型支持。
二进制来源
@vscode/ripgrep
npm包(跨平台,自动安装)
  • 自动处理Windows、Linux、macOS二进制文件
  • 无需手动管理二进制文件
可选配置
bin/.ripgreprc
(如果存在,会自动被使用)

Why Use This Over Built-in Grep Tool?

为何选择本工具而非内置Grep?

FeatureRipgrep SkillBuilt-in Grep Tool
ES Module Support✅ .mjs, .cjs, .mts, .cts❌ Limited
Performance✅ 10-100x faster⚠️ Slower on large repos
Gitignore Respect✅ Automatic⚠️ Manual filtering needed
Binary File Detection✅ Automatic❌ None
PCRE2 Advanced Regexes✅ With
-P
flag
❌ Limited
Custom Config✅ .ripgreprc support❌ None
特性Ripgrep 技能内置Grep工具
ES模块支持✅ .mjs, .cjs, .mts, .cts❌ 支持有限
性能✅ 快10-100倍⚠️ 大型仓库中速度较慢
Gitignore支持✅ 自动识别⚠️ 需要手动过滤
二进制文件检测✅ 自动识别❌ 无
PCRE2高级正则✅ 带-P标志支持❌ 支持有限
自定义配置✅ 支持.ripgreprc❌ 无

Quick Start Commands

快速开始命令

Basic Search

基础搜索

bash
undefined
bash
undefined

Search for pattern in all files

在所有文件中搜索模式

node .claude/skills/ripgrep/scripts/search.mjs "pattern"
node .claude/skills/ripgrep/scripts/search.mjs "pattern"

Search specific file types

搜索特定文件类型

node .claude/skills/ripgrep/scripts/search.mjs "pattern" -tjs node .claude/skills/ripgrep/scripts/search.mjs "pattern" -tts
node .claude/skills/ripgrep/scripts/search.mjs "pattern" -tjs node .claude/skills/ripgrep/scripts/search.mjs "pattern" -tts

Case-insensitive search

不区分大小写搜索

node .claude/skills/ripgrep/scripts/search.mjs "pattern" -i
node .claude/skills/ripgrep/scripts/search.mjs "pattern" -i

Search with context lines

显示匹配上下文行

node .claude/skills/ripgrep/scripts/search.mjs "pattern" -C 3
undefined
node .claude/skills/ripgrep/scripts/search.mjs "pattern" -C 3
undefined

Quick Search Presets

快速搜索预设

bash
undefined
bash
undefined

Search JavaScript files (includes .mjs, .cjs)

搜索JavaScript文件(包含.mjs, .cjs)

node .claude/skills/ripgrep/scripts/quick-search.mjs js "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs js "pattern"

Search TypeScript files (includes .mts, .cts)

搜索TypeScript文件(包含.mts, .cts)

node .claude/skills/ripgrep/scripts/quick-search.mjs ts "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs ts "pattern"

Search all .mjs files specifically

仅搜索所有.mjs文件

node .claude/skills/ripgrep/scripts/quick-search.mjs mjs "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs mjs "pattern"

Search .claude directory for hooks

在.claude目录中搜索钩子

node .claude/skills/ripgrep/scripts/quick-search.mjs hooks "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs hooks "pattern"

Search .claude directory for skills

在.claude目录中搜索技能

node .claude/skills/ripgrep/scripts/quick-search.mjs skills "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs skills "pattern"

Search .claude directory for tools

在.claude目录中搜索工具

node .claude/skills/ripgrep/scripts/quick-search.mjs tools "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs tools "pattern"

Search .claude directory for agents

在.claude目录中搜索Agent

node .claude/skills/ripgrep/scripts/quick-search.mjs agents "pattern"
node .claude/skills/ripgrep/scripts/quick-search.mjs agents "pattern"

Search all files (no filter)

搜索所有文件(无过滤)

node .claude/skills/ripgrep/scripts/quick-search.mjs all "pattern"
undefined
node .claude/skills/ripgrep/scripts/quick-search.mjs all "pattern"
undefined

Common Patterns

常用模式

File Type Searches

文件类型搜索

bash
undefined
bash
undefined

JavaScript files (includes .js, .mjs, .cjs)

JavaScript文件(包含.js, .mjs, .cjs)

rg "function" -tjs
rg "function" -tjs

TypeScript files (includes .ts, .mts, .cts)

TypeScript文件(包含.ts, .mts, .cts)

rg "interface" -tts
rg "interface" -tts

Config files (.yaml, .yml, .toml, .ini)

配置文件(.yaml, .yml, .toml, .ini)

rg "port" -tconfig
rg "port" -tconfig

Markdown files (includes .md, .mdc)

Markdown文件(包含.md, .mdc)

rg "# Heading" -tmd
undefined
rg "# Heading" -tmd
undefined

Advanced Regex

高级正则

bash
undefined
bash
undefined

Word boundary search

单词边界搜索

rg "\bfoo\b"
rg "\bfoo\b"

Case-insensitive

不区分大小写

rg "pattern" -i
rg "pattern" -i

Smart case (case-insensitive unless uppercase present)

智能大小写(存在大写字母时区分大小写,否则不区分)

rg "pattern" -S # Already default in .ripgreprc
rg "pattern" -S # 已在.ripgreprc中设置为默认

Multiline search

多行搜索

rg "pattern.*\n.*another" -U
rg "pattern.*
.*another" -U

PCRE2 lookahead/lookbehind

PCRE2正向/反向预查

rg -P "foo(?=bar)" # Positive lookahead rg -P "foo(?!bar)" # Negative lookahead rg -P "(?<=foo)bar" # Positive lookbehind rg -P "(?<!foo)bar" # Negative lookbehind
undefined
rg -P "foo(?=bar)" # 正向预查 rg -P "foo(?!bar)" # 负向预查 rg -P "(?<=foo)bar" # 正向后查 rg -P "(?<!foo)bar" # 负向后查
undefined

Filtering

过滤

bash
undefined
bash
undefined

Exclude directories

排除目录

rg "pattern" -g "!node_modules/" rg "pattern" -g "!.git/"
rg "pattern" -g "!node_modules/" rg "pattern" -g "!.git/"

Include only specific directories

仅包含特定目录

rg "pattern" -g ".claude/**"
rg "pattern" -g ".claude/**"

Exclude specific file types

排除特定文件类型

rg "pattern" -Tjs # Exclude JavaScript
rg "pattern" -Tjs # 排除JavaScript文件

Search hidden files

搜索隐藏文件

rg "pattern" --hidden
rg "pattern" --hidden

Search binary files

搜索二进制文件

rg "pattern" -a
undefined
rg "pattern" -a
undefined

Context and Output

上下文与输出

bash
undefined
bash
undefined

Show 3 lines before and after match

显示匹配前后3行

rg "pattern" -C 3
rg "pattern" -C 3

Show 2 lines before

显示匹配前2行

rg "pattern" -B 2
rg "pattern" -B 2

Show 2 lines after

显示匹配后2行

rg "pattern" -A 2
rg "pattern" -A 2

Show only filenames with matches

仅显示包含匹配的文件名

rg "pattern" -l
rg "pattern" -l

Show count of matches per file

显示每个文件的匹配次数

rg "pattern" -c
rg "pattern" -c

Show line numbers (default in .ripgreprc)

显示行号(.ripgreprc中已设为默认)

rg "pattern" -n
undefined
rg "pattern" -n
undefined

PCRE2 Advanced Patterns

PCRE2高级模式

Enable PCRE2 mode with
-P
for advanced features:
使用-P标志启用PCRE2模式以使用高级特性:

Lookahead and Lookbehind

预查与后查

bash
undefined
bash
undefined

Find "error" only when followed by "critical"

仅查找后面跟有"critical"的"error"

rg -P "error(?=.*critical)"
rg -P "error(?=.*critical)"

Find "test" not followed by ".skip"

查找后面不跟有".skip"的"test"

rg -P "test(?!.skip)"
rg -P "test(?!\.skip)"

Find words starting with capital after "Dr. "

查找"Dr. "后面的大写开头单词

rg -P "(?<=Dr. )[A-Z]\w+"
rg -P "(?<=Dr\. )[A-Z]\w+"

Find function calls not preceded by "await "

查找前面没有"await "的函数调用

rg -P "(?<!await )\b\w+("
undefined
rg -P "(?<!await )\b\w+\("
undefined

Backreferences

反向引用

bash
undefined
bash
undefined

Find repeated words

查找重复单词

rg -P "\b(\w+)\s+\1\b"
rg -P "\b(\w+)\s+\1\b"

Find matching HTML tags

查找匹配的HTML标签

rg -P "<(\w+)>.*?</\1>"
undefined
rg -P "<(\w+)>.*?</\1>"
undefined

Conditionals

条件匹配

bash
undefined
bash
undefined

Match IPv4 or IPv6

匹配IPv4或IPv6

rg -P "(\d{1,3}.){3}\d{1,3}|([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}"
undefined
rg -P "(\d{1,3}\.){3}\d{1,3}|([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}"
undefined

Integration with Other Tools

与其他工具集成

With fzf (Interactive Search)

与fzf集成(交互式搜索)

bash
undefined
bash
undefined

Search and interactively select file

搜索并交互式选择文件

rg --files | fzf
rg --files | fzf

Search pattern and open in editor

搜索模式并在编辑器中打开

rg "pattern" -l | fzf | xargs code
undefined
rg "pattern" -l | fzf | xargs code
undefined

With vim

与Vim集成

bash
undefined
bash
undefined

Set ripgrep as grep program in .vimrc

在.vimrc中设置ripgrep为grep程序

set grepprg=rg\ --vimgrep\ --smart-case\ --follow
undefined
set grepprg=rg\ --vimgrep\ --smart-case\ --follow
undefined

Pipeline with Other Commands

与其他命令流水线集成

bash
undefined
bash
undefined

Search and count unique matches

搜索并统计唯一匹配项

rg "pattern" -o | sort | uniq -c
rg "pattern" -o | sort | uniq -c

Search and replace preview

搜索并替换预览

rg "old" -l | xargs sed -i 's/old/new/g'
undefined
rg "old" -l | xargs sed -i 's/old/new/g'
undefined

Performance Optimization

性能优化

Tips for Large Codebases

大型代码库技巧

  1. Use file type filters:
    -tjs
    is faster than searching all files
  2. Exclude large directories:
    -g "!node_modules/**"
  3. Use literal strings when possible:
    -F "literal"
    (disables regex)
  4. Enable parallel search: Ripgrep uses all cores by default
  5. Use .gitignore: Ripgrep respects .gitignore automatically
  1. 使用文件类型过滤器
    -tjs
    比搜索所有文件更快
  2. 排除大型目录
    -g "!node_modules/**"
  3. 尽可能使用字面量字符串
    -F "literal"
    (禁用正则)
  4. 启用并行搜索:Ripgrep默认使用所有核心
  5. 使用.gitignore:Ripgrep会自动遵循.gitignore规则

Benchmarks

基准测试

Ripgrep is typically:
  • 10-100x faster than grep
  • 5-10x faster than ag (The Silver Searcher)
  • 3-5x faster than git grep
Ripgrep通常:
  • 比grep快10-100倍
  • 比ag(The Silver Searcher)快5-10倍
  • 比git grep快3-5倍

Custom Configuration

自定义配置

The optional
.ripgreprc
file at
bin/.ripgreprc
(if present) contains:
undefined
可选的
.ripgreprc
文件位于
bin/.ripgreprc
(如果存在),包含:
undefined

Extended file types

扩展文件类型

--type-add=js:.mjs --type-add=js:.cjs --type-add=ts:.mts --type-add=ts:.cts --type-add=md:.mdc --type-add=config:.yaml --type-add=config:.yml --type-add=config:.toml --type-add=config:*.ini
--type-add=js:.mjs --type-add=js:.cjs --type-add=ts:.mts --type-add=ts:.cts --type-add=md:.mdc --type-add=config:.yaml --type-add=config:.yml --type-add=config:.toml --type-add=config:*.ini

Default options

默认选项

--smart-case --follow --line-number
undefined
--smart-case --follow --line-number
undefined

Framework-Specific Patterns

框架特定模式

Searching .claude Directory

搜索.claude目录

bash
undefined
bash
undefined

Find all hooks

查找所有钩子

rg "PreToolUse|PostToolUse" .claude/hooks/
rg "PreToolUse\|PostToolUse" .claude/hooks/

Find all skills

查找所有技能

rg "^# " .claude/skills/ -tmd
rg "^# " .claude/skills/ -tmd

Find agent definitions

查找Agent定义

rg "^name:" .claude/agents/ -tmd
rg "^name:" .claude/agents/ -tmd

Find workflow steps

查找工作流步骤

rg "^### Step" .claude/workflows/ -tmd
undefined
rg "^### Step" .claude/workflows/ -tmd
undefined

Common Agent Studio Searches

Agent Studio常用搜索

bash
undefined
bash
undefined

Find all TaskUpdate calls

查找所有TaskUpdate调用

rg "TaskUpdate(" -tjs -tts
rg "TaskUpdate\(" -tjs -tts

Find all skill invocations

查找所有技能调用

rg "Skill({" -tjs -tts
rg "Skill\(\{" -tjs -tts

Find all memory protocol sections

查找所有内存协议章节

rg "## Memory Protocol" -tmd
rg "## Memory Protocol" -tmd

Find all BLOCKING enforcement comments

查找所有BLOCKING强制注释

rg "BLOCKING|CRITICAL" -C 2

</execution_process>

<best_practices>

1. **Use file type filters** (`-tjs`, `-tts`) for faster searches
2. **Respect .gitignore** patterns (automatic by default)
3. **Use smart-case** for case-insensitive search (default in config)
4. **Enable PCRE2** (`-P`) only when advanced features needed
5. **Exclude large directories** with `-g "!node_modules/**"`
6. **Use literal search** (`-F`) when pattern has no regex
7. **Binary automatically managed** via `@vscode/ripgrep` npm package
8. **Use quick-search presets** for common .claude directory searches
   </best_practices>
   </instructions>

<examples>
<usage_example>
**Search for all TaskUpdate calls in the project:**

```bash
node .claude/skills/ripgrep/scripts/search.mjs "TaskUpdate" -tjs -tts
Find all security-related hooks:
bash
node .claude/skills/ripgrep/scripts/quick-search.mjs hooks "security|SECURITY" -i
Search for function definitions with PCRE2:
bash
node .claude/skills/ripgrep/scripts/search.mjs -P "^function\s+\w+\(" -tjs
</usage_example> </examples>
rg "BLOCKING|CRITICAL" -C 2

</execution_process>

<best_practices>

1. **使用文件类型过滤器**(`-tjs`, `-tts`)以加快搜索速度
2. **遵循.gitignore**规则(默认自动生效)
3. **使用智能大小写**进行不区分大小写搜索(配置中已设为默认)
4. **仅在需要高级特性时启用PCRE2**(`-P`)
5. **用`-g "!node_modules/**"`排除大型目录**
6. **当模式无正则时使用字面量搜索**(`-F`)
7. **二进制文件由`@vscode/ripgrep` npm包自动管理**
8. **对于.claude目录的常见搜索,使用快速搜索预设**
   </best_practices>
   </instructions>

<examples>
<usage_example>
**搜索项目中所有TaskUpdate调用:**

```bash
node .claude/skills/ripgrep/scripts/search.mjs "TaskUpdate" -tjs -tts
查找所有安全相关钩子:
bash
node .claude/skills/ripgrep/scripts/quick-search.mjs hooks "security|SECURITY" -i
使用PCRE2搜索函数定义:
bash
node .claude/skills/ripgrep/scripts/search.mjs -P "^function\\s+\\w+\\(" -tjs
</usage_example> </examples>

Binary Management

二进制管理

The search scripts use
@vscode/ripgrep
npm package which automatically:
  • Detects your platform (Windows, Linux, macOS)
  • Downloads the correct binary during
    pnpm install
  • Handles all architecture variants (x64, ARM64, etc.)
No manual binary management required - the npm package handles everything automatically.
搜索脚本使用
@vscode/ripgrep
npm包,该包会自动:
  • 检测你的平台(Windows、Linux、macOS)
  • pnpm install
    时下载正确的二进制文件
  • 处理所有架构变体(x64、ARM64等)
无需手动管理二进制文件 - npm包会自动处理所有事宜。

Related Skills

相关技能

  • grep
    - Built-in Claude Code grep (simpler, less features)
  • glob
    - File pattern matching
  • grep
    - 内置Claude Code grep(更简单,功能更少)
  • glob
    - 文件模式匹配

Memory Protocol (MANDATORY)

内存协议(强制要求)

Before starting: Read
.claude/context/memory/learnings.md
After completing:
  • New pattern ->
    .claude/context/memory/learnings.md
  • Issue found ->
    .claude/context/memory/issues.md
  • Decision made ->
    .claude/context/memory/decisions.md
ASSUME INTERRUPTION: If it's not in memory, it didn't happen.
开始前: 阅读
.claude/context/memory/learnings.md
完成后:
  • 新模式 ->
    .claude/context/memory/learnings.md
  • 发现问题 ->
    .claude/context/memory/issues.md
  • 做出决策 ->
    .claude/context/memory/decisions.md
假设会被中断:如果未记录到内存中,就视为未发生。 ",