github-code-search
jaredpalmer/claude-plugins
使用 grep.app 在數百萬個 GitHub 儲存庫中搜尋程式碼。當您需要尋找程式碼模式、實作方式、範例,或了解公開程式碼庫中的功能是如何建構時,即可使用此工具。(專案)
...展開全部關於「github-code-search」
「github-code-search」技能讓使用者能透過 grep.app 服務,在數百萬個公開的 GitHub 儲存庫中進行搜尋。此技能提供了一種強大且高效的方式,讓使用者能在龐大的開源程式碼庫中尋找程式碼模式、實作方式及範例。 透過利用 grep.app 的 MCP 伺服器,使用者能搜尋特定的程式碼模式,例如查閱其他專案如何實作特定功能,或是不同儲存庫中如何使用各種函式庫與 API。無論是為了學習、分析現有實作,還是蒐集特定程式碼模式的範例,此技能皆提供了一種簡便且高效的 GitHub 程式碼查詢方法。
此技能的主要功能包括能夠執行 TypeScript 程式碼,以在本地端進行搜尋、篩選及處理結果,從而提升搜尋效率並減少代幣消耗。內建的 TypeScript 搜尋腳本提供了一個易於使用的命令列介面,可透過語言篩選、限制結果數量以及使用正規表達式等各種選項來執行搜尋。 使用者亦可透過編寫內嵌 TypeScript 程式碼來進行自訂篩選與處理,從而執行自訂搜尋。此外,此技能還提供直接 API,可透過 curl 等簡易工具進行快速搜尋,無論是進階或基礎使用者都能靈活運用。
此技能非常適合開發者、研究人員以及任何參與分析開源專案的人士。對於想要尋找程式碼實作或範例、分析編碼模式,或研究最佳實踐的人來說,它再適合不過了。 對於尋求可重複使用的程式碼片段、探索開源專案中功能建構方式,或深入了解公開儲存庫中函式庫與 API 使用方式的開發者而言,此技能尤為實用。
常見問題
如何使用這項技能搜尋特定的程式碼片段?
您可以使用內建的 TypeScript 搜尋腳本來搜尋特定的程式碼片段。 請輸入您想要的搜尋查詢,並可選擇加入語言或儲存庫等篩選條件來執行該腳本。例如,您可以使用以下指令在 TypeScript 檔案中搜尋「use cache」:'bun run skills/github-code-search/scripts/search.ts "use cache" --lang=TypeScript'。
我可以搜尋特定儲存庫內的內容嗎?
是的,您可以透過 '--repo' 參數,後接擁有者或儲存庫名稱,來在特定儲存庫內進行搜尋。 例如,若要在「vercel/next.js」儲存庫內搜尋,請使用以下指令:'bun run skills/ github-code-search /scripts/search.ts "cacheLife" --repo=vercel/next.js'。
使用此技能有哪些設定要求?
要使用此技能,您需要先設定好 grep.app MCP 伺服器。您可以透過以下指令新增伺服器:「claude mcp add --transport http grep https://mcp.grep.app」。執行「/mcp」以驗證設定,此時應會列出「grep」。
內嵌 TypeScript 選項如何運作?
內嵌 TypeScript 選項可進行自訂搜尋與篩選。您可以編寫 TypeScript 程式碼來呼叫 grep.app API,並在本地端處理結果,以根據需求篩選或轉換資料。這為進階使用情境提供了更大的靈活性,例如結合多個查詢結果,或依儲存庫名稱進行篩選。
GitHub Code Search via grep.app
Overview
This skill enables searching across millions of public GitHub repositories using the grep.app service. It uses a code mode pattern where you write and execute TypeScript code to query the grep.app MCP server, filter results locally, and return only relevant findings.
When to Use
- Find implementations of specific patterns (e.g., "how do other projects implement OAuth2?")
- Search for usage examples of APIs or libraries
- Analyze architectural patterns across codebases
- Find code snippets matching regex patterns
- Research best practices by examining popular repositories
Setup Requirements
The grep.app MCP server must be configured. Add it with:
claude mcp add --transport http grep https://mcp.grep.app
Verify with /mcp - you should see grep listed.
Code Mode Pattern
Instead of calling MCP tools directly (which loads all tool definitions into context), this skill uses code execution for efficiency:
- Write TypeScript code that calls the grep MCP server
- Execute the code via Bash with
bunornpx tsx - Filter and process results in the execution environment
- Return only relevant findings to minimize token usage
This approach reduces token usage by 90%+ compared to direct tool calls with large result sets.
Implementation
Option 1: Use the bundled search script (recommended)
A ready-to-use TypeScript search script is included:
bun run skills/github-code-search/scripts/search.ts "query" [--lang=Language] [--repo=owner/repo] [--limit=N] [--regexp]
Examples:
# Search for "use cache" in TypeScript filesbun run skills/github-code-search/scripts/search.ts "use cache" --lang=TypeScript --limit=5# Search in a specific repositorybun run skills/github-code-search/scripts/search.ts "cacheLife" --repo=vercel/next.js --limit=10# Use regex patternsbun run skills/github-code-search/scripts/search.ts "async.*await" --regexp --lang=TypeScript
Output format (JSON):
{ "query": "cacheLife", "options": { "language": "TypeScript", "limit": 3 }, "total": 2931, "results": [ { "repo": "vercel/next.js", "path": "packages/next/src/server/use-cache/cache-life.ts", "url": "https://github.com/vercel/next.js/blob/canary/packages/next/src/server/use-cache/cache-life.ts", "matches": [{ "lineNumber": 5, "content": "export type »CacheLife« = {" }] } ]}The » and « markers indicate where the search term was matched.
Option 2: Inline TypeScript (for custom processing)
For more complex searches with custom filtering, write inline TypeScript:
// Execute with: bun -e "..."const response = await fetch( 'https://grep.app/api/search?q=useOptimistic&l=TypeScript')const data = await response.json()// Process results locally - this is the efficiency gain!const filtered = data.hits.hits .filter((hit: any) => hit.repo.includes('react')) .slice(0, 5) .map((hit: any) => ({ repo: hit.repo, path: hit.path }))console.log(JSON.stringify(filtered, null, 2))
Quick Search (Direct API)
For simple searches, use curl directly:
curl -s "https://grep.app/api/search?q=useOptimistic+hook&l=TypeScript" | jq '.hits.hits[:5] | .[] | {repo: .repo.raw, path: .path.raw}'
Parameters
| Parameter | Description | Example |
|---|---|---|
q | Search query (required). Supports regex with regexp:true | "use cache", async.*await |
l | Language filter | TypeScript, Python, Go |
r | Repository filter | vercel/next.js, facebook/react |
regexp | Enable regex mode | true |
Example Queries
Find "use cache" implementations in Next.js projects
curl -s "https://grep.app/api/search?q=%22use%20cache%22&l=TypeScript" | jq '.hits.hits[:10] | .[] | {repo: .repo.raw, path: .path.raw}'
Search for error handling patterns
curl -s "https://grep.app/api/search?q=catch.*error.*log®exp=true&l=TypeScript" | jq '.hits.total'
Find implementations in a specific repo
curl -s "https://grep.app/api/search?q=cacheLife&r=vercel/next.js" | jq '.hits.hits[] | {path: .path.raw, lines: .content.lines}'
Best Practices
- Start broad, then narrow: Begin with a general query, then add language/repo filters
- Use regex for patterns: Enable
regexp=truefor complex pattern matching - Limit results locally: Process and filter in code before returning to save tokens
- Cache common searches: Store results for frequently-used queries
- Respect rate limits: The grep.app API has rate limits; batch queries when possible
Integration with MCP Tools
If the grep MCP server is configured, you can also use it via MCP tools:
// Via MCP (if mcp__grep__search is available)mcp__grep__search({ query: 'authentication middleware', language: 'TypeScript', useRegexp: false,})
However, the code mode approach (curl + jq or TypeScript script) is preferred for:
- Large result sets that need filtering
- Complex post-processing logic
- Chaining multiple searches
- Minimizing context window usage
Troubleshooting
- No results: Try broadening the query or removing filters
- Rate limited: Wait a few seconds and retry, or use the MCP server which may have higher limits
- Timeout: Large queries may timeout; add more specific filters





首頁
