Skip to content

tui: current-directory session picker includes sibling Git worktrees #58108

Open

Description

@qinqon

Description

In the TUI session picker, “Show current directory sessions” also shows sessions from other Git worktrees of the same repository.

Expected: only sessions whose working directory matches the selected directory. Actual: sessions at the same relative subpath in sibling worktrees appear too.

The scoped request in packages/tui/src/component/dialog-session-list.tsx sends project and subpath instead of directory. Worktree roots share a project ID and an empty subpath, so they all match. The local fallback uses exact-directory filtering, making the two paths inconsistent.

Proposed fix: use the existing directory API filter for current-directory mode, with regression coverage for sibling worktrees and the all-projects toggle.

Plugins

No explicit plugin entries found in inspected global/project configs. Local global plugin file: notify.js; runtime activation not verified.

OpenCode version

2.1.2 (latest channel)

Steps to reproduce

  1. Create two Git worktrees of the same repository.
  2. Create a top-level OpenCode session at each worktree root with distinct titles.
  3. In one worktree, open /sessions and select “Show current directory sessions” with Ctrl+A if necessary.
  4. Observe sessions from both worktrees rather than only the selected directory.

Reported by a user and confirmed by tracing the request and backend filters in the source. No manual reproduction recording is available.

Screenshot

Not available.

Operating System

Linux x86_64, kernel 7.1.12-200.fc44.x86_64; shell /bin/bash.

Terminal

TERM=xterm-256color, COLORTERM=truecolor; TERM_PROGRAM unset, terminal application unknown.

Activity

  1. opencode-agent commented on Oct 22, 2026

    @opencode-agent
    Contributor

    Thanks for the detailed report. I can confirm this on 2.1.2, and it still happens on the latest dev (b42c316).

    Steps I used:

    1. Created a git repo and a second worktree with git worktree add.
    2. Created one top-level session in each worktree root. Both sessions get the same project ID.
    3. Opened /sessions in the main worktree. The picker is in current-directory mode (header "Sessions for ", hint "all projects ctrl+a").

    The session from the sibling worktree is still listed, labelled with the sibling's directory. The recording and screenshot below show this, and the script below reproduces it.

    The cause matches what you traced: for non-global projects, the scoped request sends project + subpath instead of directory, while the local fallback filters on the exact directory.

    Related: #51514 (empty subpath handling) and #57635 (only the flat directory filter is honoured by GET /api/session).

    recording.mp4

    Screenshot

    Reproduction script (drive.ts)
    // Repro for #58108: "current directory" session picker shows sessions from sibling git worktrees.
    import { Effect } from "effect"
    import { join } from "node:path"
    import { OpenCodeDriver } from "opencode-drive"
    
    export default OpenCodeDriver.use(
      {
        ...(process.env.OC_DEV ? { opencode: { dev: process.env.OC_DEV } } : {}),
        project: { git: true, files: { "README.md": "main\n" } },
        tui: { recording: true, keypressOverlay: true },
      },
      ({ ui, opencode, artifacts }) =>
        Effect.gen(function* () {
          const main = join(artifacts, "files")
          const sibling = join(artifacts, "sibling-worktree")
          // Second git worktree of the same repository
          yield* Effect.promise(async () => {
            const r = Bun.spawnSync(["git", "-C", main, "worktree", "add", "-q", "-b", "other", sibling])
            if (r.exitCode !== 0) throw new Error(r.stderr.toString())
          })
          const a = yield* opencode.session.create({ title: "SESSION-IN-MAIN-WORKTREE", location: { directory: main as any } })
          const b = yield* opencode.session.create({ title: "SESSION-IN-SIBLING-WORKTREE", location: { directory: sibling as any } })
          yield* Effect.log(`main=${a.projectID} ${JSON.stringify(a.location)} sibling=${b.projectID} ${JSON.stringify(b.location)}`)
          yield* Effect.sleep(1000)
          yield* ui.submit("/sessions")
          yield* ui.waitFor("SESSION-IN-MAIN-WORKTREE")
          yield* Effect.sleep(800)
          const frame1 = yield* ui.capture()
          yield* ui.screenshot("picker-initial")
          const text1 = JSON.stringify(frame1)
          if (!text1.includes("current directory")) {
            // currently in current-directory mode already if hint says "all projects"
          }
          yield* Effect.log(`initial frame includes sibling: ${text1.includes("SESSION-IN-SIBLING-WORKTREE")}; hint all projects: ${text1.includes("all projects")}`)
          // Toggle scope and capture again, so both modes are shown
          yield* ui.press("a", { ctrl: true })
          yield* Effect.sleep(1500)
          const frame2 = yield* ui.capture()
          yield* ui.screenshot("picker-toggled")
          const text2 = JSON.stringify(frame2)
          yield* Effect.log(`toggled frame includes sibling: ${text2.includes("SESSION-IN-SIBLING-WORKTREE")}; hint all projects: ${text2.includes("all projects")}`)
          yield* Effect.sleep(1000)
        }),
    )

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH; set OC_DEV to the path of an OpenCode checkout to run that from source instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions