{"slug": "how-to-give-claude-code-up-to-date-documentation-with-context7", "title": "How to Give Claude Code Up-to-Date Documentation With Context7", "summary": "Upstash's open-source Context7 MCP server lets Claude Code retrieve version-specific library documentation and code examples during a project, addressing cases where the agent generates code against outdated APIs such as LangChain's removed LLMChain. The tutorial's setup path runs `npx ctx7 setup --claude`, which requires Claude Code plus Node.js 22.13 or newer, and offers two integration modes: an MCP server using the `resolve-library-id` and `query-docs` tools, or a CLI + Skills install that teaches Claude Code to fetch docs via Context7 CLI commands.", "body_md": "# How to Give Claude Code Up-to-Date Documentation With Context7\n\nStop wasting tokens debugging outdated code. Give Claude Code up-to-date docs with Context7.\n\nIf you do vibe coding, have you ever run into this issue? You ask **[Claude Code](https://www.claude.com/product/claude-code)** to build an AI application, and it generates the code using a library version that is incompatible with your project. For example, you have **[LangChain](https://www.langchain.com/)** 1.x installed, but Claude Code generates code from an older tutorial that uses `LLMChain`:\n\n``` python\nfrom langchain.chains import LLMChain\n```\n\nYou run the application and get an import error because this older API is not available in your installed setup. Now Claude Code has to investigate the version mismatch, look for the updated API, rewrite the code, and try again. Depending on the issue, it might take several attempts before everything works. There is no doubt that Claude Code can generate entire applications for you. The problem is that the frameworks and libraries it relies on keep changing, and Claude's built-in knowledge does not always reflect these changes. These failed runs are not just frustrating. They also cost time and tokens.\n\nOne way to address this is **[Context7](https://context7.com/)**, an open-source Model Context Protocol (MCP) server developed by **[Upstash](https://upstash.com/)** that lets AI coding agents retrieve version-specific library documentation and code examples while working on a project. So, instead of manually searching documentation and pasting examples into Claude Code, you can connect Context7 and let the agent retrieve relevant information while working on your project.\n\nIn this tutorial, we will explore how Context7 works, connect it to Claude Code, configure automatic documentation retrieval, and test it with some examples. So, let's get started.\n\n## What Is Context7 and How Does It Work?\n\nContext7 is a documentation retrieval service that integrates with AI coding assistants through two main MCP tools: `resolve-library-id`, which identifies the correct library, and `query-docs`, which retrieves documentation related to a specific question. Whatever it returns acts as additional context before Claude writes the implementation.\n\nContext7 also has several benefits, including:\n\n- **Current documentation:** Retrieve relevant framework and library references instead of relying entirely on the model's built-in knowledge\n- **Version-specific examples:** Find documentation for supported library versions\n- **Fewer outdated APIs:** Reduce the chances of generating code using deprecated functions\n- **MCP integration:** Connect documentation retrieval directly to Claude Code and other compatible coding assistants\n- **Less manual work:** Avoid repeatedly searching documentation websites and copying examples into your prompts\n\nNow, let us set it up with Claude Code.\n\n## Step 1: Installing Context7 for Claude Code\n\nBefore getting started, make sure you have Claude Code installed and working. You can check your Claude Code installation by opening a terminal and running:\n\n```\nclaude --version\n```\n\nFor the recommended Context7 command-line interface (CLI) installation, you also need **[Node.js](https://nodejs.org/)** 22.13 or newer. You can check your versions with:\n\n```\nnode --version\nnpm --version\n```\n\nIf both commands return version information and Node.js meets the minimum requirement, you are ready.\n\nNow install and configure Context7 using a single command:\n\n```\nnpx ctx7 setup --claude\n```\n\nThis command launches an interactive setup that allows you to configure Context7 specifically for Claude Code. You will be asked to authenticate with Context7 and select an integration mode. There are two options:\n\n- **MCP server:** Connects Claude Code to Context7 through MCP tools\n- **CLI + Skills:** Installs a skill that teaches Claude Code to retrieve documentation using Context7 CLI commands\n\nFor this tutorial, select the MCP option because it allows us to examine how Claude Code interacts with Context7's documentation tools. The setup process authenticates your account, creates an API key, and configures the necessary integration. It also installs instructions that help Claude Code recognize when documentation retrieval is needed. When everything is set up, you will see something like this at the end:\n\n```\n  Press Enter to open the browser, or Ctrl-C to quit...\n  ✔ Authenticated with API key\n\n✔ Context7 setup complete\n\n  Claude Code\n    + MCP server configured with API Key\n    + Rule installed\n    + Skill installed\n```\n\n## Step 2: Verifying the Context7 Connection\n\nAfter completing the setup, open Claude Code:\n\n```\nclaude\n```\n\nInside Claude Code, enter:\n\n```\n/mcp\n```\n\nThis opens the MCP management interface, where you can inspect the available servers and their connection status. Look for Context7 and check that it is connected.\n\n```\nOutput:\nContext7 MCP Server\n\nStatus:       ✔ connected\nAuth:         ✔ authenticated\nURL:          https://mcp.context7.com/mcp\nCapabilities: tools\n```\n\nYou can also inspect configured MCP servers directly from your terminal using this command:\n\n```\nclaude mcp list\n```\n\nIf the MCP connection is working, Claude Code should be able to access the two Context7 tools: `resolve-library-id` and `query-docs`. If Context7 is missing or disconnected, restart Claude Code, check your authentication, and repeat the setup if necessary.\n\n## Step 3: Testing Context7 With a Coding Task\n\nNow we can test whether Claude Code can retrieve documentation before generating code.\n\nFor this example, we will use **[Next.js](https://nextjs.org/)** 16.\n\nStart Claude Code inside an existing Next.js project, or create a new project and open Claude Code there.\n\nEnter the following prompt:\n\n```\nUse Context7 to retrieve the Next.js 16 documentation for the proxy convention. Show me how to protect a dashboard route by checking an authentication cookie and redirecting unauthenticated users to `/login`. Explain which Next.js APIs are required, and implement the solution using the current documentation.\n```\n\nHere is what happens:\n\n1. Claude Code recognizes that your request requires Next.js documentation\n2. Context7 resolves the correct Next.js library, if necessary\n3. The agent retrieves relevant documentation about the proxy convention\n4. Claude Code uses the retrieved examples to generate or modify the project's code\n\nHere is what Claude Code returned in our run. In the terminal, you can see that it called Context7 four times and named the documentation version it used:\n\n```\nCalled context7 4 times\n\nSources: the Next.js docs on Context7 (/vercel/next.js/v16.2.9), specifically the\nproxy file convention, the Proxy getting-started guide, the authentication guide,\nthe redirecting guide and the v16 upgrade guide.\n```\n\nIt then summarized what changed in Next.js 16:\n\n- `middleware.ts` is now`proxy.ts` . The old file name and the`middleware` named export are deprecated. Export a function called`proxy` instead (a default export also works).\n- File location. Put `proxy.ts` in the project root, or in`src/` , at the same level as`app/` or`pages/` .\n- Runtime. Proxy always runs on Node.js and can't use the edge runtime. If you need edge, the docs say to keep using `middleware` .\n- Migrating. `npx @next/codemod@canary middleware-to-proxy .` renames the file and the function for you.\n\nIt also listed the APIs required for the solution:\n\n| API | From | Purpose | \n|---|---|---|\n| `proxy(request)` export | `proxy.ts` | Runs on the server before a matched request completes | \n| `NextRequest` (type) | `next/server` | The incoming request; `request.cookies.get(name)` reads a cookie and`request.nextUrl.pathname` gives the path | \n| `NextResponse.redirect(url)` | `next/server` | Sends the redirect; the URL must be absolute, so use `new URL('/login', request.url)` | \n| `NextResponse.next()` | `next/server` | Lets the request continue | \n| `export const config = { matcher }` | `proxy.ts` | Limits which paths proxy runs on. Without it, proxy runs on every request, including static files and images | \n\nFinally, it added the code. The important part of this experiment is not just the generated code. It is whether Claude Code actually used the documentation tools and selected APIs appropriate for your project. You can ask Claude to explain which documentation it retrieved and why it selected a particular implementation.\n\n## Step 4: Making Context7 Work Automatically\n\nOne of the biggest advantages of Context7 is that you do not need to explicitly request documentation every time. The recommended setup installs a skill intended to activate when Claude Code encounters library-related questions.\n\nHowever, if you are using a manual MCP installation, or want more explicit control, you can configure a rule using `CLAUDE.md`.\n\nClaude Code reads this file to understand project instructions and development preferences.\n\nOpen the file in your project directory:\n\n```\nnano CLAUDE.md\n```\n\nAdd the following rule:\n\n```\n## Library Documentation\n\nAlways use Context7 when working with external libraries,\nframeworks, or APIs.\n\nBefore generating code:\n1. Identify the library and its installed version.\n2. Retrieve relevant documentation using Context7.\n3. Prefer examples matching the project's version.\n4. Avoid deprecated APIs when supported alternatives exist.\n5. Check the generated code against the documentation.\n```\n\nSave the file.\n\nNow, when you ask Claude Code to create a feature involving a supported framework or API, it has an explicit instruction to consult Context7 before implementing it.\n\nFor example, you can simply write:\n\n```\nAdd Supabase email and password authentication to my application.\n```\n\nClaude Code can use the Context7 integration without you adding the phrase `use context7`. If you want the rule to apply across all your projects, you can place it in your user-level Claude Code instructions:\n\n```\nnano ~/.claude/CLAUDE.md\n```\n\n## Step 5: Using Context7 With Specific Library Versions\n\nAnother useful Context7 feature is the ability to request documentation for a specific library version. This matters when working with applications that have not yet migrated to the latest release.\n\nFor example:\n\n```\nUsing Context7, retrieve the documentation for Pydantic v2 and show how to migrate a BaseModel from Pydantic v1.\n```\n\nClaude Code called Context7 four times and used the **[Pydantic](https://docs.pydantic.dev/latest/)** v2 documentation (`/pydantic/pydantic/v2.14.1`), specifically the migration guide and the validators and models concept pages.\n\nHere is the Pydantic v1 model it started from:\n\n``` python\nfrom typing import Optional, List\nfrom pydantic import BaseModel, Field, validator, root_validator\n\nclass User(BaseModel):\n    id: int\n    username: str\n    nickname: Optional[str]              # v1: optional, defaults to None\n    tags: List[str] = []\n    password: str\n    password_repeat: str\n\n    class Config:\n        orm_mode = True\n        allow_population_by_field_name = True\n        anystr_strip_whitespace = True\n        schema_extra = {\"example\": {\"id\": 1, \"username\": \"kanwal\"}}\n\n    @validator(\"username\")\n    def username_alphanumeric(cls, v):\n        assert v.isalnum(), \"must be alphanumeric\"\n        return v\n\n    @validator(\"tags\", each_item=True)\n    def tag_not_empty(cls, v):\n        assert v, \"empty tag\"\n        return v\n\n    @root_validator(skip_on_failure=True)\n    def passwords_match(cls, values):\n        if values.get(\"password\") != values.get(\"password_repeat\"):\n            raise ValueError(\"Passwords do not match\")\n        return values\n\nuser = User.parse_obj(data)\nuser.dict(); user.json(); user.copy()\nUser.from_orm(orm_obj)\n```\n\nAnd here is the same model after the migration to Pydantic v2:\n\n``` python\nfrom typing import Annotated, Optional\nfrom typing_extensions import Self\nfrom pydantic import BaseModel, ConfigDict, Field, field_validator, model_validator\n\nclass User(BaseModel):\n    model_config = ConfigDict(\n        from_attributes=True,          # was orm_mode\n        populate_by_name=True,         # was allow_population_by_field_name\n        str_strip_whitespace=True,     # was anystr_strip_whitespace\n        json_schema_extra={\"example\": {\"id\": 1, \"username\": \"kanwal\"}},  # was schema_extra\n    )\n\n    id: int\n    username: str\n    nickname: Optional[str] = None     # explicitly optional\n    tags: list[Annotated[str, Field(min_length=1)]] = []   # replaces each_item=True\n    password: str\n    password_repeat: str\n\n    @field_validator(\"username\")\n    @classmethod\n    def username_alphanumeric(cls, v: str) -> str:\n        if not v.isalnum():\n            raise ValueError(\"must be alphanumeric\")\n        return v\n\n    @model_validator(mode=\"after\")\n    def passwords_match(self) -> Self:\n        if self.password != self.password_repeat:\n            raise ValueError(\"Passwords do not match\")\n        return self\n\nuser = User.model_validate(data)\nuser.model_dump(); user.model_dump_json(); user.model_copy()\nUser.model_validate(orm_obj)            # replaces from_orm (needs from_attributes=True)\n```\n\nIt also explained what changed, step by step. First, `class Config` becomes `model_config = ConfigDict(...)`. The inner `Config` class is deprecated, and several settings were renamed:\n\n| v1 | v2 | \n|---|---|\n| `orm_mode` | `from_attributes` | \n| `allow_population_by_field_name` | `populate_by_name` (or`validate_by_name` from v2.11) | \n| `anystr_strip_whitespace` /`anystr_lower` /`anystr_upper` | `str_strip_whitespace` /`str_to_lower` /`str_to_upper` | \n| `min_anystr_length` /`max_anystr_length` | `str_min_length` /`str_max_length` | \n| `schema_extra` | `json_schema_extra` | \n| `validate_all` | `validate_default` | \n| `keep_untouched` | `ignored_types` | \n\nSecond, the methods on `BaseModel` were renamed. The old names still work but raise deprecation warnings. Third, `@validator` becomes `@field_validator`. Fourth, `@root_validator` becomes `@model_validator`. Lastly, `Optional[T]` no longer implies a default, which is a breaking change. In v2, `Optional[str]` with no default is required but accepts `None`. To keep the v1 behavior, write `Optional[str] = None`. This causes some of the most unexpected \"Field required\" errors after upgrading.\n\nProviding the library ID saves the agent from performing an additional library-resolution step.\n\nContext7 can match version-specific documentation when it is available in its index, but you should still verify that the returned material corresponds to the requested version.\n\n## Step 6: Installing Context7 as a Claude Code Plugin Instead\n\nContext7 also provides an official Claude Code plugin, which can be easier if you prefer managing integrations directly inside Claude Code.\n\nOpen Claude Code:\n\n```\nclaude\n```\n\nRun the following commands one at a time:\n\n```\n/plugin marketplace add upstash/context7\n/plugin install context7@context7-marketplace\n```\n\nRestart Claude Code and enter:\n\n```\n/mcp\n```\n\nSelect Context7 and follow the browser authentication process.\n\nThe plugin connects to the hosted Context7 MCP server and exposes the same documentation lookup tools. Unlike the CLI setup, the plugin does not require you to install Node.js or run `npx` locally.\n\nIt also supports browser-based sign-in without manually configuring an API key. You only need one working Context7 integration. There is no benefit to registering duplicate MCP servers.\n\n## Step 7: Configuring Context7 Manually With an API Key\n\nFor developers who prefer direct control, Context7 can also be installed manually.\n\nFirst, visit the [Context7 dashboard](https://context7.com/dashboard) and create an API key.\n\nThen run the following command in your terminal, replacing the placeholder with your key:\n\n```\nclaude mcp add \\\n  --scope user \\\n  --transport http \\\n  context7 https://mcp.context7.com/mcp \\\n  --header \"Authorization: Bearer YOUR_API_KEY\"\n```\n\nThis connects Claude Code to the hosted Context7 server and makes the integration available across your projects.\n\nAlternatively, you can run Context7 as a local MCP server using `npx`:\n\n```\nclaude mcp add --scope user context7 -- \\\n  npx -y @upstash/context7-mcp \\\n  --api-key YOUR_API_KEY\n```\n\nFor security, avoid putting actual API keys directly into shared configuration files, public repositories, or shell history. Prefer a secret manager or environment-variable-based configuration supported by your setup.\n\n## Final Thoughts\n\nContext7 does not replace testing, code reviews, or official documentation. However, it gives Claude Code a better starting point for generating code that matches the libraries you are actually using. I particularly like the ability to request documentation for specific library versions. It is useful when upgrading older projects or working with frameworks that frequently introduce breaking changes. You can learn more in the [Context7 documentation](https://context7.com/docs).\n\n \n\n \n\n**[**\\[Kanwal Mehreen\\](https://www.linkedin.com/in/kanwal-mehreen1/)**](https://www.linkedin.com/in/kanwal-mehreen1/)** is a machine learning engineer and a technical writer with a profound passion for data science and the intersection of AI with medicine. She co-authored the ebook \"Maximizing Productivity with ChatGPT\". As a Google Generation Scholar 2022 for APAC, she champions diversity and academic excellence. She's also recognized as a Teradata Diversity in Tech Scholar, Mitacs Globalink Research Scholar, and Harvard WeCode Scholar. Kanwal is an ardent advocate for change, having founded FEMCodes to empower women in STEM fields.", "url": "https://wpnews.pro/news/how-to-give-claude-code-up-to-date-documentation-with-context7", "canonical_source": "https://www.kdnuggets.com/how-to-give-claude-code-up-to-date-documentation-with-context7", "published_at": "2026-11-16 15:00:00+00:00", "updated_at": "2026-11-16 15:24:04.098679+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "agent-protocols", "developer-tools", "ai-products"], "entities": ["Context7", "Upstash", "Claude Code", "Anthropic", "LangChain", "Node.js", "Model Context Protocol"], "also_reported_by": [], "alternates": {"html": "https://wpnews.pro/news/how-to-give-claude-code-up-to-date-documentation-with-context7", "markdown": "https://wpnews.pro/news/how-to-give-claude-code-up-to-date-documentation-with-context7.md", "text": "https://wpnews.pro/news/how-to-give-claude-code-up-to-date-documentation-with-context7.txt", "jsonld": "https://wpnews.pro/news/how-to-give-claude-code-up-to-date-documentation-with-context7.jsonld"}}