OpenCode plugin for isolated branch workspaces using devcontainers or git worktrees.
Note: This is a community project and is not built by or affiliated with the OpenCode team.
Version 0.x - Pre-1.0 software. Minor versions may contain breaking changes.
When working on multiple branches, you need isolated development environments:
This plugin provides both options with:
Add to your ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-devcontainers"]
}
OpenCode automatically installs npm plugins on startup.
devcontainer CLI - Install with: npm install -g @devcontainers/cli/devcontainer feature-x # Start/target a devcontainer for this branch
/devcontainer myapp/main # Target specific repo/branch
/devcontainer # Show current status
/devcontainer off # Disable, run commands on host
When a devcontainer is targeted:
HOST: to force host execution/worktree feature-x # Create/target a worktree for this branch
/worktree myapp/main # Target specific repo/branch
/worktree # Show current status
/worktree off # Disable, run commands in original directory
When a worktree is targeted:
HOST: prefix for escaping/workspaces # List all workspaces (clones + worktrees)
/workspaces cleanup # Find stale workspaces (not used in 7+ days)
| Use Case | Recommendation |
|---|---|
| Project has devcontainer.json | /devcontainer |
| Different dependencies per branch | /devcontainer |
| Quick branch work, same deps | /worktree |
| No Docker or Podman available | /worktree |
| Testing migrations/databases | /devcontainer |
~/.config/opencode/devcontainers/config.json:
{
"portRangeStart": 13000,
"portRangeEnd": 13099,
"dockerPath": "podman",
"dockerComposePath": "podman-compose"
}
dockerPath and dockerComposePath are optional. When unset, the plugin uses Docker when available, otherwise Podman. A Podman runtime requires either podman-compose or docker-compose; the plugin detects one automatically and reports an unsupported configuration when neither is available. Set both paths explicitly to use nonstandard executable locations.
~/.local/share/opencode/clone/<repo>/<branch>/devcontainer up~/.local/share/opencode/worktree/<repo>/<branch>/direnv allow if .envrc existsFor worktrees, you can configure your .envrc to derive PORT and database settings from the worktree name to avoid conflicts:
# .envrc
export BRANCH_NAME=$(basename $(pwd))
export PORT=$((3000 + $(echo "$BRANCH_NAME" | cksum | cut -d' ' -f1) % 1000))
export DATABASE_URL="postgres://localhost/${BRANCH_NAME//-/_}_development"
When using opencode-pilot for automated issue processing, configure your repos.yaml:
repos:
myorg/myrepo:
session:
prompt_template: |
/devcontainer issue-{number}
{title}
{body}
This starts an isolated devcontainer for each issue automatically.
When switching workspaces with /devcontainer or /worktree, OpenCode's internal directory context doesn't update. The "Session changes" panel continues showing diffs from the original directory.
Workaround: Start OpenCode directly in the target directory, or use separate terminal sessions per workspace.
Upstream issue: anomalyco/opencode#6697
Override default paths:
OCDC_CONFIG_DIR - Config directory (default: ~/.config/opencode/devcontainers)OCDC_CACHE_DIR - Cache directory (default: ~/.cache/opencode-devcontainers)OCDC_CLONES_DIR - Clones directory (default: ~/.local/share/opencode/clone)OCDC_WORKTREES_DIR - Worktrees directory (default: ~/.local/share/opencode/worktree)OCDC_SESSIONS_DIR - Sessions directory (default: <cache>/opencode-sessions)MIT
150 commits
25 commits
18 commits
2 commits
JavaScript
97.6%
Shell
2.4%
OpenCode plugin for isolated branch workspaces using devcontainers or git worktrees.
Note: This is a community project and is not built by or affiliated with the OpenCode team.
Version 0.x - Pre-1.0 software. Minor versions may contain breaking changes.
When working on multiple branches, you need isolated development environments:
This plugin provides both options with:
Add to your ~/.config/opencode/opencode.json:
{
"plugin": ["opencode-devcontainers"]
}
OpenCode automatically installs npm plugins on startup.
devcontainer CLI - Install with: npm install -g @devcontainers/cli/devcontainer feature-x # Start/target a devcontainer for this branch
/devcontainer myapp/main # Target specific repo/branch
/devcontainer # Show current status
/devcontainer off # Disable, run commands on host
When a devcontainer is targeted:
HOST: to force host execution/worktree feature-x # Create/target a worktree for this branch
/worktree myapp/main # Target specific repo/branch
/worktree # Show current status
/worktree off # Disable, run commands in original directory
When a worktree is targeted:
HOST: prefix for escaping/workspaces # List all workspaces (clones + worktrees)
/workspaces cleanup # Find stale workspaces (not used in 7+ days)
| Use Case | Recommendation |
|---|---|
| Project has devcontainer.json | /devcontainer |
| Different dependencies per branch | /devcontainer |
| Quick branch work, same deps | /worktree |
| No Docker or Podman available | /worktree |
| Testing migrations/databases | /devcontainer |
~/.config/opencode/devcontainers/config.json:
{
"portRangeStart": 13000,
"portRangeEnd": 13099,
"dockerPath": "podman",
"dockerComposePath": "podman-compose"
}
dockerPath and dockerComposePath are optional. When unset, the plugin uses Docker when available, otherwise Podman. A Podman runtime requires either podman-compose or docker-compose; the plugin detects one automatically and reports an unsupported configuration when neither is available. Set both paths explicitly to use nonstandard executable locations.
~/.local/share/opencode/clone/<repo>/<branch>/devcontainer up~/.local/share/opencode/worktree/<repo>/<branch>/direnv allow if .envrc existsFor worktrees, you can configure your .envrc to derive PORT and database settings from the worktree name to avoid conflicts:
# .envrc
export BRANCH_NAME=$(basename $(pwd))
export PORT=$((3000 + $(echo "$BRANCH_NAME" | cksum | cut -d' ' -f1) % 1000))
export DATABASE_URL="postgres://localhost/${BRANCH_NAME//-/_}_development"
When using opencode-pilot for automated issue processing, configure your repos.yaml:
repos:
myorg/myrepo:
session:
prompt_template: |
/devcontainer issue-{number}
{title}
{body}
This starts an isolated devcontainer for each issue automatically.
When switching workspaces with /devcontainer or /worktree, OpenCode's internal directory context doesn't update. The "Session changes" panel continues showing diffs from the original directory.
Workaround: Start OpenCode directly in the target directory, or use separate terminal sessions per workspace.
Upstream issue: anomalyco/opencode#6697
Override default paths:
OCDC_CONFIG_DIR - Config directory (default: ~/.config/opencode/devcontainers)OCDC_CACHE_DIR - Cache directory (default: ~/.cache/opencode-devcontainers)OCDC_CLONES_DIR - Clones directory (default: ~/.local/share/opencode/clone)OCDC_WORKTREES_DIR - Worktrees directory (default: ~/.local/share/opencode/worktree)OCDC_SESSIONS_DIR - Sessions directory (default: <cache>/opencode-sessions)MIT
150 commits
25 commits
18 commits
2 commits
JavaScript
97.6%
Shell
2.4%