Agent skill
code-context
This skill should be used when the user asks to "understand a codebase", "get code context", "research a library", "explore a repository", "find code examples", "look up documentation", or wants to understand how a specific project or library works before making changes.
Install this agent skill to your Project
npx add-skill https://github.com/FradSer/dotclaude/tree/main/code-context/skills/code-context
SKILL.md
Code Context Retrieval
This skill provides 5 methods for retrieving code context. Select methods based on the target: public GitHub repos, library docs, code search, direct inspection, or post-clone web enrichment.
Token Isolation (Critical)
Never run any external lookup in the main context. Always spawn Task agents:
- DeepWiki: Agent calls
read_wiki_structure/read_wiki_contents/ask_question, extracts architecture summary and key relationships, returns concise overview. - Context7: Agent calls
resolve-library-idthenquery-docs, extracts the minimum viable API surface and usage examples, returns copyable snippets with version notes. - Exa: Agent calls
get_code_context_exa, extracts minimum viable snippets, deduplicates near-identical results (mirrors, forks, repeated StackOverflow answers), returns copyable snippets + brief explanation. - Git clone: Agent clones to
/tmp/, reads entry points and core modules, runsrm -rfcleanup, returns file structure summary and key patterns. - Web Search+Fetch: Agent runs
WebSearchwith version-anchored queries derived from clone findings, callsWebFetchon high-signal URLs, returns only validated insights cross-referenced against cloned code.
Main context stays clean regardless of search volume. Only final summaries return to the caller.
Method 1: DeepWiki (AI-powered repo documentation)
Best for: Well-known public GitHub repositories where you need architecture overview, component explanations, or high-level understanding fast.
Tools: read_wiki_structure, read_wiki_contents, ask_question
Process:
- Call
read_wiki_structurewith the owner/repo (e.g.,"facebook/react") to get topic list - Call
read_wiki_contentsfor relevant topics, orask_questionfor targeted queries - Use when you need: architecture diagrams, component relationships, design decisions
Strengths: Zero setup, instant AI-summarized documentation, good for onboarding to unfamiliar repos.
Limitations: Only works for public GitHub repos; coverage varies by project popularity.
Method 2: Context7 (library documentation)
Best for: Getting up-to-date API docs, usage examples, and version-specific documentation for npm/pip packages and frameworks.
Tools: resolve-library-id, query-docs
Process:
- Call
resolve-library-idwith the library name (e.g.,"react","fastapi") to get the canonical ID - When the user specifies a version (e.g.,
"react@18"), select the matching version from theversionslist returned byresolve-library-idand append it to the library ID path (e.g.,/facebook/react/18.3.1) - Call
query-docswithlibraryIdandquery— these are the only two parameters
Query tips: Be specific -- "useCallback dependency array" beats "react hooks". Include the framework version when known.
Version pinning: Encode version into the library ID path (e.g., /vercel/next.js/v14.3.0-canary.87), not as a separate parameter. Use the versions list from resolve-library-id to pick the correct slug.
Strengths: Always current docs, supports version pinning, covers thousands of libraries, excellent for API reference.
Limitations: Requires the library to be indexed; less useful for internal/private packages.
Method 3: Exa Code Search (web-wide code examples)
Best for: Finding real-world usage patterns, StackOverflow-style answers, GitHub Gist examples, and code snippets from across the web.
Tool: get_code_context_exa
Setup: Works without an API key (free tier with rate limits). For higher limits, set the EXA_API_KEY environment variable.
Process:
- Call
get_code_context_exawith a precise query - Set
tokensNumbased on need: 3000 for quick examples, 8000 for comprehensive patterns - Verify publication dates on results; prefer recent sources
Query writing guidance:
- Include the language or framework:
"TypeScript React"not just"React" - Include the version when relevant:
"Next.js 14 app router" - Use exact identifiers:
"useServerAction"not"server action hook" - Add the pattern type:
"example","error handling","migration guide" - Example:
"TypeScript Next.js 14 app router server action error handling example"
Strengths: Finds diverse real-world examples, not limited to official docs, surfaces community solutions.
Limitations: Results may be outdated; always check publication dates and verify against official docs.
Method 4: Git Clone (direct code inspection)
Best for: Private repositories, detailed implementation review, running local analysis, or when other methods lack depth.
Process:
- Run
git clone <repo-url> /tmp/<repo-name> --depth=1to fetch the code - Read key files: entry points, configuration, core modules
- Use Glob to map structure; use Grep to search patterns
- Clean up when done:
rm -rf /tmp/<repo-name>
Strengths: Full code access, works with private repos (with credentials), enables static analysis tools.
Limitations: Requires network access and disk space; slow for large repos; credentials needed for private repos.
Method 5: Web Search + Fetch (post-clone enrichment)
Best for: Enriching findings from a git clone with changelogs, issue discussions, blog posts, and migration guides that live outside the repository itself.
Tools: WebSearch, WebFetch
When to apply: Use after completing Method 4. The clone gives you the code; this method gives you the why and what changed.
Process:
- Derive targeted queries from clone findings — use exact identifiers, error strings, or design patterns found in the source
- Call
WebSearchwithqueryset to a precise, version-anchored string (e.g.,"<library> <version> breaking change <symbol>") - For each high-signal result, call
WebFetchwithurl(from search results) and a focusedpromptto extract only the relevant section - Cross-reference fetched content against the cloned code to validate accuracy
- Discard results older than 2 years unless the topic is stable/foundational
Query patterns:
- Changelogs:
"<repo-name> CHANGELOG v<version>"or"<repo-name> release notes" - Design rationale:
"<repo-name> <concept> why OR rationale site:github.com" - Known issues:
"<repo-name> <symbol or pattern> issue OR bug site:github.com" - Migration:
"<repo-name> migrate from <old-version> to <new-version>"
Strengths: Surfaces context that never appears in source code — deprecation notices, upstream issue threads, author blog posts, community migration experiences.
Limitations: Results may be stale or inaccurate; always validate fetched claims against the actual cloned code. Rate-limited without API key.
Method Selection Guide
| Scenario | Primary Method | Fallback |
|---|---|---|
| "How does X library work?" | Context7 | DeepWiki |
| "Understand the architecture of Y repo" | DeepWiki | Git Clone |
| "Find examples of Z pattern" | Exa | Context7 |
| "Inspect private/internal repo" | Git Clone | - |
| "What changed in v3 of library?" | Context7 | Exa |
| "How are modules connected?" | DeepWiki | Git Clone |
| "Why was this design decision made?" | Git Clone → Web Search+Fetch | DeepWiki |
| "What broke between versions?" | Web Search+Fetch | Context7 |
Combining Methods
For comprehensive context, combine methods:
- DeepWiki for architecture overview
- Context7 for specific API details
- Exa for community usage patterns
- Git Clone for implementation details when needed
Always prefer non-destructive read-only operations. When cloning, use /tmp and clean up after.
Recommended Agent Skills
Expand your agent's capabilities with these related and highly-rated skills.
optimize-plugin
This skill should be used when the user asks to "validate a plugin", "optimize plugin", "check plugin quality", "review plugin structure", or "run plugin optimizer".
plugin-best-practices
This skill should be used when the user asks to "validate plugin structure", "review manifest files", "check frontmatter compliance", "verify tool invocation patterns", "explain plugin component types", or needs Claude Code plugin architectural guidance.
init-config
Generates a CLAUDE.md file with AI-driven environment detection and advanced configuration options. This skill should be used when the user asks to "initialize config", "setup claude config", "create CLAUDE.md", or needs help configuring project instructions.
start-feature
Starts working on a new feature branch using git-flow. This skill should be used when the user asks to "start a feature", "create feature branch", "begin new feature", "git flow feature start", or wants to start a new feature.
finish-feature
Finalizes and merges a feature branch into develop using git-flow. This skill should be used when the user asks to "finish a feature", "merge feature branch", "complete feature", "git flow feature finish", or wants to finalize a feature branch.
finish-hotfix
Finalizes a hotfix and merges it into main and develop using git-flow. This skill should be used when the user asks to "finish a hotfix", "merge hotfix branch", "complete hotfix", "git flow hotfix finish", or wants to finalize a hotfix.
Didn't find tool you were looking for?