Skip to content

How to Install and Setup OpenCode AI Assistant in VS Code

VS Code coding environment Photo by Afgprogrammer on Unsplash

I opened VS Code, searched for “OpenCode” in the extension marketplace, and found nothing. Then I tried running the install script in a regular terminal window - the extension didn’t show up in VS Code. After a few failed attempts and some documentation hunting, I figured out the right way to get OpenCode working inside VS Code.

The Problem: Multiple Wrong Paths

Here’s what tripped me up initially:

  1. OpenCode doesn’t have a traditional VS Code extension you download from the marketplace
  2. The extension installs automatically when you run OpenCode in the integrated terminal
  3. Running it in an external terminal doesn’t trigger the VS Code integration
  4. Different IDEs (VS Code, Cursor, Windsurf, VSCodium) need different CLI commands available

I wasted time trying to find a marketplace extension and running install commands in my regular terminal. Neither approach worked.

The Direct Answer

The simplest working method: open VS Code’s integrated terminal (Ctrl + ~), run opencode, and the extension installs automatically. But first you need OpenCode itself installed on your system.

Step 1: Install OpenCode on Your System

OpenCode has several installation options. I tried them all and here’s what works:

Official installation script
curl -fsSL https://opencode.ai/install | bash

This script detects your operating system and installs the right binary. It’s what the documentation recommends and it worked on my Mac without issues.

Method B: Node.js Package Managers

If you already use npm, bun, pnpm, or yarn, you can install through those:

Node.js package manager options
# npm
npm install -g opencode-ai
# bun (faster)
bun install -g opencode-ai
# pnpm
pnpm install -g opencode-ai
# yarn
yarn global add opencode-ai

I tested the npm method on a Linux machine and it worked fine. The bun method is noticeably faster if you have bun installed.

Method C: Homebrew (macOS/Linux)

Homebrew installation
# Use the official tap for latest version
brew install anomalyco/tap/opencode

Don’t use brew install opencode without the tap - that gave me an outdated version on my first attempt.

Method D: Windows Options

On Windows, I had to use different tools:

Windows installation options
# Chocolatey
choco install opencode
# Scoop
scoop install opencode

But here’s what I found works better on Windows: use WSL (Windows Subsystem for Linux). OpenCode feels more natural in a Unix-like environment. Inside WSL, just use the official script.

WSL installation (recommended for Windows)
# Inside WSL
curl -fsSL https://opencode.ai/install | bash

Step 2: Verify the Installation

Before moving to VS Code integration, verify OpenCode is actually installed:

Check OpenCode version
opencode --version

I got:

Version output
OpenCode v1.0.0

If you see a version number, OpenCode is ready. If you get command not found, something went wrong with the installation.

Step 3: Install the VS Code Extension

This is where I made my mistake. I ran opencode in my regular terminal (outside VS Code) and expected the extension to appear. It didn’t.

Here’s the correct process:

1. Open VS Code

Start VS Code normally and open any project folder.

2. Open the Integrated Terminal

Press Ctrl + ~ (Windows/Linux) or Cmd + ~ (Mac) to open VS Code’s integrated terminal. Or use the menu: View > Terminal.

3. Run OpenCode

Run OpenCode in VS Code integrated terminal
opencode

When you run this inside VS Code’s integrated terminal, OpenCode detects the IDE and installs its extension automatically.

4. Verify the Extension Installed

I checked by looking at VS Code’s extension panel (Ctrl+Shift+X) and searching “OpenCode”. The extension appeared with an “OpenCode” name after the automatic install.

What If the Extension Doesn’t Auto-Install?

This happened to me on one machine. Here’s the troubleshooting steps:

Check 1: Are You in the Integrated Terminal?

Terminal location matters
Running in:
External terminal (Terminal.app, iTerm2, Windows Terminal) → No extension install
VS Code integrated terminal (Ctrl + ~) → Extension auto-installs

OpenCode only detects VS Code when running inside its integrated terminal. The detection relies on environment variables that VS Code sets for its terminal.

Check 2: Is the IDE CLI Installed?

OpenCode needs to call your IDE’s command-line tool to install the extension. Check if your IDE CLI is available:

Check IDE CLI availability
# VS Code
code --version
# Cursor
cursor --version
# Windsurf
windsurf --version
# VSCodium
codium --version

If any of these return a version, the CLI is installed. If you get command not found, install the CLI.

Check 3: Install the IDE CLI

In VS Code, install the code command:

  1. Press Cmd+Shift+P (Mac) or Ctrl+Shift+P (Windows/Linux)
  2. Search for “Shell Command: Install ‘code’ command in PATH”
  3. Select it
VS Code command palette action
Shell Command: Install 'code' command in PATH

For Cursor and Windsurf, check their documentation for CLI installation. Both have similar shell command install options.

Check 4: Permissions

On macOS, I hit a permission issue once. VS Code needed permission to install extensions. Check VS Code’s settings:

VS Code settings.json
{
"extensions.autoUpdate": true,
"extensions.allowedExtensions": ["*"]
}

If allowedExtensions is restricted, OpenCode’s extension might be blocked.

Supporting Multiple IDEs

OpenCode works with more than just VS Code. I tested it with Cursor and Windsurf too.

IDE compatibility
IDE | CLI Command | Works With OpenCode
------------------|--------------|--------------------
VS Code | code | Yes
Cursor | cursor | Yes
Windsurf | windsurf | Yes
VSCodium | codium | Yes
Any terminal IDE | - | Terminal mode only

The process is identical for each: open the IDE’s integrated terminal, run opencode, and the extension installs automatically.

For Cursor:

Cursor integration
# In Cursor's integrated terminal
opencode

For Windsurf:

Windsurf integration
# In Windsurf's integrated terminal
opencode

Using OpenCode After Installation

Once the extension is installed, here’s what I got:

Code generation - Ask OpenCode to write functions, classes, or entire files.

Code explanation - Select code and ask “what does this do?”

Refactoring - “Refactor this function to be more readable”

Debugging help - “Why is this null pointer exception happening?”

Terminal commands - OpenCode can run shell commands through its MCP integration

The key difference from running OpenCode standalone: the VS Code integration lets OpenCode see your current file, selection, and project context. Running in a separate terminal would require manually providing that context.

Why This Installation Method Matters

OpenCode has over 140,000 GitHub stars and 6.5 million users according to the official site. That popularity comes with different installation preferences - npm users want npm installs, Homebrew users want brew installs, Windows users want Chocolatey.

But the VS Code extension install is consistent: run opencode in the integrated terminal. No matter how you installed OpenCode itself, the extension mechanism is the same.

Common Mistakes I Made

Mistake 1: External Terminal

WRONG: Running in external terminal
# In Terminal.app or iTerm2
opencode
# Extension doesn't install

The fix: always use VS Code’s integrated terminal (Ctrl + ~).

Mistake 2: Missing IDE CLI

Error when CLI is missing
OpenCode cannot find 'code' command
Please install the VS Code shell command

The fix: install the shell command via VS Code’s command palette.

Mistake 3: Old Homebrew Formula

WRONG: Generic brew install
brew install opencode
# Installed outdated version

The fix: use the official tap: brew install anomalyco/tap/opencode.

Summary

In this post, I walked through installing OpenCode and setting it up for VS Code. The key points:

  1. Install OpenCode first - Use the official script (curl -fsSL https://opencode.ai/install | bash) or your preferred package manager
  2. Open VS Code’s integrated terminal - Ctrl + ~ (not an external terminal)
  3. Run opencode - The extension installs automatically when OpenCode detects VS Code
  4. Verify the CLI - Make sure code, cursor, or windsurf commands are available
  5. Works with multiple IDEs - VS Code, Cursor, Windsurf, VSCodium all follow the same process

The whole process takes about 5 minutes once you know the right steps. Most of my wasted time came from running commands in the wrong terminal and expecting marketplace-style extension installation.

Final Words + More Resources

My intention with this article was to help others share my knowledge and experience. If you want to contact me, you can contact by email: Email me

Here are also the most important links from this article along with some further resources that will help you in this scope:

Oh, and if you found these resources useful, don’t forget to support me by starring the repo on GitHub!

Comments