GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — plan mode: worktree_create bypasses read-only restriction · Issue #64162 · anomalyco/opencode

plan mode: worktree_create bypasses read-only restriction #64162

New issue
Copy link
New issue
Copy link
Open
#66859
Open
plan mode: worktree_create bypasses read-only restriction#64162
#66859
Copy link
Labels
area/coreAgent loop, tools and configplatform/windowsWindowstype/bugSomething is brokenversion/v2OpenCode 2.x

Description

@thequantpartners
thequantpartners
opened on Nov 16, 2026
Issue body actions

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

  1. Enter Plan mode in an OpenCode session (the mode that advertises read-only discussion and forbids file modification).
  2. From Code Mode (execute), call tools.opencode.worktree_create({ name: "probe" }).
  3. Observe the call return { directory: ".../.local/share/opencode/worktree/<id>/probe" } and the worktree registered via git worktree list.
  4. 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.

Activity

  1. opencodejr commented on Nov 16, 2026

    @opencodejr
    opencodejrBot
    on Nov 16, 2026
    Contributor
    More actions

    Thanks for the detailed report and the git worktree list output.

    In short, you're asking for Plan mode to block every tool that changes the filesystem or Git state. That would mean gating worktree_create and session_move the way edits are gated, and also making worktree_remove succeed when the directory is already gone.

    The current behaviour matches how these tools are documented, so I've filed this as a feature request rather than a bug:

    • Plan mode's extra policy "allows questions; denies edits except files under ~/.opencode/plan". The agents docs describe Plan as exploring and planning "without editing normal project files".
    • The tools docs say that worktree_remove uses the edit permission on the worktree directory, which Plan denies. The other worktree utilities, including worktree_create, do not request a built-in permission action. That is why one was refused and the other ran.

    Maintainers will consider changing how these tools are classified.

    Related issues:

    • worktree_remove is gated only by edit, so a file-editing agent can delete its own worktree (uncommitted work included) #61121: asks for worktree_remove to get its own permission action instead of edit. It is the same "permission doesn't match the side effect" concern, from the other direction.
    • feat(core): add permission actions for session_move and session_rename #58047: open PR adding separate permission actions for session_move and session_rename.
    • Windows: worktree remove fails half-way and leaves a stale row when the worktree's location has a local MCP server running #51172: on Windows, a worktree removal can fail half-way and leave a stale row. This matches your note about a locked folder.
    • worktree_list: silent empty outside a repo, and its registry disagrees with git in both directions #60768: worktree_list's registry can disagree with git worktree list, which is the divergence you saw.
  2. opencodejr
    added
    area/coreAgent loop, tools and config
    platform/windowsWindows
    type/featureNew behaviour or an improvement
    version/v2OpenCode 2.x
    on Nov 16, 2026
  3. thequantpartners commented on Nov 17, 2026

    @thequantpartners
    thequantpartners
    on Nov 17, 2026
    Author
    More actions

    Thanks for the context. The core friction for us is the asymmetry: worktree_create runs freely in Plan mode but worktree_remove is blocked by the edit permission. That leaves orphaned worktrees with no way to clean them up from within the same mode.

    The Windows stale-row issue (#51172) is particularly relevant — we're on Windows and a half-failed removal would leave git state inconsistent.

    For our workflow, having worktree_remove succeed when the directory is already gone (idempotent removal) would solve the immediate problem, even before a dedicated permission action exists.

  4. neriousy
    added
    type/bugSomething is broken
    and removed
    type/featureNew behaviour or an improvement
    on Nov 26, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/coreAgent loop, tools and configplatform/windowsWindowstype/bugSomething is brokenversion/v2OpenCode 2.x

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.