Loading...
Loading...
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.
npx skill4agent add otrebu/agents gh-code-searchgh auth login --webgh auth status # Should show authenticatedcd plugins/knowledge-work/skills/gh-code-search
pnpm install # First time only
pnpm search "your query here"useState/useEffectfunction useconst use =(req, res, next) =>app.usefunction(err,useMachinecreateMachineinterpret.ymlactions/setup-nodetscpnpm builduseState useEffect language:typescript extension:tsxfunction use language:typescript extension:tsfunction useFetch()const use = language:typescriptconst useAuth = () =>(req, res, next) => language:javascriptapp.use expressfunction(err, req, res, next) language:javascriptuseMachine language:typescript extension:tsxconst [state, send] = useMachine(machine)createMachine language:typescriptinterpret xstate language:typescriptconst service = interpret(machine)cd plugins/knowledge-work/skills/gh-code-search
pnpm search "query text here"repository.full_name + file_path# 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]| Approach | Pros | Cons | Best For |
|---|---|---|---|
| Approach 1 | [pros] | [cons] | [use case] |
| Approach 2 | [pros] | [cons] | [use case] |
[Specific relevant code - imports, key function, not arbitrary truncation][Specific relevant code]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