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





首页
