Installation Guide
Relevant source files
The following files were used as context for generating this wiki page:OpenCode is an open-source AI coding agent designed to run directly from the terminal. It is provider-agnostic, allowing connections to various models including Claude, GPT, Gemini, and local models. This guide provides comprehensive instructions for installing the OpenCode CLI for regular use and setting up a local development environment for contributing to the project.
The installation process is designed to be straightforward, with options ranging from a direct curl script to various system-specific package managers. For developers, the setup involves installing dependencies with Bun and using provided scripts to build and run the application.
Standard Installation
There are multiple ways to install the OpenCode agent, depending on your operating system and preferences.
Universal Script (curl)
The recommended installation method for most Linux and macOS systems is using the provided curl script. This script automatically handles the download and placement of the OpenCode binary into an appropriate directory on your system's PATH.
curl -fsSL https://opencode.ai/install | bash
Sources: README.md:25-28, packages/console/app/src/routes/index.tsx:103-109
Installation Directory Logic
The installation script determines the installation path by checking for specific environment variables and directory existence in a prioritized order.
The following diagram illustrates the decision flow for selecting the installation directory.
Sources: README.md:33-39
The priority for the installation path is as follows:
| Priority | Path | Description |
|---|---|---|
| 1 | $OPENCODE_INSTALL_DIR | A custom installation directory specified by the user. |
| 2 | $XDG_BIN_DIR | A path compliant with the XDG Base Directory Specification. |
| 3 | $HOME/bin | The standard user binary directory. |
| 4 | $HOME/.opencode/bin | The default fallback directory. |
| Sources: README.md:33-39 |
You can override the default path by setting one of the environment variables before running the script:
# Example with OPENCODE_INSTALL_DIR
OPENCODE_INSTALL_DIR=/usr/local/bin curl -fsSL https://opencode.ai/install | bash
# Example with XDG_BIN_DIR
XDG_BIN_DIR=$HOME/.local/bin curl -fsSL https://opencode.ai/install | bash
Sources: README.md:41-43
Package Managers
OpenCode can also be installed via several popular package managers.
| Package Manager | OS / Environment | Command |
|---|---|---|
| npm | Any | npm i -g opencode-ai@latest |
| bun | Any | bun add -g opencode-ai |
| pnpm | Any | pnpm i -g opencode-ai@latest |
| yarn | Any | yarn global add opencode-ai@latest |
| Scoop | Windows | scoop bucket add extras; scoop install extras/opencode |
| Chocolatey | Windows | choco install opencode |
| Homebrew | macOS & Linux | brew install opencode |
| paru | Arch Linux | paru -S opencode-bin |
| mise | Any | mise use --pin -g ubi:sst/opencode |
| Nix | Any | nix run nixpkgs#opencode |
| Sources: README.md:25-31, packages/console/app/src/routes/index.tsx:111-149 |
Development Setup
For those who wish to contribute to OpenCode, a local development environment is required.
Prerequisites
- Bun: Version 1.3 or higher is required to manage dependencies and run scripts.
Sources: CONTRIBUTING.md:21
Core Repository Setup
The main setup process involves installing dependencies and starting the development server.
The following sequence diagram shows the steps for a developer to get the environment running.
- Install dependencies: From the root of the repository, run:
bun install - Start the dev server:
bun dev
Sources: CONTRIBUTING.md:24-25
Go SDK Setup
If you are working on the Go SDK, additional setup steps are required.
- Bootstrap Environment:
./scripts/bootstrap - Build the SDK:
./scripts/build
To use the local version of the Go SDK in another project, you must add a replace directive to your go.mod file.
go mod edit -replace github.com/sst/opencode-sdk-go=/path/to/opencode-sdk-go
Sources: packages/sdk/go/CONTRIBUTING.md:4-7, 26-27
Debugger Setup
Debugging with Bun has some caveats. The most reliable method is to run OpenCode manually and attach a debugger.
- Run the server with the
--inspectflag:bun run --inspect=<url> dev ... - For debugging the TUI and server breakpoints simultaneously, you may need to use
bun dev spawn. - You can set the
BUN_OPTIONSenvironment variable to avoid typing the inspect flag on every invocation:export BUN_OPTIONS=--inspect=ws://localhost:6499/
Sources: CONTRIBUTING.md:33-51
Build and Test Commands
The project contains several scripts for building, type-checking, and testing.
| Command | Description |
|---|---|
bun install | Install dependencies. |
bun run index.ts | Run the main application entry point. |
bun run typecheck | Run the TypeScript type checker. |
bun test | Run all tests. |
bun test test/tool/tool.test.ts | Run a specific test file. |
| Sources: packages/opencode/AGENTS.md:4-8 |