MyBestToolsMyBestTools

Building LM Studio Copilot Expansion: Bringing Local LLMs to VS Code Chat

Cover Image for Building LM Studio Copilot Expansion: Bringing Local LLMs to VS Code Chat
Mike van der Sluis
Mike van der Sluis

Have you ever wanted to use your favorite local LLM—the ones running on your own hardware via LM Studio—directly within the VS Code Copilot Chat interface? While VS Code provides an incredible experience with GitHub Copilot, there is a growing desire among developers to use local models for privacy, cost-efficiency, or to experiment with specific models that might outperform general-purpose cloud models for certain tasks.

That's why I built LM Studio Copilot Expansion.

The Problem: The Gap Between Local Models and Cloud-First IDEs

VS Code's Chat interface is highly optimized for cloud-based models like GitHub Copilot. While it is incredibly powerful, it doesn't natively allow you to "plug in" a local server running an OpenAI-compatible API (like LM Studio) into the high-level Copilot Chat UI.

Usually, you'd have to use a different extension or a completely different workflow to interact with your local models. I wanted to bridge that gap.

The Solution: LM Studio Copilot Expansion

The LM Studio Copilot Expansion extension allows you to seamlessly integrate your local LM Studio models into the VS Code Copilot Chat model picker.

Once configured, your local models appear right alongside GitHub Copilot models, allowing you to switch between them with a single click.

Key Features

  • Seamless Integration: Your LM Studio models appear in the Copilot Chat model picker.
  • Streaming Support: No waiting for the whole response! Responses stream into the chat window just like GitHub Copilot.
  • Tool Calling: For models that support it, you can leverage the power of tool calling, making your local LLM much more capable within the IDE. How? Read this article
  • Local & Remote: It works whether LM Studio is running on your local machine or a powerful remote server accessible via an IP address.

How It Works (The Architecture)

To make this work seamlessly without bloating the VS Code extension itself, I implemented a hybrid architecture:

  1. The VS Code Extension (TypeScript): This is the "face" of the project. It handles the VS Code API interactions, manages the model list, and integrates with the Chat UI.
  2. The Backend Process (.NET 8): Because some of the complex logic (like handling the heavy lifting of the API communication and certain protocol details) is more efficiently managed in a managed runtime, I use a bundled .NET 8 backend process. This backend communicates with the VS Code extension and the LM Studio API.

By using a separate backend process, I ensure the extension remains responsive and can handle the intricacies of the communication protocols required to "trick" the VS Code chat UI into using a local model.

Getting Started

Getting up and running is incredibly simple:

  1. Install the extension from the VS Code Marketplace.
  2. Start LM Studio and load the model you want to use.
  3. Ensure the API Server is running in LM Studio (usually at http://localhost:1234).
  4. Open Copilot Chat in VS Code, select your LM Studio model from the picker, and start chatting!

Conclusion

The LM Studio Copilot Expansion is a testament to the power of the open AI ecosystem. By bridging the gap between local, private models and industry-standard IDE interfaces, I'm giving developers more choice, more privacy, and more flexibility in how they use AI to write code.

Happy coding (with your local models)!