Supercharge your workflow: Run OpenCode directly inside your VSCode terminal using Docker and Remote Containers for a clean, isolated, and highly reproducible AI development environment.
| Benefit | Description |
|---|---|
| 🛡️ Isolation | No dependencies pollute your host machine |
| 🔄 Consistency | Same environment across all users and contributors |
| 🔒 Security | Sandboxed environment that is easy to revoke |
| 📌 Version Control | Pin specific OpenCode versions with ease |
| 💻 Cross-Platform | Works identically on Windows, Mac, and Linux |
| 🧹 Clean State | Start fresh every time, no accumulated junk |
| Limitation | Description |
|---|---|
| 📁 File Access | Only files in mounted directories are accessible |
| ⚡ Performance | Slight overhead compared to native execution |
| 🐳 Docker Required | Must have Docker installed and running |
| 🖥️ No GUI Apps | Strictly a terminal-only interface |
| 📈 Resource Usage | Consumes memory/CPU for container runtime |
- Visual Studio Code
- Docker Desktop / Engine
- GitHub Account
git clone https://github.com/2241812/OpenCode-VSCode-Setup.git
cd OpenCode-VSCode-Setup
code .Install the Dev Containers extension (published by Microsoft):
- Open VSCode Extensions (
Ctrl+Shift+X) - Search for "Dev Containers"
- Click Install
After installing:
- VSCode will prompt "Reopen in Container" - click it
- Wait for the container to build (~2-3 min first time)
Open the integrated terminal (Ctrl+`) and run:
opencodeThat's it! Use OpenCode however you want - ask questions, write code, debug, etc.
The Dockerfile sets up a complete OpenCode environment:
| Step | What It Does |
|---|---|
| 1 | Creates devuser - a non-root user for security |
| 2 | Pre-creates config directories (~/.config/opencode, ~/.local/share/opencode, ~/.ssh) |
| 3 | Installs OpenCode via the official install script |
| 4 | Sets up PATH to include OpenCode binaries |
.
├── .devcontainer/
│ └── devcontainer.json # Dev Container configuration
├── .vscode/
│ ├── settings.json
│ └── extensions.json
├── docs/
│ ├── AGENTS.md
│ ├── DOCKER.md
│ └── QUICKSTART.md
├── Dockerfile # Build your own OpenCode image
├── docker-compose.yml # Easy container management
└── README.md
Before using OpenCode, you need to connect an AI provider:
opencode
/initThen run /connect to add your API key. Or set environment variables:
Create a .env file in the project root:
OPENAI_API_KEY=sk-your-key-hereWhat is it?
Remote Containers lets you open any folder inside a Docker container as your workspace in VSCode. Your entire development environment—including OpenCode—runs securely inside the container.
Benefits:
- Seamless integration: Terminals, extensions, and the file system work naturally
- Multiple containers: Easily switch between isolated project environments
- Persistent settings: Extensions and preferences are saved per container
If you prefer to run without VS Code Remote Containers:
Using docker-compose:
cp .env.example .env
# Add your API key to .env
docker-compose upOr build and run manually:
docker build -t opencode-dev .
docker run -it --rm -v $(pwd):/workspace -w /workspace opencode-devThen run opencode in the terminal.
Looking to swap out or configure different models? Check out the detailed Agents Setup Guide.
This project is licensed under the MIT License. This means you are free to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the software, provided you include the original copyright notice and permission notice. See the LICENSE file for more details.