Summary
The Code Mode tools.opencode.worktree_create and tools.opencode.worktree_remove tools execute successfully while Plan mode is active. Plan mode is documented as read-only, but these tools mutate the filesystem and Git state (creating/removing worktree directories and registering entries in .git/worktrees/).
Related: tools.opencode.session_move likely has the same gap, since it also mutates session state rather than only reading it.
Environment
- opencode version: 2.3.0
- OS: Windows_NT 10.0.22621 (win32 x64)
- Terminal: xterm-256color (
TERM_PROGRAM / COLORTERM unset)
- Shell:
C:\WINDOWS\system32\cmd.exe (config sets shell: powershell)
- Install/channel: latest
- Active plugins: none configured (
~/.config/opencode/opencode.jsonc has no plugin key)
Reproduction
- Enter Plan mode in an OpenCode session (the mode that advertises read-only discussion and forbids file modification).
- From Code Mode (
execute), call tools.opencode.worktree_create({ name: "probe" }).
- Observe the call return
{ directory: ".../.local/share/opencode/worktree/<id>/probe" } and the worktree registered via git worktree list.
- Optionally call
tools.opencode.worktree_remove({ directory, force: true }) — note it returns Permission denied: edit while worktree_create succeeded, so the two tools are gated inconsistently.
Expected Behavior
Plan mode should block any tool that mutates the filesystem or repository state. worktree_create creates a directory tree and writes to .git/worktrees/, so it is a write operation and should be unavailable (or require explicit approval) in Plan mode, the same way edit and write are.
Actual Behavior
tools.opencode.worktree_create ran to completion in Plan mode. The resulting worktree was visible to git worktree list as a detached-HEAD entry, and the directory existed on disk. worktree_remove was then refused with Permission denied: edit, which suggests the permission classification for the worktree tools is not aligned with their actual side effects.
Additional Context
Observed git worktree list output after creating a worktree during Plan mode:
C:/.../ai-engineering-os 895fcd8 [main]
C:/.../.local/share/opencode/worktree/<id>/probe-worktree 895fcd8 (detached HEAD)
Two notes that may matter for the fix:
- Worktree location and shape.
worktree_create places worktrees under ~/.local/share/opencode/worktree/<hash>/<name> in detached HEAD state, with "strategy": "git" reported by worktree_list. This looks like a sandbox for agent isolation rather than a user-facing feature branch. If that is intentional, it is worth documenting, because it differs from git worktree add ../dir -b branch.
- Stale entries after failed removal. After
worktree_remove succeeded for one worktree but failed for another with Permission denied (folder locked by another process), git worktree list no longer showed either entry, while worktree_list still reported both. The Git-side and OpenCode-side registries appear to be able to diverge. git worktree prune is the manual fix.
Suggested fix: classify worktree_create, worktree_remove, and session_move as write tools so Plan mode and the edit permission gate cover them consistently, and make worktree_remove idempotent when the directory is already gone from disk.