A Dev Container feature to install OpenCode by SST into your development environment.
Add the OpenCode feature to your devcontainer.json:
{
"features": {
"ghcr.io/dirien/devcontainer-features/opencode:0": {}
}
}| Option | Type | Default | Description |
|---|---|---|---|
version |
string | latest |
Version of opencode to install (e.g., 1.2.27). Set to latest to fetch the latest version from GitHub. |
Pinning a version avoids hitting the GitHub API during installation, which can fail due to rate limiting (60 requests/hour for unauthenticated requests):
{
"features": {
"ghcr.io/dirien/devcontainer-features/opencode:0": {
"version": "1.2.27"
}
}
}This feature supports automatic configuration of API keys for OpenCode from a JSON file on your host machine.
Most users will already have an auth.json file from their existing OpenCode installation on the host. Mount that file to the container:
{
"features": {
"ghcr.io/dirien/devcontainer-features/opencode:0": {}
},
"mounts": [
"source=${localEnv:HOME}/.local/share/opencode/auth.json,target=/tmp/opencode-auth.json,type=bind,consistency=cached"
]
}If you don't have an existing auth.json file or want to use a different location:
-
Create a JSON file with your API keys on your host machine (e.g.,
~/.opencode/auth.jsonor${localWorkspaceFolder}/.opencode/auth.json) -
Configure the mount in your
devcontainer.json:
{
"features": {
"ghcr.io/dirien/devcontainer-features/opencode:0": {}
},
"mounts": [
"source=${localWorkspaceFolder}/.opencode/auth.json,target=/tmp/opencode-auth.json,type=bind,consistency=cached"
]
}Your auth.json file should follow the standard OpenCode format with provider-specific configurations:
{
"anthropic": {
"type": "api",
"key": "your-anthropic-api-key"
},
"openai": {
"type": "api",
"key": "your-openai-api-key"
},
"openrouter": {
"type": "api",
"key": "your-openrouter-api-key"
}
}During installation, this file will be copied to: ~/.local/share/opencode/auth.json
- The specified auth.json file from the host (typically from an existing OpenCode installation) is mounted to
/tmp/opencode-auth.jsonin the container - During installation, the file is copied to
/home/${remoteUser}/.local/share/opencode/auth.json - The target directory is created if it doesn't exist
- If no auth file is mounted, API keys configuration is skipped
Ensure your auth.json file is not committed to version control. If you're referencing an existing file from your host OpenCode installation, make sure it contains the API keys you want to use in the dev container. Consider adding it to your .gitignore file if it's in your workspace.