npx skills add https://github.com/otrebu/agents --skill gh-code-search通过智能的多重搜索编排,从 GitHub 获取真实世界的代码示例。
必需项:
gh auth login --web)验证:
gh auth status # 应显示已认证
cd plugins/knowledge-work/skills/gh-code-search
pnpm install # 仅首次运行时需要
pnpm search "你的查询语句"
当用户请求以下内容时,调用此技能:
需要细致多重搜索的示例:
useState/useEffect(导入)、(定义)、(箭头函数)的查询广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
function useconst use =(req, res, next) =>(签名)、app.use(注册)、function(err,(错误处理程序)的查询useMachine、createMachine、interpret(实际函数名,而非"状态机")的查询.yml 工作流文件 + actions/setup-node + tsc 或 pnpm build(实际命令)的查询职责划分:
该脚本是一个单查询工具。 Claude 负责编排多次调用。
Claude 执行一个多阶段工作流:
分析用户请求以确定:
考虑细微差别,生成 3-5 个有针对性的查询:
示例 1:"查找 React hooks"
useState useEffect language:typescript extension:tsx(匹配组件中的导入语句、hook 使用)function use language:typescript extension:ts(匹配 hook 定义,如 function useFetch())const use = language:typescript(匹配箭头函数 hooks,如 const useAuth = () =>)示例 2:"Express 错误处理"
(req, res, next) => language:javascript(匹配中间件函数签名)app.use express(匹配 Express 中间件注册)function(err, req, res, next) language:javascript(匹配具有 4 个参数的错误处理程序签名)示例 3:"React 中的 XState 状态机"
useMachine language:typescript extension:tsx(匹配 React hook 使用,如 const [state, send] = useMachine(machine))createMachine language:typescript(匹配状态机定义和导入)interpret xstate language:typescript(匹配服务创建,如 const service = interpret(machine))每个查询的理由:
检查点: 在继续之前,验证是否生成了 3-5 个查询
对于每个查询(按顺序):
cd plugins/knowledge-work/skills/gh-code-search
pnpm search "查询文本"
每次搜索后:
跟踪哪些查询成功 - 在总结中注意哪些策略有效
提前停止: 如果前 2-3 个查询产生了 30+ 个高质量结果,则剩余查询可选
合并所有搜索中的所有代码文件:
repository.full_name + file_path 去重
* 如果存在重复项,保留得分最高的版本
* 注意哪些查询找到了相同的文件(表明强相关性)结果: 包含 GitHub URL 的 15-30 个唯一、高质量代码文件的统一列表
提取所有代码文件中的事实模式:
导入分析:
架构模式:
代码结构:
语言分布:
不要发表评论 - 提取事实,而非观点。分析在步骤 5 中进行。
输出格式(精确结构):
# GitHub 代码搜索:[用户查询主题]
## 执行的搜索策略
运行了 [N] 个有针对性的查询:
1. `查询文本` - [简要理由] → [X 个结果]
2. `查询文本` - [简要理由] → [Y 个结果]
3. ...
**分析的唯一文件总数:** [N]
---
## 模式分析
### 常见导入
- `库名称` - 在 [N/总数] 个文件中使用
- `另一个库` - 在 [M/总数] 个文件中使用
### 架构风格
- **函数式编程** - [N] 个文件使用纯函数、不可变模式
- **面向对象** - [M] 个文件使用类、继承
- **混合** - [K] 个文件混合使用两种方法
### 实现模式
- **模式 1 名称**:[描述及普遍性]
- **模式 2 名称**:[描述及普遍性]
---
## 发现的方法
### 方法 1:[名称]
**仓库:** [repo1], [repo2]
**特点:**
- [关键特征 1]
- [关键特征 2]
**示例:** [repo/文件路径:行号](github_url)
```语言
[相关代码片段 - 不仅仅是前 40 行]
[类似结构]
| 方法 | 优点 | 缺点 | 最适合 |
|---|---|---|---|
| 方法 1 | [优点] | [缺点] | [用例] |
| 方法 2 | [优点] | [缺点] | [用例] |
针对您的用例([根据用户上下文推断]):
来源: repo/文件路径:行范围
[特定的相关代码 - 导入、关键函数,而非任意截断]
为何重要: [简要解释]
来源: repo/文件路径:行范围
[特定的相关代码]
为何重要: [简要解释]
重要:包含所有搜索中找到的所有重要文件的 GitHub URL。
列出每个分析过的唯一文件(15-30 个文件),按仓库分组:
格式: 直接使用 GitHub blob URL,并在相关处包含行号(例如,https://github.com/owner/repo/blob/main/path/file.ts#L10-L50)
**总结特点:**
- **基于事实** - 基于提取的数据,而非假设
- **可操作** - 带有推理的清晰建议
- **情境化** - 引用带有行号的特定代码位置
- **平衡** - 展示权衡,而不仅仅是"最佳实践"
- **全面** - 涵盖模式、方法、权衡、建议
- **可访问** - 包含所有重要文件的 GitHub URL,以便用户可以探索完整源代码
---
### 步骤 6:将结果保存到文件
**生成综合总结后,持久化保存以供将来参考:**
1. **生成时间戳:**
- 调用 `timestamp` 技能以获取确定性的 YYYYMMDDHHMMSS 格式
- 示例:`20250110143052`
2. **清理查询以用于文件名:**
- 将用户的原始查询转换为 kebab-case 短横线分隔格式
- 规则:小写,空格 → 连字符,移除特殊字符,最多 50 个字符
- 示例:"React hooks useState" → "react-hooks-usestate"
3. **构建文件路径:**
- 目录:`docs/research/github/`
- 格式:`<时间戳>-<清理后的查询>.md`
- 完整路径:`docs/research/github/20250110143052-react-hooks-usestate.md`
4. **使用 Write 工具保存:**
- 内容:来自步骤 5 的完整综合总结
- 确保跨会话持久化
- 用户可以引用过去的研究
5. **记录保存位置:**
- 通知用户文件保存的位置
- 示例:"研究已保存至 docs/research/github/20250110143052-react-hooks-usestate.md"
**为何保存:**
- 综合总结代表了大量的分析工作(30-150 秒的 API 调用)
- 用户可能希望稍后参考模式/权衡
- 构建可搜索的 GitHub 研究知识库
- 避免为相同主题重新运行昂贵的查询
---
## 错误处理
**常见问题:**
- **身份验证错误:** 提示用户运行 `gh auth login --web`
- **速率限制:** 显示剩余配额、重置时间。如果在多重搜索期间达到限制,则优雅停止并返回部分结果
- **网络故障:** 继续处理部分结果,记录哪些查询失败
- **查询无结果:** 在总结中注明,调整后续查询以更宽泛
- **所有查询返回相同文件:** 注明多样性低,建议更宽泛的初始查询
**优雅降级:** 部分结果是可以接受的。基于可用数据完成总结。
---
## 限制
- GitHub API 速率限制:认证后 5,000 次请求/小时(多重搜索使用更多配额)
- 每次工具调用仅获取前 10 个结果
- 跳过 >100KB 的文件
- 顺序执行比单次查询耗时更长(每次查询 10-30 秒)
- 提供事实数据,而非结论(Claude 解释模式)
- 去重假设路径完全匹配(重命名的文件被视为唯一)
---
## 典型执行时间
**每次查询:** 10-30 秒,取决于:
- 结果数量(最多 100 个)
- 文件大小
- 网络延迟
- API 速率限制
**完整工作流(3-5 个查询):** 30-150 秒
**优化:** 如果前几个查询产生了足够的结果,则跳过剩余查询
---
## 集成说明
**示例:用户询问"查找执行 GitHub 搜索的 Claude Code skills"**
```javascript
// 1. Claude 分析:Skills 使用带有 frontmatter 的 SKILL.md,可能在 .claude/skills/ 目录中
// 2. Claude 生成查询:
// - "filename:SKILL.md github search"(匹配包含 "github search" 文本的 SKILL.md 文件)
// - "octokit.rest.search language:typescript"(匹配实际的 Octokit API 使用)
// - "gh api language:typescript path:skills"(匹配 skills 中的 gh CLI 使用)
// 3. Claude 顺序执行:
cd plugins/knowledge-work/skills/gh-code-search
pnpm search "filename:SKILL.md github search"
// [分析结果]
pnpm search "octokit.rest.search language:typescript"
// [分析结果]
pnpm search "gh api language:typescript path:skills"
// 4. Claude 聚合、去重、分析模式
// 5. Claude 生成包含权衡和建议的综合总结
使用多样化的查询验证工作流:
检查质量:
每周安装数
75
仓库
GitHub 星标数
3
首次出现
2026年1月24日
安全审计
安装于
opencode68
cursor65
codex62
gemini-cli61
github-copilot55
kimi-cli51
Fetch real-world code examples from GitHub through intelligent multi-search orchestration.
Required:
gh auth login --web)Validation:
gh auth status # Should show authenticated
cd plugins/knowledge-work/skills/gh-code-search
pnpm install # First time only
pnpm search "your query here"
Invoke this skill when user requests:
Examples requiring nuanced multi-search:
useState/useEffect (imports), function use (definitions), const use = (arrow functions)(req, res, next) => (signatures), app.use (registration), function(err, (error handlers)useMachine, createMachine, interpret (actual function names, not "state machine").yml workflow files + actions/setup-node + tsc or pnpm build (actual commands)Division of responsibilities:
The script is a single-query tool. Claude orchestrates multiple invocations.
Claude executes a multi-phase workflow:
Query Strategy Generation: Craft 3-5 targeted search queries considering:
Sequential Search Execution: Run tool multiple times, adapting queries based on intermediate results
Result Aggregation: Combine all code files, deduplicate by repo+path, preserve GitHub URLs
Pattern Analysis: Extract common imports, architectural styles, implementation patterns
Comprehensive Summary: Synthesize findings with trade-offs, recommendations, key code highlights, and GitHub URLs for ALL meaningful files
Analyze user request to determine:
Generate 3-5 targeted queries considering nuances:
Example 1: "Find React hooks"
useState useEffect language:typescript extension:tsx (matches import statements, hook usage in components)function use language:typescript extension:ts (matches hook definitions like function useFetch())const use = language:typescript (matches arrow function hooks like const useAuth = () =>)Example 2: "Express error handling"
(req, res, next) => language:javascript (matches middleware function signatures)app.use express (matches Express middleware registration)function(err, req, res, next) language:javascript (matches error handler signatures with 4 params)Example 3: "XState state machines in React"
useMachine language:typescript extension:tsx (matches React hook usage like const [state, send] = useMachine(machine))createMachine language:typescript (matches machine definitions and imports)interpret xstate language:typescript (matches service creation like const service = interpret(machine))Rationale for each query:
CHECKPOINT: Verify 3-5 queries generated before proceeding
For each query (in order):
cd plugins/knowledge-work/skills/gh-code-search
pnpm search "query text here"
After each search:
Track which queries succeed - Note for summary which strategies were effective
Early stopping: If first 2-3 queries yield 30+ high-quality results, remaining queries optional
Combine all code files from all searches:
repository.full_name + file_path
Result: Unified list of 15-30 unique, high-quality code files with GitHub URLs
Extract factual patterns across all code files:
Import Analysis:
Architectural Patterns:
Code Structure:
Language Distribution:
DO NOT editorialize - Extract facts, not opinions. Analysis comes in Step 5.
Output format (exact structure):
# GitHub Code Search: [User Query Topic]
## Search Strategy Executed
Ran [N] targeted queries:
1. `query text` - [brief rationale] → [X results]
2. `query text` - [brief rationale] → [Y results]
3. ...
**Total unique files analyzed:** [N]
---
## Pattern Analysis
### Common Imports
- `library-name` - Used in [N/total] files
- `another-lib` - Used in [M/total] files
### Architectural Styles
- **Functional Programming** - [N] files use pure functions, immutable patterns
- **Object-Oriented** - [M] files use classes, inheritance
- **Hybrid** - [K] files mix both approaches
### Implementation Patterns
- **Pattern 1 Name**: [Description with prevalence]
- **Pattern 2 Name**: [Description with prevalence]
---
## Approaches Found
### Approach 1: [Name]
**Repos:** [repo1], [repo2]
**Characteristics:**
- [Key trait 1]
- [Key trait 2]
**Example:** [repo/file_path:line_number](github_url)
```language
[relevant code snippet - NOT just first 40 lines]
[Similar structure]
| Approach | Pros | Cons | Best For |
|---|---|---|---|
| Approach 1 | [pros] | [cons] | [use case] |
| Approach 2 | [pros] | [cons] | [use case] |
For your use case ([infer from user's context]):
Primary recommendation: [Approach name]
Alternative: [Another approach]
Source: repo/file_path:line_range
[Specific relevant code - imports, key function, not arbitrary truncation]
Why this matters: [Brief explanation]
Source: repo/file_path:line_range
[Specific relevant code]
Why this matters: [Brief explanation]
IMPORTANT: Include GitHub URLs for ALL meaningful files found across all searches.
List every unique file analyzed (15-30 files), grouped by repository:
Format: Direct GitHub blob URLs with line numbers where relevant (e.g., https://github.com/owner/repo/blob/main/path/file.ts#L10-L50)
**Summary characteristics:**
- **Factual** - Based on extracted data, not assumptions
- **Actionable** - Clear recommendations with reasoning
- **Contextualized** - References specific code locations with line numbers
- **Balanced** - Shows trade-offs, not just "best practice"
- **Comprehensive** - Covers patterns, approaches, trade-offs, recommendations
- **Accessible** - GitHub URLs for ALL meaningful files so users can explore full source code
---
### Step 6: Save Results to File
**After generating comprehensive summary, persist for future reference:**
1. **Generate timestamp:**
- Invoke `timestamp` skill to get deterministic YYYYMMDDHHMMSS format
- Example: `20250110143052`
2. **Sanitize query for filename:**
- Convert user's original query to kebab-case slug
- Rules: lowercase, spaces → hyphens, remove special chars, max 50 chars
- Example: "React hooks useState" → "react-hooks-usestate"
3. **Construct file path:**
- Directory: `docs/research/github/`
- Format: `<timestamp>-<sanitized-query>.md`
- Full path: `docs/research/github/20250110143052-react-hooks-usestate.md`
4. **Save using Write tool:**
- Content: Full comprehensive summary from Step 5
- Ensures persistence across sessions
- User can reference past research
5. **Log saved location:**
- Inform user where file was saved
- Example: "Research saved to docs/research/github/20250110143052-react-hooks-usestate.md"
**Why save:**
- Comprehensive summaries represent significant analysis work (30-150s of API calls)
- Users may want to reference patterns/trade-offs later
- Builds searchable knowledge base of GitHub research
- Avoids re-running expensive queries for same topics
---
## Error Handling
**Common issues:**
- **Auth errors:** Prompt user to run `gh auth login --web`
- **Rate limits:** Show remaining quota, reset time. If hit during multi-search, stop gracefully with partial results
- **Network failures:** Continue with partial results, note which queries failed
- **No results for query:** Note in summary, adjust subsequent queries to be broader
- **All queries return same files:** Note low diversity, recommend broader initial queries
**Graceful degradation:** Partial results are acceptable. Complete summary based on available data.
---
## Limitations
- GitHub API rate limit: 5,000 req/hr authenticated (multi-search uses more quota)
- Each tool invocation fetches top 10 results only
- Skips files >100KB
- Sequential execution takes longer than single query (10-30s per query)
- Provides factual data, not conclusions (Claude interprets patterns)
- Deduplication assumes exact path matches (renamed files treated as unique)
---
## Typical Execution Time
**Per query:** 10-30 seconds depending on:
- Number of results (100 max)
- File sizes
- Network latency
- API rate limits
**Full workflow (3-5 queries):** 30-150 seconds
**Optimization:** If first queries yield sufficient results, skip remaining queries
---
## Integration Notes
**Example: User asks "find Claude Code skills doing github search"**
```javascript
// 1. Claude analyzes: Skills use SKILL.md with frontmatter, likely in .claude/skills/
// 2. Claude generates queries:
// - "filename:SKILL.md github search" (matches SKILL.md files with "github search" text)
// - "octokit.rest.search language:typescript" (matches actual Octokit API usage)
// - "gh api language:typescript path:skills" (matches gh CLI usage in skills)
// 3. Claude executes sequentially:
cd plugins/knowledge-work/skills/gh-code-search
pnpm search "filename:SKILL.md github search"
// [analyze results]
pnpm search "octokit.rest.search language:typescript"
// [analyze results]
pnpm search "gh api language:typescript path:skills"
// 4. Claude aggregates, deduplicates, analyzes patterns
// 5. Claude generates comprehensive summary with trade-offs and recommendations
Validate workflow with diverse queries:
Check quality:
Weekly Installs
75
Repository
GitHub Stars
3
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykWarn
Installed on
opencode68
cursor65
codex62
gemini-cli61
github-copilot55
kimi-cli51
React 组合模式指南:Vercel 组件架构最佳实践,提升代码可维护性
120,000 周安装