Originally published at gidadomukhta.me. Install it from the VS Code Marketplace or read the source on GitHub.
Most error messages are only half the story. A TypeScript message such as "Type 'string' is not assignable to type 'number'" tells you that two types disagree, but not which value caused it, which call produced it, or what the code around it is doing. To get a useful answer from an AI assistant, developers usually reconstruct that missing context by hand: they copy the message, find the line, scroll up to the function, and paste it all into a chat window. It works, but it's slow, and the result depends on how much context the developer remembered to include.
ErrorCopy: AI Error Explainer is a VS Code extension that automates that step. It reads the diagnostic directly from the editor, gathers the code around it, and builds a consistent prompt that you can send to the AI tool of your choice. This post explains what the extension captures, why it routes requests the way it does, how it handles privacy, and what its current limitations are.
What the extension captures
ErrorCopy reads the diagnostic from VS Code's language diagnostics API, not from text on the screen. That matters because the editor already holds structured information about each problem, and copying the visible text would throw most of it away. For the diagnostic under the cursor, the extension collects:
- The diagnostic message, its severity, and its source, such as TypeScript or ESLint
- The diagnostic code, when the language server provides one
- The exact range of the problem, rather than only the line number
- Related information that the language server attaches to the diagnostic
- Any text the developer has selected, so the prompt can point at the exact expression
- The surrounding code, limited to a configurable number of lines
- The language identifier and the line number
All of this is assembled into a Markdown prompt with fixed sections. Because the structure is the same for every error, the prompt reads the same whether it came from a compiler, a linter, or a language server, and the AI tool receives the same kind of input each time.
Two commands, one prompt
The extension has two entry points. Copy Error with Context, bound to Ctrl+Shift+E on Windows and Linux and Cmd+Shift+E on macOS, builds the prompt and places it on the clipboard. It doesn't send anything anywhere. Explain This Error does the same work, then opens a picker so you can choose a destination. Both use the same prompt builder, so the output is identical either way.
Why there are two kinds of destination
The providers fall into two groups, and the difference between them drives most of the design.
GitHub Copilot is handled through VS Code's Language Model API. The extension selects an available Copilot model, sends the prompt, and streams the response into a dedicated output channel called ErrorCopy Copilot. This keeps the answer inside the editor. It requires an active Copilot subscription, a signed-in VS Code account, and the user's permission for the extension to use the model. If no model is available, ErrorCopy keeps the prompt on the clipboard and tells the user what to do next, so the request isn't lost.
Copilot Web, Claude, and ChatGPT work differently. These sites don't offer an API that an extension can use to submit a prompt, and their chat inputs are controlled by the page itself. An extension can't reliably fill those fields, and any attempt to do so would break whenever the site changed its markup. So ErrorCopy copies the prompt, opens the site, and leaves the final paste to the user. It's one extra keystroke, but it's predictable, and it works with any account the user already has.
Stack Overflow is a third case. It isn't an AI provider. ErrorCopy builds a search from the diagnostic text and opens the results, because a large share of common errors already have accepted answers. Including it gives users a non-AI path when they want one.
The trade-off is clear. Copilot gives the most integrated experience, but only for users who have access to it. The browser providers work for everyone, but they require a manual step. Supporting both means the extension doesn't depend on a single vendor, and a new provider can be added to the same prompt pipeline without changing how diagnostics are collected.
Privacy and data handling
ErrorCopy has no backend. It doesn't store the user's code, it doesn't collect telemetry, and it doesn't call any AI service on its own behalf. The only time a prompt leaves the machine is when the user chooses a destination. If the user picks Copilot, the prompt goes to a model through VS Code's Language Model API. If the user picks a browser provider, nothing is sent until they paste the prompt into that site.
Before a prompt is built, the extension masks common secret patterns, including API keys, tokens, passwords, and Bearer credentials. Pattern-based masking is a safety net, not a guarantee. It can't recognise every secret format, so users should still read the prompt before sending it, especially when working in a codebase that holds real credentials.
File paths are excluded by default. A path can reveal a username, a company name, or the layout of a private repository, and none of that is needed to explain most errors. Users who want paths included can enable them in settings. The same setting governs any file locations that appear in related diagnostics, so the default applies consistently.
Configuration
Three settings control how much of the editor's content is shared:
-
errorCopy.includeFilePath, which is off by default, adds the file path to the prompt. -
errorCopy.includeSurroundingCode, which is on by default, includes the code around the error. -
errorCopy.maxContextLines, which defaults to 12 and can be set from 2 to 40, limits how many lines of surrounding code are included.
Together these let a developer decide how much code leaves the editor, from only the diagnostic message to a wider window of the file.
Engineering decisions
The extension is written in TypeScript against the VS Code API. Type checking catches mistakes in calls to the editor and the diagnostics API before the code runs, which matters because many of those mistakes would otherwise only show up inside the Extension Development Host.
The build uses esbuild to bundle the entry point, src/extension.ts, into a single CommonJS file, out/extension.js, targeting Node 20. The vscode module is marked as external, because VS Code supplies it at runtime and must not be bundled. A single output file keeps activation fast and keeps the package small.
Packaging is controlled by .vscodeignore. Source files, configuration, and tests are excluded, so the published package contains only the compiled bundle, the manifest, the README, the changelog, and the license. Before publishing, I confirmed the package contents by listing them, rather than assuming the ignore rules were correct.
One issue appeared only when the project was cloned onto a different machine. The build script referenced a Windows-specific path to the esbuild binary, so compilation failed elsewhere. I replaced that with a command that npm resolves on every platform. It's a small change, but it's the kind of problem that only shows up when someone other than the original author builds the project.
Current limitations
The extension has no automated tests that run inside the VS Code Extension Host yet. Validation so far combines type checking, a production build, packaging checks, and manual testing of the packaged extension. That's adequate for a first release, but it isn't a substitute for tests that exercise commands and diagnostics inside the editor, and adding them is the next priority.
Other limits are inherent to the design. The browser providers require a manual paste. Copilot access depends on the user's subscription and sign-in state. Secret masking is heuristic. And Ctrl+Shift+E captures only diagnostics the language server has reported, so an error printed in the terminal or raised at runtime is outside its scope.
What's next
The priorities for the next release are automated Extension Host tests, covering command registration, prompt content, clipboard fallback, and the Copilot path when no model is available. After that, the same prompt pipeline could support additional providers, and I'd like to refine the prompt structure based on the errors people actually send through it.
Try it and tell me what's missing
ErrorCopy: AI Error Explainer can be installed from the Extensions view in VS Code by searching for its name. The source code and issue tracker are on GitHub at github.com/gidadomukhtar/error-copy-pro.
If you try it, the most useful feedback is a specific case where the prompt didn't include the context you needed. Those cases show exactly where the prompt builder should improve.
Top comments (0)