When researching code, follow the tool escalation ladder:
- Local first - For pure code lookup, invoke
code-searchskill first; otherwise use Grep/Glob/Read - Terminal research - Use fast CLI tools (w3m/lynx, curl, jq, rg, fd, gh) and DDG bangs
- Built-in web - Use WebSearch/WebFetch for documentation and articles
- Skills & Scripts - Use
gh-cliskill for GitHub, scripts for Stack Overflow - MCP servers - Use Exa/Deepwiki/Chrome for complex research needs
Start simple. Escalate only when simpler tools fail.
Web research:
WebSearch- General web search for docs, tutorials, discussionsWebFetch- Fetch and analyze specific URLs (works for most static sites)
When to use: Always start here. These tools are fast, low-cost, and handle 80% of research tasks.
Fallback to POSIX tools:
grep,find,sed,awk,cut,sort,uniq
Terminal web/doc workflows:
w3m/lynxfor fast doc browsing- DuckDuckGo bangs (
!gh,!so,!npm,!pypi) to jump directly to sources curl+jq+rgfor structured data and targeted extractionpup/htmlq/python -m bs4for HTML parsing when neededreadability-lxml(orpython -m readability) to clean article contentcsvkit/xsvfor CSV docs and tablesfzfto interactively select snippets and URLs- Clipboard handoff:
pbcopy(macOS) /xclip -selection clipboard(Linux)
Rate-limit hygiene:
curl --retry 3 --retry-delay 2 --compressed+ backoff (sleep)- Use
ETag/If-Modified-Sinceto avoid refetching unchanged docs
When to use: Quick web/CLI research before WebSearch, or when you need high-throughput data extraction.
GitHub CLI (gh) - Use the gh-cli skill for comprehensive GitHub operations:
- Repository info, issues, PRs, code search, Actions, releases, and more
- Invoke with:
Skill: gh-cli
stackoverflow-api.sh - Find solutions to errors
# Search Stack Overflow for solutions
${AGENT_ROOT}/skills/code-research/scripts/stackoverflow-api.sh "error message or question"
When to use: When you need structured GitHub data (issues, PRs, code across repos) that WebSearch can't provide cleanly.
Exa MCP - Semantic web search with AI understanding
- Use for: Finding related libraries, discovering best practices, semantic similarity search
- Better than WebSearch when you need conceptual matches, not keyword matches
Deepwiki MCP - Documentation and wiki content
- Use for: Library documentation, API references, technical wikis
- Better than WebFetch for structured documentation extraction
Chrome Web Tools MCP - Headless browser automation
- Use for: JavaScript-heavy sites, sites requiring authentication, dynamic content
- Example: Navigating
https://codewiki.google/github.com/anomalyco/opencode
When to use: When simpler tools fail—JS-rendered content, semantic search needs, or complex documentation sites.
Find relevant files
Glob: **/{keyword}.{ts,py,go}
Search for patterns
Grep: "functionName|className|errorMessage"
Deep exploration
Task(subagent_type=Explore): "Find how authentication is implemented"
</step>
<step name="2.5" label="Terminal Research">
Use fast terminal tools to browse docs and extract data:
Quick doc browsing
w3m https://docs.example.com/guide
DDG bangs
WebSearch: "!gh repo:org/project authentication middleware"
Fast extraction
curl -s https://docs.example.com/api | rg -n "endpoint" | sed -n '1,120p'
Structured GitHub data via gh
gh repo view org/repo --json description --jq '.description'
Clean article text
curl -s https://blog.example.com/post | python -m readability | rg -n "API" | sed -n '1,80p'
CSV extraction
curl -s https://docs.example.com/table.csv | xsv select 1,3 | xsv table | sed -n '1,40p'
Interactive selection
curl -s https://docs.example.com/api | rg -n "endpoint" | fzf
Clipboard handoff
curl -s https://docs.example.com/api | pbcopy # or: xclip -selection clipboard
Prefer Rust utilities when available (rg/fd/bat/sd/xsv); fall back to standard Unix tools otherwise.
</step>
<step name="3" label="Expand to Web">
If local exploration isn't enough:
General search
WebSearch: "library-name how to implement X"
Fetch specific docs
WebFetch: "https://docs.library.com/guide"
</step>
<step name="4" label="Use Skills & Scripts for Structured Data">
When you need GitHub/StackOverflow data:
GitHub operations - invoke the gh-cli skill
Skill: gh-cli
Then use gh directly, e.g.:
gh issue list -R facebook/react --search "useEffect cleanup" gh search code "useEffect cleanup" --repo facebook/react
```bash
# Find error solutions
${AGENT_ROOT}/skills/code-research/scripts/stackoverflow-api.sh "React useEffect memory leak"
Semantic search (Exa)
mcp__web_search_exa: "best practices for React state management 2024" mcp__get_code_context_exa: "langgraph deepagent cli" mcp__crawling_exa: "https://codewiki.google/github.com/anomalyco/opencode"
Documentation extraction (Deepwiki)
mcp__deepwiki__read_wiki_contents: "react/react" mcp__deepwiki__read_wiki_structure: "anomalyco/opencode" mcp__deepwiki__ask_question: "What are the context engineering strategies used by anomalyco/opencode?"
Website Navigation
Use chrome-devtools-mcp to open up webpages and crawl through them for deeper information extraction tasks.
</step>
<step name="6" label="Save High-Value Sources to Readwise">
When a source is highly relevant (authoritative docs, key blog posts, insightful discussions), persist it for future retrieval:
```bash
# Save a URL to Reader with research tags
readwise reader-create-document --url "https://..." --tags "code-research,<topic>"
# Create a highlight for a key finding or quote
readwise readwise-create-highlights --highlights '[{"text": "key finding text", "title": "Source Title", "source_url": "https://...", "note": "Why this matters"}]'
Only save sources scoring 2-3 on relevance (directly answers the question or provides strong supporting context). Do not save noise.
Quick answer - For simple questions, respond inline with sources Structured summary - For broader research:
## Findings
- Key finding 1
- Key finding 2
## Recommendations
- Recommended approach with rationale
## Sources
- [Source 1](url)
- [Source 2](url)
Research report - For deep dives, create a markdown file:
Write: research-{topic}-{date}.md