Skip to content
| Marketplace
Sign in
Visual Studio Code>Programming Languages>Ollama AINew to Visual Studio Code? Get it now.
Ollama AI

Ollama AI

Rivan Mota

|
367 installs
| (0) | Free
AI-powered coding assistant with built-in Ollama server support. Generate code, explain code, refactor, and chat with AI models like Mistral, Llama 2, and more.
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Ollama AI - VS Code Extension

Version Downloads Rating

AI-powered coding assistant with built-in Ollama server support. Generate code, explain code, refactor, and chat with AI models like Mistral, Llama 2, and more.

🚀 Features

  • 🤖 AI Code Generation: Generate code from natural language descriptions
  • 💬 Interactive Chat: Chat with AI models directly in VS Code
  • 🔧 Code Explanation: Get detailed explanations of your code
  • 🔄 Code Refactoring: Automatically refactor and improve your code
  • 🐛 Code Fixing: Identify and fix issues in your code
  • ⚡ Built-in Server: No need to install Ollama separately
  • 🎯 Multiple Models: Support for Mistral, Llama 2, Code Llama, and more
  • 📁 File Creation: Generate complete files with AI assistance

🎯 Quick Start

  1. Install the Extension

    • Search for "Ollama AI" in VS Code Extensions
    • Click Install
  2. Enable Built-in Server (Optional)

    {
      "ollama.useBuiltInServer": true
    }
    
  3. Start Chatting

    • Press Ctrl+Shift+P and run "Ollama: Open Chat Panel"
    • Ask the AI to help with your code!

📋 Commands

Command Description Shortcut
ollama.startModel Start an Ollama model -
ollama.stopModel Stop the current model -
ollama.chat Quick chat with the model -
ollama.generateCode Generate code from description -
ollama.explainCode Explain selected code -
ollama.refactorCode Refactor selected code -
ollama.fixCode Fix issues in selected code -
ollama.openChatPanel Open the chat panel (default: right panel) -
ollama.openChatPanelRight Open the chat panel in the rightmost panel -
ollama.openChatPanelBeside Open the chat panel beside the current editor -
ollama.pullModel Pull a model from Ollama -
ollama.listModels List available models -
ollama.checkModelStatus Check if a model is currently running -
ollama.startBuiltInServer Start the built-in Ollama server -
ollama.stopBuiltInServer Stop the built-in Ollama server -
ollama.checkServerStatus Check if any Ollama server is running -

⚙️ Configuration

Add these settings to your VS Code settings:

{
  "ollama.serverUrl": "http://localhost:11434",
  "ollama.defaultModel": "mistral",
  "ollama.maxTokens": 2048,
  "ollama.temperature": 0.7,
  "ollama.autoStart": true,
  "ollama.autoOpenChat": true,
  "ollama.keepModelRunningOnBlur": true,
  "ollama.stopModelOnPanelClose": false,
  "ollama.defaultChatPanelLocation": "right",
  "ollama.openFileInNewTab": true,
  "ollama.openFileAfterCreation": true,
  "ollama.refocusChatAfterFileCreation": false,
  "ollama.useBuiltInServer": false
}

Settings Explained

  • ollama.serverUrl: URL of your Ollama server (default: http://localhost:11434)
  • ollama.defaultModel: Default model to use (default: mistral)
  • ollama.maxTokens: Maximum tokens for responses (default: 2048)
  • ollama.temperature: Temperature for model responses, 0.0-1.0 (default: 0.7)
  • ollama.autoStart: Automatically start the default model when VS Code starts (default: true)
  • ollama.autoOpenChat: Automatically open the chat panel in the right panel when VS Code starts (default: true)
  • ollama.keepModelRunningOnBlur: Keep the model running when the chat panel loses focus (default: true)
  • ollama.stopModelOnPanelClose: Stop the model when the chat panel is closed (default: false)
  • ollama.defaultChatPanelLocation: Default location for the chat panel (default: "right", options: "left", "center", "right", "beside")
  • ollama.openFileInNewTab: Open created files in a new tab instead of replacing the current editor (default: true)
  • ollama.openFileAfterCreation: Automatically open files after they are created by the AI (default: true)
  • ollama.refocusChatAfterFileCreation: Refocus the chat panel after creating a file (useful to maintain chat history) (default: false)
  • ollama.useBuiltInServer: Use built-in Ollama server instead of external server (default: false)

Note: The chat panel now opens in the right panel by default. You can change this behavior using the ollama.defaultChatPanelLocation setting.

🤖 Supported Models

The extension works with any model available in Ollama. Popular models include:

  • Mistral: High-performance open model (default)
  • GPT-OSS: Open-source GPT model
  • Llama 2: Meta's large language model
  • Code Llama: Specialized for code generation
  • Phi-2: Microsoft's small but powerful model
  • Gemma: Google's open model

🔧 Built-in Ollama Server

The extension now supports a built-in Ollama server, eliminating the need to install and run Ollama separately.

Features

  • ✅ Automatic Server Management: Starts and stops the server automatically
  • ✅ Cross-Platform Support: Works on Windows, macOS, and Linux
  • ✅ Fallback Support: Falls back to external server if built-in fails
  • ✅ Easy Configuration: Simple toggle in settings

Setup

  1. Enable Built-in Server:

    {
      "ollama.useBuiltInServer": true
    }
    
  2. Install Ollama Binary (if not included in extension):

    • Download Ollama from ollama.ai
    • Place the binary in the extension's bin directory
    • Or use the external server option
  3. Start the Server:

    • Use command: Ollama: Start Built-in Server
    • Or let the extension start it automatically

Commands

  • ollama.startBuiltInServer: Start the built-in server
  • ollama.stopBuiltInServer: Stop the built-in server
  • ollama.checkServerStatus: Check server status

Benefits

  • No Manual Installation: No need to install Ollama separately
  • Automatic Management: Server starts/stops with VS Code
  • Isolated Environment: Doesn't interfere with system Ollama
  • Easy Setup: One-click server management

🎯 Usage Examples

Code Generation

  1. Right-click in the editor
  2. Select "Ollama: Generate Code"
  3. Describe what you want to create
  4. AI generates the code for you

Code Explanation

  1. Select code in the editor
  2. Right-click and select "Ollama: Explain Code"
  3. Get detailed explanations

Interactive Chat

  1. Open the chat panel
  2. Ask questions about your code
  3. Get AI assistance in real-time

File Creation

In the chat panel, try:

  • "Write a hello world in typescript in main.ts"
  • "Create a React component in App.jsx"
  • "Generate a Python function in utils.py"

🛠️ Troubleshooting

Model Not Found

If you get a "Model not found" error:

  1. Make sure Ollama is running: ollama serve
  2. Pull the model: ollama pull <model-name>
  3. Check available models: ollama list

Connection Issues

If you can't connect to Ollama:

  1. Verify Ollama is running: ollama serve
  2. Check the server URL in settings
  3. Ensure no firewall is blocking port 11434

Performance Issues

  • Use smaller models for faster responses
  • Reduce maxTokens setting for shorter responses
  • Lower temperature for more focused outputs

Model Stops When Panel Loses Focus

If the model stops running when you switch to another tab or panel:

  1. Check the ollama.keepModelRunningOnBlur setting (should be true by default)
  2. The model will now stay running when the chat panel loses focus
  3. You can manually stop the model using the "Stop Model" button or command
  4. If you want the model to stop when the panel is closed, set ollama.stopModelOnPanelClose to true

Chat History Lost When Creating Files

If the chat history is lost when the AI creates files:

  1. Set ollama.openFileInNewTab to true (default) to open files in separate tabs
  2. Set ollama.refocusChatAfterFileCreation to true to automatically return to the chat panel
  3. The chat panel will maintain its history and position
  4. Files will open in new editor tabs without affecting the chat interface

🚀 Development

Building the Extension

# Install dependencies
npm install

# Compile TypeScript
npm run compile

# Watch for changes
npm run watch

# Run tests
npm test

Project Structure

src/
├── extension.ts          # Main extension entry point
├── ollamaClient.ts       # Ollama API client
├── ollamaServer.ts       # Built-in server management
├── chatPanel.ts          # Chat interface
└── codeGenerator.ts      # Code generation utilities

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

📄 License

MIT License - see LICENSE file for details

🆘 Support

  • Issues: Report bugs and request features on GitHub
  • Documentation: Check the README and inline comments
  • Community: Join the VS Code extension community

🙏 Acknowledgments

  • Ollama for providing the AI models
  • VS Code for the excellent extension platform
  • The open-source community for inspiration and contributions

Made with ❤️ for the developer community

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft