anomalyco / anomalyco/opencode

Review panel diffs the session's original directory, not the worktree the agent is working in

Open
#47,911 1 comment 0 reactions 1 assignee View on GitHub

@Hona is already working on this.

Since Sep 8, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description
What happened

I opened a project at its main checkout (~/project/) and asked the agent to work in a linked git worktree (~/project-feature/). The agent correctly created and edited files inside the worktree.

However, the review panel (the "changes" pane) shows the working-tree changes for ~/project/ — the directory I originally opened — instead of ~/project-feature/ where the work actually happened.

What I expected

The review panel should surface the changes the agent actually made. When the agent does its work in a worktree/sandbox, the panel should show that directory's diff (or the session's own per-turn diff), not the diff of the directory that happened to be opened at session start.

Root cause (from a code read)

The review panel is scoped to the session's directory, which is fixed at creation and never tracks where the agent is actually working:

  • The web/app panel fetches GET /vcs/diff?directory=<sdk().directory>&mode=git. sdk().directory comes from the session record (packages/app/src/pages/session.tsx).
  • On the server, Session.Info.directory is set once from ctx.directory at creation and never updated (packages/opencode/src/session/session.ts, create/fork).
  • When the agent works in a worktree, it does so transiently via the tool's workdir param (packages/opencode/src/tool/shell.ts ~L612: params.workdir ? resolvePath(params.workdir, instanceCtx.directory, shell) : instanceCtx.directory). That working directory is never persisted back to the session, so nothing downstream knows the work moved.
  • The "turn" mode has the same blind spot: summary.diffs is computed from snapshots, and the snapshot service is scoped to ctx.directory/ctx.worktree of the session's instance (packages/opencode/src/snapshot/index.ts ~L68-75). So it also captures main, not the worktree.

In short: every diff source (/vcs/diff in git mode, and the snapshot-backed turn mode) is keyed off the directory the session was opened in, not the directory the agent is editing in.

Suggested directions

Any of these would resolve it, in increasing scope:

  1. Make the review panel auto-switch to (or default to) the turn mode when the session's edits land outside sdk().directory — if turn mode can be made worktree-aware.
  2. Track the session's effective working directory / active worktree (mutable on the session, or a first-class worktree-session concept) and scope /vcs/diff, the snapshot, and the review panel to it.
  3. When a worktree is created for a session, treat that worktree as the session's directory for review/diff purposes.
Environment
  • opencode dev branch (commit ecbc6ccac8)
  • Web review panel (also affects desktop, which shares ReviewPanelV2)
  • OS: Linux
  • Setup: main git checkout with a linked worktree created via git worktree add
OpenCode version

opencode dev branch (commit ecbc6ccac8)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.