
The Problem: Your Coding Agent Is Confidently Guessing
Your coding agent is guessing about libraries, and it sounds completely confident while it does it. You ask for something small, like adding streaming to a route, and it writes a function that looks right. The imports look right, the naming looks right. Then you run it and it blows up because that part of the API moved eight months ago.
The model isn't lying to you. It learned that library at a point in time, and the library moved on.
So what's the fix? Give your agent live documentation search. In the middle of a task, when it hits a library it isn't sure about, it stops, reads the current docs that the maintainers actually wrote, and then writes code off that instead of off memory.
There are two ways to wire this in: an MCP server and a CLI. I'll show you both, which one I use for what, and the two lines I put in my claude.md so it fires every single time.
Where the Wrong Answer Actually Comes From
Before wiring anything up, it's worth understanding where the wrong answer comes from, because there are three places and I've been burned by all three.
The Model's Training Data
The first one is the model itself. Whatever it knows about a library, it learned on a particular day, and that day is in the past. That's completely fine for stuff that never changes. For a fast-moving library, a year is a very long time. And the model doesn't tell you it's unsure. It just writes.
Your Own Stale Notes
The second one is the part people don't want to hear: the notes you wrote yourself. You get burned once, so you write the correct pattern down by hand into your rules file. For about three months, that's genuinely great. Then the library ships a change and your file doesn't.
Now the agent isn't guessing anymore. It's following your instructions perfectly and confidently, and your instructions are out of date. That is genuinely worse than having nothing. With nothing, the agent might hesitate or ask you. With a stale note, it just goes.
Web Search Fallback
The third one is web search, which is what most agents fall back to. There are two problems there. First, it takes whatever it lands on: a GitHub issue from 2023, somebody's blog post, a random forum answer. You have no idea what's in it, and neither does your agent.
Second is cost. A web search pulls an entire page into your context window: the navbar, the cookie banner, the author's life story, all of it.
What you actually want is narrower than any of those. You want the agent to read the current documentation for the one library it's working with, at the exact moment it needs it, and get back only the part that answers the question.
Context7: A Documentation Layer for Coding Agents
That's what Context7 is. It's free to get started with, and the way I'd describe it is a documentation layer for coding agents. It indexes over 130,000 libraries, with sources added by users and the community, and it pulls from what the project owners wrote, not from a blog.
Every snippet gets scanned for malware and prompt injections before it ever reaches your agent. That's the part people skip past, and it matters a lot more once you're letting an agent pull text off the internet in the middle of a task.
The other half of it is that it gives you snippets, not pages. Instead of dragging an entire documentation site into your context window, it returns the handful of pieces that answer the actual question. Their benchmark puts it at 34% cheaper and 37% fewer tokens than web search. You feel that one, because your context window is the thing that's genuinely scarce.
Before setting anything up, grab the API key first. It takes about 30 seconds: go to context7.com, sign in, grab the key. You get 1,000 calls a month on the free tier, which is plenty. I'll show you exactly what goes wrong if you skip this, because it's not what you'd expect.
Setting Up the MCP Server
The way I run this day to day is as an MCP server, because that's the version where the agent can reach for it on its own in the middle of a task without me doing anything.
It's one command:
claude mcp add --scope user --header authorization bearer YOUR_API_KEY --transport http context7 https://mcp.context7.com/mcp
The --scope user part means it's on for every project on my machine, not just one. That's what you want for something like this.
If you'd rather not type all that out, there's also an interactive setup:
npx ctx7@latest setup --mcp --claude
It does the same thing and writes the config for you. The same setup exists for Cursor, Codex, OpenCode, and AntiGravity. This isn't a Claude Code only thing. It's one of the most used MCP servers across all of them, and the repo is sitting at over 62,000 stars.
The Two Tools That Make It Work
Once the server is connected, there are two tools, and the whole thing is basically these two steps.
The first one resolves a library. The agent hands it a name like "AI SDK," and it comes back with the actual matching libraries in the index, how many snippets each one has, and the repo behind it. The agent picks one.
The second one queries the docs for that library with a real question attached, not just a library name. It's not dumping the manual on you. It's asking a question against the manual.
That two-step thing is why this works. The agent isn't searching the internet. It's pinning down exactly which library it's talking about first, and only then asking.
The CLI: When You Want to Check It Yourself
There's a second way to use this: the CLI. I use it more than I expected to. Same index, same docs, but you're the one running it.
It's the same two steps. First, resolve:
npx ctx7@latest library "AI SDK streaming responses with embeddings in a Next.js app router project"
Notice I'm not just passing the name. I'm passing what I'm actually trying to do, because that's the thing that ranks the results. It comes back with candidates, and you grab the library ID.
Then ask for the docs:
npx ctx7@latest docs /vercel/ai "How do I stream a response and pass the sources through?"
One small thing that will trip you up: that library ID needs the slash at the front. It's /vercel/ai, not vercel/ai. If you skip the resolve step and just type the library name straight into the docs command, it's going to fail.
The way I split these two is simple. MCP is for when I want the agent making the call on its own in the middle of a task, which is most of the time. The CLI is for when I want to check something myself before I let the agent anywhere near it, or when I want to pull docs inside a script or a hook where I don't want an MCP server involved at all. Same docs either way.
A Real Job: Embeddings and Streaming on a Live Project
Let me show you what's actually on my machine, because everything here runs on a real project. I've made a couple hundred videos on this channel, and there are thousands of comments sitting under them. All of that is basically a pile of information I can't search. Somebody asks me in the comments, "have you covered this?" and honestly, half the time I can't remember.
So this app pulls in the transcript of every video I've made plus the comments, puts it all in one place, and the whole point is that I can ask it a question and it tells me what I've already said and where. Next.js on the front end, Supabase for the database.
The job for today is the part that actually makes it useful: the search itself. I want to type a real question, have it look across everything, and stream an answer back with the video and the timestamp it came from.
That job is exactly the kind of job where embeddings and streaming are the two things that move the most. It's the fastest-moving part of the whole stack, and it's the part the model is most likely to be a year behind on.
Watching the Lookup Happen Live
Clean session, no hints, and I'm asking for the whole thing. Embed the transcripts, search across all of them, and stream the answer back with the video and timestamp.
It reads the project, works out what it needs, and then it hits the AI SDK. Instead of just writing, it stops and calls the resolve tool. The candidates come back with snippet counts and repos. That's the part I like: it's telling me exactly where this is about to come from. It's not making anything up, and I can see the source before a single line of code gets written.
Then it queries the docs. It's not asking for "the AI SDK." It's asking how to stream a response and attach the sources, which is the actual thing I asked for. The snippets come back, and then it writes. That right there is the current API, not the one from a year ago. The one that's in the docs right now, this week.
The type check passes, which is the rule sitting in my claude.md. Then I actually use the thing. I ask it what I've already said about setting up MCP servers, and there it is: streaming, pulling the actual moments out of my own videos. Now when somebody asks me in the comments whether I've covered something, I can just look.
What changed here isn't that the model got smarter. It's exactly the same model on exactly the same project with exactly the same prompt. I just stopped making it guess. It went and read, and then it wrote.
The Two Lines That Make It Fire Every Time
Here's the honest part: it will not always do that on its own. Sometimes it decides it already knows, skips the lookup, and writes from memory. Then you're right back where you started.
So this is what I put in my claude.md. It's two lines:
- Before writing code against any external library, resolve the library and pull the current docs first. Never assume you already know the API.
- If the docs come back empty, stop and tell me. Don't write the code anyway.
That second line is doing a lot more work than it looks like.
If you just want to force it on a single prompt without touching any files, you can also just say it: "Use Context7." Put that at the end of your prompt and it'll go and look. That's the manual override, and it's what I use whenever I'm testing something and want to be sure the lookup actually happened.
What Happens When You Skip the API Key
Remember when I said to grab the API key first? Here's why.
You can run this without a key and it works, which is fine for trying it out. But those limits are enforced, and they're deliberately not published. You don't get a warning before you hit one.
The annoying part is what it looks like when you do. It doesn't come back with a big red error. It just comes back with nothing. If you run the CLI and get an empty result, or the docs look thin and half-finished, that's almost certainly what happened. It's not broken, and it's not you.
Now think about what that looks like when it happens to your agent instead of happening to you in the terminal. The agent asks for the docs, gets nothing back, reads "nothing" as "those docs don't exist," and quietly falls back to whatever it already thought it knew. That's the exact problem we came here to fix, except now it's invisible, because from the outside it just looks like the agent answered.
That's the whole reason for that second line in the claude.md. It turns a silent wrong answer into a question, and a question I can deal with.
What This Doesn't Do Well
One more thing this does not do well, and I'd rather you hear it from me now than find out in the middle of a build.
The index is big, but it is not everything. Your company's internal library is not in there. A framework that shipped last week might not be in there yet. For smaller, more obscure libraries, the index can lag behind a release. The popular stuff is current; the niche stuff can be a little bit behind.
The way I'd put it: this is the fix for the libraries you're actually using every day. Next.js, Supabase, the AI SDK. The ones that move fast enough to break you. For an internal library, you're still writing that one down yourself, and that's fine, because your internal library isn't shipping a breaking change every six weeks.
Key Takeaways
- Your agent guesses from stale training data, and it sounds confident while doing it. The model learned the library at a point in time, and the library moved on.
- Your own notes go stale too. A stale note is worse than no note, because the agent follows it perfectly and confidently without hesitation.
- Web search is expensive and unreliable. It pulls entire pages into your context window, including the navbar, the cookie banner, and the author's life story.
- Context7 returns snippets, not pages. The agent resolves the exact library first, then asks a real question against the current docs. It's 34% cheaper and 37% fewer tokens than web search.
- Grab the API key before you start. Without it, you hit unpublished limits and get empty results with no warning, which makes the agent silently fall back to guessing.
- Two lines in claude.md fix the silent failure mode. Always resolve and pull current docs before writing code, and if the docs come back empty, stop and tell me.
The Thing That Actually Surprised Me
The thing that actually surprised me here wasn't the token numbers. It was that I stopped writing library notes to myself.
For months, I had a folder of little files where I'd written down the correct way to do things. Every single one of them was a to-do list I was quietly ignoring, because I knew some of them had gone stale and I didn't know which ones.
Now the agent just goes and reads. The knowledge is current by default, instead of current on the day that I wrote it down. That is a completely different relationship with your own setup.
If you're writing real code with an agent against libraries that move, which is most libraries, I highly recommend setting this up. If you're a beginner, it's probably worth more to you, not less, because you're the one who can't tell the difference between a current API and a dead one until it blows up in your face. If you're doing client work, this is the difference between shipping and spending your evening debugging code that was never going to run. And if you're on a team, this is how you stop six different people's agents writing against six different versions of the same library.
Everything I use here is free to get started with. Context7 is at context7.com. The MCP command is one line, and the CLI is npx ctx7@latest. Point it at whatever library you've been fighting with this week, run one of your own real jobs through it, and watch the lookup happen for yourself.
