Stacks
Claude Code and Context7: Current Docs on Demand
Checked 2026-10-31
Loading poll...
To give Claude Code current library docs, add the Context7 MCP server with claude mcp add --scope user --header "Authorization: Bearer YOUR_API_KEY" --transport http context7 https://mcp.context7.com/mcp, then tell it in CLAUDE.md to use Context7 for library questions. The free plan has 1,000 calls a month. Setup details checked 31 October 2026.
The stack at a glance
Part | Role | Cost |
|---|---|---|
The agent that writes the code | Pro $17 a month annual or $20 monthly | |
Looks up current, version-specific library docs | Free: 1,000 calls a month; Pro $10 per seat | |
| A standing rule so you do not have to ask | Free |
Optional: a | Keeps lookups out of your main context | Free |
Context7 is MIT-licensed and maintained by Upstash. It exposes two MCP tools, resolve-library-id and query-docs, and also has a CLI with ctx7 library and ctx7 docs.
Why you want this
A model's knowledge stops at a training date. Libraries do not. Ask an agent to write code against a framework that changed last quarter and it often answers in last year's style: a renamed function, a dropped argument, or an API it made up. The Context7 README lists the failure modes: examples based on old training data, hallucinated APIs and generic answers for old package versions.
The fix is to hand the agent the real documentation for the version you use, at the moment it needs it. That is what Context7 does: it looks up the library, finds the relevant sections, and puts them in the agent's context so it can quote them.
The other ways to give an agent docs
Method | Good | Bad |
|---|---|---|
Rely on training data | Free, instant | Stale for fast-moving libraries |
Paste the docs into the prompt | Exact, you control it | Slow, uses a lot of context |
Claude Code's web fetch of a docs URL | No setup; the Claude Code docs, for example, serve clean markdown if you add | You must know the URL; pages can be long |
| Written for models | Not every project publishes one |
Context7 | Searches many libraries by name and version | A third-party index; call limits |
Vendor-run docs servers | Official source | One server per vendor |
Context7's strength is breadth: one server for thousands of libraries. Its weakness is that you are trusting a third party's index. For a library with its own official docs MCP server, prefer that. See best MCP servers and the MCP server list.
Setup, step by step
1. Check Node
For local use the troubleshooting page says Node.js 20 or newer for the MCP package; the ctx7 CLI needs 22.13 or newer. The remote server needs no local runtime. Check with node --version.
2. The quickest route
npx ctx7 setupPer the README this signs you in with OAuth, generates an API key and installs the right skill. Flags like --claude target one agent. npx ctx7 remove undoes it.
3. Or add the server by hand
Remote server, with your key:
claude mcp add --scope user --header "Authorization: Bearer YOUR_API_KEY" --transport http context7 https://mcp.context7.com/mcpLocal server instead:
claude mcp add --scope user context7 -- npx -y @upstash/context7-mcp --api-key YOUR_API_KEY--scope user makes it available in all your projects. Use --scope project to share the config in a .mcp.json file, and never commit the key there. Claude Code's MCP docs describe the scopes in full. A key starts with ctx7sk; the README recommends one for higher rate limits.
Run /mcp in Claude Code to confirm the server is connected.
4. Add the standing rule
The README suggests putting this in CLAUDE.md, AGENTS.md or your rules file:
Always use Context7 when I need library/API documentation, code
generation, setup or configuration steps without me having to
explicitly ask.Add the versions you care about, since version matters:
## Libraries
- Next.js 16, React 19, Tailwind 4. When writing code against these,
look up the docs first and quote the section you used.See write a good CLAUDE.md and the CLAUDE.md starter template.
Prompts that work
These come from the Context7 README and our add-on page.
Build against a current API
Using Next.js 16, write a proxy that redirects unauthenticated users
to /login. use context7Skip the lookup step with a library ID
Show me the Supabase email and password sign-up call.
use library /supabase/supabase for API and docs.Plan an upgrade without editing
We are on React Router 6 and want to move to 7. use context7 to read
the migration guide, then list every file in src/ that uses an API that
changed. Do not edit anything yet.Check one option
What is the exact option name for caching JSON responses in a
Cloudflare Worker? use context7 and quote the docs you used.Asking the agent to quote what it used is the habit that pays most. It shows whether the lookup happened and whether the agent read it correctly.
How many calls you really get
One call is one tool call. A single question can use two: one to resolve the library ID, one to query the docs. That makes the free 1,000 calls nearer 500 questions if the agent resolves every time. Giving the library ID in your prompt, as in the Supabase example, halves it.
Plan | Price | Calls | Repositories |
|---|---|---|---|
Free | $0 | 1,000 a month, with 20 bonus calls a day after the limit | Public |
Pro | $10 per seat a month | 2,000 per seat; extra at $5 per 1,000 | Public and private |
Enterprise | Custom | Custom | Public and private |
Pro limits are per seat, not shared. Private repository parsing is charged at $5 per 1M tokens when you add or refresh one.
A docs-check subagent
Docs lookups add text to your context. If you do a lot of them, move them into a subagent so the main conversation stays short. A sketch for .claude/agents/docs-check.md:
---
name: docs-check
description: Looks up current library documentation with Context7 and returns a short, quoted answer. Use before writing code against any library.
---
Use Context7 to find the exact documentation for the library and version asked.
Return: the function or option name, its signature, one short example, and the
quoted lines you relied on. If the docs do not answer the question, say so.Check the current subagent file format in the Claude Code docs before copying. See subagents and how to write a subagent.
A session from start to finish
Here is how a docs-aware session usually runs, using the features above. The steps are illustrative; your library and prompts will differ.
- You start Claude Code in your project.
CLAUDE.mdalready lists your library versions and the Context7 rule. - You ask: "Add a rate limit to the contact form endpoint using the framework's built-in option."
- Claude calls
resolve-library-idfor your framework, thenquery-docswith the question. That is two calls. - It reads the returned section and quotes it back to you: the option name, the signature and an example.
- It writes the change using that exact name, runs your tests and shows the diff.
- You compare the quoted lines against the diff. If the docs said one thing and the code does another, you catch it in seconds.
The quote in step four is the safety check. Without it, you cannot tell whether the agent looked anything up or just guessed with confidence.
Setting it up for a team
A shared setup avoids five people configuring five different versions.
- Project scope. Use
--scope projectso the server definition lives in.mcp.jsonin the repository. Never put the key in that file. - Keys per person. Each developer uses their own key from their own environment. On Pro, limits are per seat, not shared across the team.
- Shared rule. Commit the
CLAUDE.mdorAGENTS.mdblock so everyone's agent behaves the same. If some people use Cursor or Codex CLI, the same rule works in their files, since Context7 supports many clients. - Pin library versions in the rule, and update them when you upgrade dependencies.
- Review the output. Docs lookup improves accuracy, but it does not replace code review, type checks or tests.
If your company restricts third-party services, remember that the remote server receives the query text. Check with your security team before enabling it, and decide whether to allow it for private repositories at all, since that needs the Pro plan and a key. See enterprise AI coding agent security for questions to ask.
Safety, privacy and trust
- Your question leaves your machine with the remote server. Keep queries about the library, not your codebase, and never include secrets.
- The content is community contributed. The README says Upstash cannot guarantee the accuracy, completeness or security of all library documentation. Documentation text can carry instructions, so treat it like any fetched web text.
- Keys are tokens. Use user scope or an environment variable, not a committed file.
- Quality varies. If a library is missing or thin in the index, the answer will be too.
For broader practice, see enterprise AI coding agent security.
Troubleshooting
- Setup fails locally. Check
node --version. The troubleshooting page coversERR_MODULE_NOT_FOUND(trybunxordeno), auriTemplate.jserror (use--node-options=--experimental-vm-modules), TLS errors and timeouts needing the full path to Node. The remote server avoids all of this. - The agent ignores Context7. Add the standing rule, or say "use context7" in the prompt, and check
/mcpshows it connected. - Wrong version. Name the version in your prompt, for example "Next.js 16", or pass a library ID with a version.
- Out of calls. Give library IDs, ask fewer, larger questions, or move to Pro.
When this stack is not enough
Docs lookup helps with what the library does. It does not tell the agent how your project uses it. For that, keep your own conventions in CLAUDE.md, and consider a code-aware tool such as Serena MCP for navigating your codebase. For browsing and testing the result, add Playwright MCP; the setup is in Claude Code and Playwright for browser QA. For GitHub context, see GitHub MCP.
Which libraries benefit most
Docs lookup pays off most where the answer changed recently. Fast-moving web frameworks and SDKs are the clearest cases, since a function renamed last quarter is exactly what training data gets wrong. Cloud and payment APIs also change, and a wrong parameter there costs real money. It helps least with stable standard libraries that rarely change, and with your own code, which Context7 does not index unless you add private repositories on Pro. A good habit is to turn the rule on for new projects and new dependencies, and leave it off when you work only on well-known, stable code.
Prompt patterns that waste calls
- Asking five small questions about one library, each triggering a resolve and a query. Ask one larger question instead.
- Not giving the library ID when you know it, which doubles the calls.
- Asking for "everything about" a library. Name the function or task.
- Re-asking the same question in each new session. Put the answer in a note or in
CLAUDE.md. - Using it for questions about your own code, which it cannot answer.
Writing the answer down
When the agent finds a non-obvious option name or behavior, ask it to add one line to a notes file or to CLAUDE.md. The next session starts with that fact and does not spend a call. Over a few weeks this builds a short, project-specific cheat sheet that costs nothing to read, and it reduces the number of lookups your free plan has to cover.
Reviewing library choices
Docs lookup also helps before you add a dependency. Ask the agent to read the current docs for two candidate libraries and compare setup steps, supported versions and breaking-change notes. Because it quotes sources, you can check the comparison yourself in a few minutes. Treat the result as a starting point and confirm the package's maintenance on its own repository.
Our take
This is an editorial reading of the Context7 README, docs and plans, not a test we ran.
Context7 solves a narrow, real problem cheaply. The setup is one command, the free tier is enough to find out whether it helps, and the standing rule in CLAUDE.md removes the habit of typing "use context7". The best return is on libraries that change fast, such as web frameworks and SDKs.
The caution is trust. It is a third-party index feeding text into your agent, so keep secrets out of queries and make the agent quote its sources. If a library has an official docs server or an llms.txt file, use that first and let Context7 cover the rest. Count calls in the first week; if you hit the cap, the fix is usually giving the library ID, not paying.
Quick answers
Does it work with other agents? Yes. The Context7 docs list snippets for many clients, and our Context7 MCP page has install lines for five agents.
Is it better than web search? For library questions it is more targeted, because it returns documentation sections for a named version instead of a list of pages.
Checklist
- Check
node --versionif you plan to run the server locally - Add the server with
claude mcp addor runnpx ctx7 setup - Confirm with
/mcp - Add the standing rule and your library versions to
CLAUDE.md - Ask the agent to quote the docs it used
- Keep secrets and private code out of docs queries
- Watch your call count in the first week
Questions
How do I add Context7 to Claude Code?
Run claude mcp add --scope user --header "Authorization: Bearer YOUR_API_KEY" --transport http context7 https://mcp.context7.com/mcp, or run npx ctx7 setup and follow the prompts.
Is Context7 free with Claude Code?
Context7 has a Free plan at $0 with 1,000 API calls a month for public repositories. Claude Code itself needs a paid Claude plan, a Console account or a supported cloud provider.
Do I have to type use context7 every time?
No. Add a standing rule to CLAUDE.md or AGENTS.md that tells the agent to use Context7 for library documentation, as the Context7 README suggests.
Does Context7 send my code to a server?
With the remote server, the query your agent sends goes to Context7. Keep queries about the library and leave secrets and private code out of them.
Loading poll...