Agent Skills › langwatch/langwatch › code-search

code-search

GitHub

提供仓库内代码搜索的最佳实践,指导根据场景选择 ripgrep、sgrep 或 gopls 等工具,涵盖字面量匹配、语义搜索及精确引用查找。

.claude/skills/code-search/SKILL.md langwatch/langwatch

Trigger Scenarios

需要定位代码位置 执行语义搜索 查询函数调用者

Install

npx skills add langwatch/langwatch --skill code-search -g -y
More Options

Non-standard path

npx skills add https://github.com/langwatch/langwatch/tree/main/.claude/skills/code-search -g -y

Use without installing

npx skills use langwatch/langwatch@code-search

指定 Agent (Claude Code)

npx skills add langwatch/langwatch --skill code-search -a claude-code -g -y

安装 repo 全部 skill

npx skills add langwatch/langwatch --all -g -y

预览 repo 内 skill

npx skills add langwatch/langwatch --list

SKILL.md

Frontmatter
{
    "name": "code-search",
    "description": "Pick the right tool to find code in this repository: ripgrep when you know the word, sgrep (search by meaning) when an index is ready, ripgrep while an index builds, gopls and tslsp for exact references. Use when someone says 'find where', 'search the code', 'which file handles', 'grep for', 'sgrep', 'semantic search', 'search by meaning', 'index the repo', 'is the index ready', 'code search', or before sweeping an unfamiliar area of the tree.",
    "argument-hint": "[status <dir> | query <dir> \"<question>\" | index <dir>]",
    "user-invocable": true
}

Code search

Measured on this repository, 2026-10-14 (busy host, so times are rough):

Tool Setup Per search Finds the right code
rg none 0.06-0.8 s given the word, in non-ignored files
git grep none 0.07-2.4 s same; tracked files only
grep -r none 18-34 s same, but walks every node_modules
sgrep, no index n/a won't run n/a
sgrep, indexed modules/ 26 min, ~500 MB 0.1-0.3 s about half, by meaning
gopls references none 4-15 s exact
tslsp references none times out not usable for lookups here

Which tool

know the identifier?            ── yes ──▶ rg -n -w <identifier> <dir>
know a literal string or code?  ── yes ──▶ rg -n -F '<string>' <dir>
        │ no
        ▼
sgrep.sh status <dir>  ── ready ──▶ sgrep.sh query <dir> "<question>"
        │                              then confirm with rg on the names it found
        │ building / none
        ▼
guess two or three likely words ──▶ rg -n -i -e a -e b <dir>
need every caller of a Go symbol, exactly? ──▶ gopls references file.go:line:col
  • ripgrep first. It needs nothing and never misses a literal match in the files it searches (everything not excluded by .gitignore or .rgignore; see below). Never grep -r. Give rg an explicit path: with no path and no terminal it reads stdin and hangs.
  • sgrep only when the index is ready. A query against a missing or half-built index is wrong or empty, so the helper refuses (exit 3) and you use rg. sgrep answers roughly half the "where is X done" questions; treat its hits as leads and confirm them with rg.
  • While an index builds, use rg. Don't wait for it.
  • Exact references: gopls references for Go. For TypeScript renames and moves, tslsp is still the tool (rename, rename_file); its read commands time out on this monorepo.
  • sgrep skips tests, generated and vendored files itself; pass -t to include tests.
  • rg skips the generated files listed in the root .rgignore (lockfiles, snapshots, generated clients and READMEs). Searching for something that only lives there, such as a handled-error code in codes.generated.ts? Add --no-ignore-dot. After adding a linguist-generated line to .gitattributes, regenerate .rgignore with the command in its header.

The helper

.claude/skills/code-search/sgrep.sh wraps sgrep so you don't handle its embedding server:

Command Does
sgrep.sh status modules/trace ready: <dir> (exit 0), or building / none (exit 3)
sgrep.sh query modules/trace "where spans are written" -n 5 search the index covering that path; exit 3 = use rg
sgrep.sh index modules/trace build an index in the background; prints the log path
sgrep.sh stop stop the embedding server it started

Extra arguments after the question go to sgrep (-n 5, -t, --profile fast, --json). Index one area (modules/<name>, services/<name>), not the root: the whole tree takes 2-3 hours. A Go service of ~300 files takes under two minutes.

The index lives in ~/.sgrep (outside the checkout), so git never sees it. An index belongs to one absolute path: a worktree does not share the main checkout's, so status there says none. Indexes stay until removed (modules/ is about 500 MB); sgrep.sh stop stops the server only. sgrep list shows them; cd <dir> && sgrep clear deletes one.

Install

brew install xiaoconstantine/tap/sgrep (after brew trust --formula xiaoconstantine/tap/sgrep). If brew refuses over outdated Command Line Tools, download the release tarball named in the formula, check its sha256 against the formula, and put the binary at .bin/sgrep/sgrep. Needs llama-server (brew install llama.cpp); the helper downloads the model on first index.

Version History

  • c0c14dc Current 2026-10-19 19:32

Same Skill Collection

.claude/skills/analyticssim/SKILL.md
.claude/skills/browser-pair/SKILL.md
.claude/skills/browser-test/SKILL.md
.claude/skills/chakra-ui-builder/SKILL.md
.claude/skills/chakra-ui-refactor/SKILL.md
.claude/skills/code-review/SKILL.md
.claude/skills/feature-map/SKILL.md
.claude/skills/githubsim/SKILL.md
.claude/skills/haven-auth/SKILL.md
.claude/skills/haven-db/SKILL.md
.claude/skills/haven-orb/SKILL.md
.claude/skills/haven-play/SKILL.md
.claude/skills/haven-seed/SKILL.md
.claude/skills/haven-setup/SKILL.md
.claude/skills/idpsim/SKILL.md
.claude/skills/lambdasim/SKILL.md
.claude/skills/langwatch-kanban/SKILL.md
.claude/skills/llmsim/SKILL.md
.claude/skills/mailsim/SKILL.md
.claude/skills/module/SKILL.md
.claude/skills/outboundsim/SKILL.md
.claude/skills/ownership/SKILL.md
.claude/skills/repo-tree/SKILL.md
.claude/skills/storagesim/SKILL.md
.claude/skills/voicesim/SKILL.md
plugins/langwatch/skills/langwatch/SKILL.md
services/langy-agent/skills/github/SKILL.md
skills/_compiled/native/agent-best-practices/SKILL.md
skills/_compiled/native/agent-performance/SKILL.md
skills/_compiled/native/automations/SKILL.md
skills/_compiled/native/code-changes/SKILL.md
skills/_compiled/native/context-sweet-spot/SKILL.md
skills/_compiled/native/daily-insights/SKILL.md
skills/_compiled/native/dashboard-widgets/SKILL.md
skills/_compiled/native/datasets/SKILL.md
skills/_compiled/native/debug-instrumentation/SKILL.md
skills/_compiled/native/debug-with-langwatch/SKILL.md
skills/_compiled/native/drive-the-ui/SKILL.md
skills/_compiled/native/eval-triage/SKILL.md
skills/_compiled/native/evaluate-multimodal/SKILL.md
skills/_compiled/native/evaluations/SKILL.md
skills/_compiled/native/experiments/SKILL.md
skills/_compiled/native/find-traces/SKILL.md
skills/_compiled/native/generate-rag-dataset/SKILL.md
skills/_compiled/native/github/SKILL.md
skills/_compiled/native/guided-onboarding/SKILL.md
skills/_compiled/native/level-up/SKILL.md
skills/_compiled/native/lwql-charts/SKILL.md
skills/_compiled/native/online-evaluations/SKILL.md

Metadata

Files
0
Version
c0c14dc
Hash
0307c23a
Indexed
2026-10-19 19:32

Home - Wiki
Copyright © 2011-2026 iteam. Current version is 2.155.2. UTC+08:00, 2026-10-20 15:12
浙ICP备14020137号-1