Search GitHub for real-world code examples and implementation patterns. Use when user wants to find code examples on GitHub, search GitHub repositories, discover how others implement features, learn library usage patterns, or research architectural approaches. Fetches top results with smart ranking (stars, recency, language), extracts factual data (imports, syntax patterns, metrics), and returns clean markdown for analysis and pattern identification.
/plugin marketplace add otrebu/agents/plugin install knowledge-work@otrebu-dev-toolsThis skill is limited to using the following tools:
package.jsonpnpm-lock.yamlscripts/github.tsscripts/log.tsscripts/main.tsscripts/query.tsscripts/ranker.tsscripts/types.tstsconfig.jsonFetch 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:
Implement GDPR-compliant data handling with consent management, data subject rights, and privacy by design. Use when building systems that process EU personal data, implementing privacy controls, or conducting GDPR compliance reviews.
Create employment contracts, offer letters, and HR policy documents following legal best practices. Use when drafting employment agreements, creating HR policies, or standardizing employment documentation.