Skip to content

dirien/devcontainer-features

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DevContainer Feature: OpenCode

A Dev Container feature to install OpenCode by SST into your development environment.

Usage

Add the OpenCode feature to your devcontainer.json:

{
    "features": {
        "ghcr.io/dirien/devcontainer-features/opencode:0": {}
    }
}

Options

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.

Pin a specific version

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"
        }
    }
}

API Keys Configuration

This feature supports automatic configuration of API keys for OpenCode from a JSON file on your host machine.

Setup

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:

  1. Create a JSON file with your API keys on your host machine (e.g., ~/.opencode/auth.json or ${localWorkspaceFolder}/.opencode/auth.json)

  2. 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"
    ]
}

API Keys JSON Format

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

How it Works

  • The specified auth.json file from the host (typically from an existing OpenCode installation) is mounted to /tmp/opencode-auth.json in 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

Security Note

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.

About

devcontainers features

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages

  • Shell 100.0%