| name | context |
| description | Set up the best context tools for AI coding agents: Context7 (live library docs via MCP), opensrc (real package source code), and a project CLAUDE.md. Use when starting a new project or when the agent keeps hallucinating outdated API usage. |
Context
You are setting up the context infrastructure that makes an AI coding agent accurate and well-informed. Work through each phase in order.
Project: {{args}}
Phase 1: Interview
Ask the user (combine related questions):
- Primary languages/frameworks: What stack is this project? (Needed to know which library docs matter most)
- Context7: Install as a project-level MCP server (
.claude/settings.json) or user-level (~/.claude/settings.json)?
- opensrc: Is Node.js 18+ installed? (required for opensrc CLI)
- CLAUDE.md: Does a
CLAUDE.md already exist for this project? Should we create or update one?
Phase 2: Context7: Live Library Docs
Context7 is an MCP server that pulls up-to-date, version-specific library documentation directly into the agent's context. It eliminates hallucinated APIs and outdated usage patterns.
Install
Option A: Automatic (recommended):
npx @upstash/context7-mcp@latest init --claude
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp
Option B: Manual config:
Add to .claude/settings.json (project-level) or ~/.claude/settings.json (user-level):
{
"mcpServers": {
"context7": {
"command": "npx",
"args": ["-y", "@upstash/context7-mcp@latest"]
}
}
}
Restart Claude Code after adding the config.
Verify
Ask Claude: What is the latest way to do server actions in Next.js? use context7
If Context7 is working, Claude will fetch live docs from the official Next.js documentation and cite the version. If it falls back to training data, the MCP config is not loaded yet.
How to use
Add use context7 to any prompt involving a library:
How do I set up Drizzle ORM with Postgres? use context7
Create a Hono middleware that validates a JWT. use context7
What changed in React 19 for forms? use context7
To target a specific library: use context7 library /vercel/next.js
Phase 3: opensrc: Real Package Source Code
opensrc gives the agent access to the actual source code of any npm, PyPI, or Rust crate: not just types or docs. Useful when you need to understand exactly how a library works internally, trace a bug into a dependency, or find real usage examples.
Install
npm install -g opensrc
Requires Node.js 18+ and Git. Packages are fetched on first use and cached locally.
Verify
opensrc path zod
How to use
cat $(opensrc path drizzle-orm)/src/pg-core/columns/common.ts
rg "createServer" $(opensrc path hono)/src
ls $(opensrc path better-auth)/packages/better-auth/src
These examples use POSIX $(...) command substitution with unix tools (cat, rg, ls), so they assume a POSIX shell. On Windows, run them via the Bash tool or Git Bash, or use the PowerShell equivalent (e.g. Get-Content (opensrc path hono)/src/router/trie-router/router.ts).
Tell the agent: "Use opensrc path <package> to read the source of before implementing."
Add to CLAUDE.md so the agent uses it automatically: see Phase 4.
Phase 4: CLAUDE.md: Project Context File
A CLAUDE.md at the project root is loaded into Claude Code's context on every session. It is the most reliable way to give the agent persistent, project-specific knowledge.
Create or update CLAUDE.md with:
# Project Context
## Stack
[List the key frameworks, libraries, and tools with their versions]
## Architecture
[Brief description of the main components and how they connect]
## Key Conventions
[Coding conventions, naming patterns, important file locations]
## Context Tools
- **Library docs**: Add `use context7` to any prompt about a library API
- **Package source**: Use `opensrc path <package>` to read a dependency's actual source code
- Example: `cat $(opensrc path hono)/src/router/trie-router/router.ts` (POSIX shell; on Windows use the Bash tool, Git Bash, or `Get-Content (opensrc path hono)/src/router/trie-router/router.ts`)
## Commands
- `bun dev` / `npm run dev` / `pnpm dev` - start dev server
- `bun test` / `npm test` / `pnpm test` - run tests
- `bun run db:migrate` / `npm run db:migrate` - run migrations
[Add the actual commands for this project, using the project's package manager]
If a CLAUDE.md already exists, add the Context Tools section to it rather than overwriting.
Phase 5: Explore the Project
With context tools in place, run a structured codebase exploration so the agent starts with accurate project knowledge. Spawn 3 parallel subagents:
| Subagent | Focus |
|---|
| 1 | Stack inventory: read package.json / Cargo.toml / requirements.txt, identify all key dependencies and their versions |
| 2 | Architecture: read entry points, main config files, directory structure, understand how the pieces connect |
| 3 | Conventions: find coding patterns, naming conventions, how tests are structured, any existing documentation |
Synthesize findings into a Context Summary and offer to write it into CLAUDE.md.
Phase 6: Verify Everything Works
Run these checks:
Completion Report
- Context7: installed (project-level or user-level), verified working
- opensrc: installed, verified working
- CLAUDE.md: created or updated with project context
- Key libraries where Context7 will be most useful (list)