Developing a Claude Code Addin for Visual Studio 2005
Introduction
Visual Studio 2005 (VS 2005) may feel dated compared to today’s modern IDEs, but it still serves a niche of legacy projects that require its specific toolchain. One powerful way to extend VS 2005 is through add‑ins written in .NET that hook into the IDE’s automation model. In this post we’ll walk through the process of building a VS 2005 add‑in that talks to Claude, the large‑language‑model (LLM) platform from Anthropic, allowing developers to generate, refactor, or explain code directly from the editor.
The complete source for the add‑in lives in the public Git repository:
https://git.flamenet.io/ezluzvaerus/ClaudeCodeAddin
Feel free to clone the repo, explore the implementation, and adapt it to your own workflow.
1. Prerequisites
| Requirement | Why It Matters |
|---|---|
| Visual Studio 2005 (Professional or higher) | Provides the extensibility SDK and the COM‑based automation model used by add‑ins. |
| .NET Framework 2.0 | VS 2005 targets this runtime; the add‑in must compile against it. |
| Anthropic API credentials | To send prompts to Claude and receive responses. |
| Internet connectivity | Required for each request to the Claude endpoint. |
| Git client | To clone the repository and manage future changes. |
Tip: Even though VS 2005 predates NuGet, you can still reference external DLLs manually (e.g.,
System.Net.Http.dllfor HTTP calls). The sample project includes a small wrapper library that abstracts the HTTP communication.
2. Project Layout
The repository follows a straightforward structure:
ClaudeCodeAddin/
│
├─ src/
│ ├─ ClaudeAddin/
│ │ ├─ AddIn.cs // Core add‑in class implementing IDTExtensibility2
│ │ ├─ Command.cs // Definition of the menu command that triggers Claude
│ │ └─ ClaudeClient.cs // Thin HTTP client for Anthropic’s API
│ └─ ClaudeAddinPackage/
│ └─ AssemblyInfo.cs
│
├─ resources/
│ └─ icons/ // Toolbar icons used by the add‑in
│
└─ README.md // Build instructions, usage guide, contribution notes
- AddIn.cs – Registers the add‑in with VS 2005, creates a new top‑level menu item under Tools → Claude, and wires the click event to our command handler.
- Command.cs – Retrieves the active document text, sends it to Claude, and inserts the returned snippet back into the editor.
- ClaudeClient.cs – Handles authentication, request serialization, and response parsing. It uses
HttpWebRequestto stay compatible with .NET 2.0.
3. Core Logic Overview
Below is a high‑level walkthrough of the interaction flow:
- User selects text (or places the cursor) and clicks Tools → Claude → Generate.
Command.Execute()extracts the selected code region via the DTE (EnvDTE) object.- The extracted snippet, together with a short prompt (e.g., “Refactor this C# method for readability”), is handed to
ClaudeClient.SendPromptAsync(). ClaudeClientbuilds a JSON payload conforming to Anthropic’s API spec, injects the API key from an environment variable (ANTHROPIC_API_KEY), and posts tohttps://api.anthropic.com/v1/complete.- Claude returns a JSON response containing the generated code.
- The add‑in parses the response, strips any surrounding markdown fences, and replaces the original selection with the new code.
- A status message appears in the VS 2005 status bar indicating success or any error encountered.
Key snippet from ClaudeClient.cs:
public string SendPrompt(string prompt, string codeSnippet)
{
var request = (HttpWebRequest)WebRequest.Create(ApiEndpoint);
request.Method = "POST";
request.ContentType = "application/json";
request.Headers["x-api-key"] = Environment.GetEnvironmentVariable("ANTHROPIC_API_KEY");
var payload = new {
model = "claude-v1",
prompt = $"{prompt}\n\n{codeSnippet}",
max_tokens_to_sample = 1024,
temperature = 0.2
};
var json = new JavaScriptSerializer().Serialize(payload);
using (var stream = request.GetRequestStream())
using (var writer = new StreamWriter(stream))
{
writer.Write(json);
}
using (var response = (HttpWebResponse)request.GetResponse())
using (var reader = new StreamReader(response.GetResponseStream()))
{
var respJson = reader.ReadToEnd();
dynamic result = new JavaScriptSerializer().DeserializeObject(respJson);
return result["completion"];
}
}
Security note: The API key is never hard‑coded; it must be supplied via an environment variable or a secure configuration file outside the repository.
4. Building the Add‑in
- Clone the repo
git clone https://git.flamenet.io/ezluzvaerus/ClaudeCodeAddin.git cd ClaudeCodeAddin/src/ClaudeAddin - Open the solution (
ClaudeAddin.sln) in VS 2005. - Set the target framework to .NET 2.0 (the default).
- Add a reference to
System.Web.Extensionsif you wish to useJavaScriptSerializer. - Build – the output will be
ClaudeAddin.dll. - Register the add‑in
- Copy
ClaudeAddin.dllto a folder of your choice, e.g.,C:\Program Files\ClaudeAddin\. - Open the Add‑in Manager in VS 2005 (
Tools → Add‑in Manager). - Click Add New Add‑in…, browse to the DLL, and confirm.
- Copy
- Restart VS 2005 – you should now see a Claude submenu under Tools.
5. Using the Add‑in
| Action | Steps |
|---|---|
| Generate code | Select a region → Tools → Claude → Generate. |
| Explain code | Select a region → Tools → Claude → Explain. The prompt sent to Claude will be “Explain what the following code does”. |
| Refactor | Place cursor inside a method → Tools → Claude → Refactor. Claude receives a prompt to improve readability and performance. |
The status bar will display messages such as “Claude: Generation successful (1.2 s)” or “Claude: Error – invalid API key”.
6. Extending the Add‑in
The sample implementation is intentionally minimal, leaving plenty of room for customization:
- Additional commands – Add menu items for unit‑test generation, doc‑string insertion, or security review.
- Rich UI – Replace the simple status‑bar feedback with a custom tool window that shows Claude’s full response, including explanations or alternative suggestions.
- Language support – Although the demo focuses on C#, the same pattern works for VB.NET, C++, or even plain text files. Adjust the prompt templates accordingly.
- Caching – Store recent Claude responses locally to reduce latency and API costs for repetitive queries.
Because the add‑in runs inside VS 2005’s process, keep performance considerations in mind: avoid blocking the UI thread during network calls. The sample already uses asynchronous patterns (BeginInvoke/EndInvoke) to keep the IDE responsive.
7. Testing & Debugging
- Unit tests – While VS 2005 doesn’t ship with a built‑in test runner, you can reference NUnit 2.x (compatible with .NET 2.0) to validate
ClaudeClientbehavior. - Logging – The repository includes a lightweight logger that writes to
%TEMP%\ClaudeAddin.log. Enable it by settingDEBUG=1in the environment. - Error handling – The add‑in catches
WebExceptionto surface HTTP errors (e.g., rate limits) in the status bar.