opencode-isolateOpenCode plugin: create a git worktree and switch the current session into it
0
20
4 in 7 days
25.8
Multi-signal model
1 month ago
2026-07-02
Install and configure
opencode.jsonWrites to this project's opencode.json — applies to this repository only.
opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-isolate@0.1.0"]
}Writes to ~/.config/opencode/opencode.json — applies to every project.
~/.config/opencode/opencode.json
{
"$schema": "https://opencode.ai/config.json",
"plugin": ["opencode-isolate@0.1.0"]
}If you want to modify the plugin locally, install it into the project and reference the local path.
shell
pnpm add -D opencode-isolateopencode loads npm dependencies through its embedded runtime on startup and caches them locally — no manual global install needed.
An OpenCode plugin that isolates agent work into a git worktree, without leaving your session.
Ask the agent to start working on a branch, and the rest of the conversation continues in an independent working directory under .worktrees/<branch>/. Your main checkout, including any uncommitted changes you have there, stays untouched.
Why
When an agent edits files directly in your checkout, its changes mix with yours: you cannot review them separately, switching branches conflicts with your open editor, and a failed experiment leaves debris behind. Git worktrees solve this by giving each branch its own directory, but managing them by hand (creating, ignoring, navigating) is tedious enough that few people bother.
This plugin makes the isolation a single sentence. The session you are already in simply continues inside the worktree: no new terminal, no new session, no lost conversation context.
What it does
The plugin provides one tool, worktree_start. When the agent calls it with a branch name, the tool:
- Creates a git worktree at
.worktrees/<branch>/under the repository root. The branch is created if it does not exist, and reused if it does. - Appends
.worktrees/to.git/info/exclude, so worktrees never show up ingit status. Your shared.gitignoreis left alone. - Switches the current session's working directory to the worktree. Every file edit and shell command from that point on runs inside the isolated directory.
The tool is idempotent: calling it again with the same branch name reuses the existing worktree and simply switches the session there. When the work is merged, remove the directory with git worktree remove.
Installation
Add the package name to the plugin array in your opencode.json. OpenCode installs it automatically on startup.
{
"plugin": ["opencode-isolate"]
}
Usage
In an OpenCode session, ask for isolated work with a branch name:
Use worktree_start to work on the 123-fix-login-bug branch
The agent creates the worktree, the session moves there, and you continue the conversation as usual. Meanwhile your original checkout remains exactly as you left it.
Limitations
The session switch works by updating OpenCode's local session database, which is an internal detail of OpenCode rather than a public API. A future OpenCode release could change this schema; if the switch stops working, please file an issue.
Development
This project uses Bun. Run the tests with:
bun test
License
MIT License. See LICENSE for details.