Claude in Visual Studio 2005

Bringing a modern AI coding assistant to a 20-year-old IDE.

Claude in Visual Studio 2005

Modern AI coding assistants are great if you work in a modern editor. I have a soft spot for old tooling, so I asked a different question: could Claude run inside Visual Studio 2005, an IDE that is twenty years old? It can. This post shows how the add-in is built and what it does.

One correction to the title I first used. The add-in talks to the Anthropic Messages API directly. It does not drive the Claude Code command line tool. The slug stays the same, so old links still work.

The add-in model

Visual Studio 2005 predates the VSIX extension format, which arrived with Visual Studio 2010. It uses the older COM add-in model. A .AddIn XML file names an assembly, and that assembly contains a class that implements IDTExtensibility2. The IDE loads the class and hands it the DTE automation object, which is the way into the editor, the solution and the output window.

The manifest is short. It names the host application and version (Visual Studio 8.0), a friendly name and description, the path to the assembly, and the full class name:

<Extensibility xmlns="http://schemas.microsoft.com/AutomationExtensibility">
  <HostApplication>
    <Name>Microsoft Visual Studio</Name>
    <Version>8.0</Version>
  </HostApplication>
  <Addin>
    <FriendlyName>Claude AI Assistant</FriendlyName>
    <Description>Send questions and code to Claude AI from within VS 2005</Description>
    <Assembly>C:\path\to\ClaudeCode.dll</Assembly>
    <FullClassName>ClaudeVS2005Addin.Connect</FullClassName>
    <LoadBehavior>1</LoadBehavior>
    <CommandPreload>1</CommandPreload>
    <CommandLineSafe>0</CommandLineSafe>
  </Addin>
</Extensibility>

IDTExtensibility2 has five methods: OnConnection, OnDisconnection, OnAddInsUpdate, OnStartupComplete and OnBeginShutdown. Four of mine are empty. All the work happens in OnConnection, which receives the application object, and in the command handler.

Adding a menu command

On the first run, OnConnection gets the mode ext_cm_UISetup. That is the moment to register a command and put it in a menu. I add one command, “Ask Claude…”, to the Tools menu:

public void OnConnection(object application, ext_ConnectMode connectMode,
                         object addInInst, ref Array custom)
{
    _application = (DTE2)application;
    _addInInstance = (AddIn)addInInst;

    if (connectMode == ext_ConnectMode.ext_cm_UISetup)
    {
        Commands2 commands = (Commands2)_application.Commands;
        CommandBar menuBar = ((CommandBars)_application.CommandBars)["MenuBar"];
        CommandBarPopup toolsPopup =
            (CommandBarPopup)menuBar.Controls["Tools"];

        object[] contextUIGuids = new object[] { };
        try
        {
            Command command = commands.AddNamedCommand2(
                _addInInstance, "AskClaude", "Ask Claude...",
                "Send selected code or a question to Claude AI",
                true, 59, ref contextUIGuids,
                (int)vsCommandStatus.vsCommandStatusSupported +
                (int)vsCommandStatus.vsCommandStatusEnabled,
                (int)vsCommandStyle.vsCommandStylePictAndText,
                vsCommandControlType.vsCommandControlTypeButton);
            command.AddControl(toolsPopup.CommandBar, 1);
        }
        catch (ArgumentException) { /* the command already exists */ }
    }
}

The try block matters. Visual Studio remembers commands between sessions, so the second registration throws an ArgumentException, and the add-in has to ignore it.

Reading the selection

The class also implements IDTCommandTarget. Its Exec method runs when you pick the menu item. It reads the selected text from the active document through the DTE object:

TextSelection sel = (TextSelection)_application.ActiveDocument.Selection;
string selectedCode = sel.Text != null ? sel.Text : string.Empty;

That string goes into a small Windows Forms dialog as the starting text. You edit it, add a question, and pick a model from a drop-down. The list of model names is a plain string array at the top of the file, so adding a model is a one-line change. The dialog remembers your last choice for the rest of the session.

Calling the API from .NET 2.0

This is where the age of the platform shows. Visual Studio 2005 targets .NET Framework 2.0 and C# 2.0. There is no LINQ, no lambda syntax, no async, and no JSON library in the box. The request is built with string.Format, and the response is read with HttpWebRequest.

Three details matter. The Anthropic API requires TLS 1.2, and the .NET 2.0 enum has no member for it, so I cast the number: (SecurityProtocolType)3072. I escape backslashes, quotes and line breaks by hand before putting the prompt in the request body. And I parse the reply with a small loop that finds the first "text":" marker and unescapes characters until the closing quote. It is a hack, but it handles a text reply and needs no library.

The request itself is a POST to the Messages API with the anthropic-version and x-api-key headers, a model name, a token limit and one user message. The key lives in a constant in the source file. That is fine for a toy on a private machine, and a bad idea for anything shared. Keep your key out of any repository you publish.

Showing the answer

The reply opens in a second dialog with a read-only text box in a fixed-width font, a Copy to Clipboard button and a Close button. The add-in does not write the answer back into the editor. It opens in the dialog, so the add-in never changes your file and you choose what to paste.

Why bother

It is gloriously cursed, and it works: AI-assisted coding inside an IDE older than some of my coworkers. The AI part is the easy part. The hard part is coaxing a 2005-era extensibility API into doing something it was never designed for.

The source is on GitLab, in the userscripts project, folder vs2005-claude-code-addin.

Subscribe to Just another Geek

Don’t miss out on the latest issues. Sign up now to get access to the library of members-only issues.
jamie@example.com
Subscribe