opencode icon indicating copy to clipboard operation
opencode copied to clipboard

session list is showing all sessions not only the ones scopes to the curent dir

Open luisrudge opened this issue 10 months ago • 11 comments

Description

see title

Plugins

opencode-anthropic-auth, @franlol/opencode-md-table-formatter

OpenCode version

1.1.23

Steps to reproduce

open opencode anywhere and type /sessions it should load only sessions from that directory, but lists all my sessions

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

luisrudge avatar Jan 16 '26 08:01 luisrudge

This issue might be a duplicate of existing issues. Please check:

  • #6098: The sessions list seems to show all history, not the sessions history of the working directory
  • #3551: Sessions are now mixed with home directory session list, disregarding which directory you're in
  • #7186: Sessions not displayed in /session for specific project path despite being written to storage

Feel free to ignore if none of these address your specific case.

github-actions[bot] avatar Jan 16 '26 08:01 github-actions[bot]

This is from Claude:

I've done some research on this issue and wanted to share findings on the existing PRs and a potentially more complete approach.

Existing PR Analysis

PR #8886 (client-side filtering in dialog only):

  • Only filters the session list dialog UI display
  • Does NOT filter the bootstrap session list fetch (initial load still fetches all sessions)
  • Does NOT filter real-time session.updated events (cross-directory sessions can still appear via SSE)
  • Does NOT filter session search results
  • Result: Sessions from other directories can still leak through via bootstrap, search, or real-time events

PR #6724 (server-side default filtering):

  • Changes Session.list() default behavior for ALL clients (web UI, API consumers, CLI)
  • Requires new --all flag and ?all=true query param for opt-out
  • More invasive change that affects the API contract
  • Web UI and other consumers may want cross-directory visibility by default

Proposed Alternative: TUI-only, use existing API

The API already supports GET /session?directory=<path> (exact match filter) - it's just never wired up in the TUI. A more complete TUI-only fix would:

  1. Pass directory param to bootstrap session.list call in sync.tsx
  2. Pass directory param to session search in dialog-session-list.tsx
  3. Filter session.updated real-time events by directory (early break if mismatch)
  4. Pass directory: cwd to tui() call for SDK context

Why this approach?

  • Uses existing API infrastructure (no server changes, no new flags)
  • Filters ALL entry points: bootstrap, search, AND real-time events
  • No behavior change for web UI or other API consumers
  • Purely additive - doesn't change any defaults or require opt-out mechanisms

Known limitation: Uses exact directory match (existing API behavior). Sessions created from a subdirectory won't appear when TUI is launched from repo root. This is acceptable for the worktree use case and could be improved later with prefix matching if needed.

I have a working implementation of this approach and happy to submit a PR if maintainers prefer this direction over the existing PRs.

allisoneer avatar Jan 21 '26 20:01 allisoneer

Is this a git project? because in git projects it is scoped, everything else is global

rekram1-node avatar Jan 21 '26 20:01 rekram1-node

Is this a git project? because in git projects it is scoped, everything else is global

It is a git project! I want scoped to each worktree in that git project instead of just scoped to the git project as a whole.

allisoneer avatar Feb 05 '26 17:02 allisoneer

I have the same issue when working with worktrees. When using the --continue flag, it resumes the last session in whatever worktree. Ideally it would resume the session in that particular worktree.

alexprudhomme avatar Feb 05 '26 17:02 alexprudhomme

Is this a git project? because in git projects it is scoped, everything else is global

Hi @rekram1-node, I am having the same issue because of git worktrees. I am available to work on this if you can provide some instructions regarding where the fix should be. Should the fix be on the server and affect all clients or should this be a fix only for the TUI ? Let me know and I can provide a PR.

alexprudhomme avatar Feb 05 '26 19:02 alexprudhomme

Would there be any interest in PRs to make the scoping configurable? In my use case at least, I want a separate session list per worktree rather than a global one for the entire git repo. I tend to use a worktree to contain a particular thread of work so scoping them that way is much more clear for my workflow. I'm sure others might want it directory scoped or have other ideas.

Happy to file an issue and a PR if that sounds desirable more broadly.

ejj avatar Mar 17 '26 19:03 ejj

Yeah. I’m using lots of work trees now and having a single session list is not ideal.

On Tue, Mar 17, 2026 at 1:29 PM Ethan J. Jackson @.***> wrote:

ejj left a comment (anomalyco/opencode#8836) https://github.com/anomalyco/opencode/issues/8836#issuecomment-4077492498

Would there be any interest in PRs to make the scoping configurable? In my use case at least, I want a separate session list per worktree rather than a global one for the entire git repo. I tend to use a worktree to contain a particular thread of work so scoping them that way is much more clear for my workflow. I'm sure others might want it directory scoped or have other ideas.

Happy to file an issue and a PR if that sounds desirable more broadly.

— Reply to this email directly, view it on GitHub https://github.com/anomalyco/opencode/issues/8836#issuecomment-4077492498, or unsubscribe https://github.com/notifications/unsubscribe-auth/AAHFYE5BNLG2WGQJSDJBPZL4RGRRBAVCNFSM6AAAAACR4MI7QCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHM2DANZXGQ4TENBZHA . You are receiving this because you authored the thread.Message ID: @.***>

luisrudge avatar Mar 17 '26 19:03 luisrudge

Also an issue for me. If at least it could show the working dir for the session in the session list, what would help

marcodiniz avatar Mar 19 '26 10:03 marcodiniz

Adding a current reproduction from OpenCode 1.15.9 because this still affects the new OPENCODE_EXPERIMENTAL=1 + /warp worktree workflow.

Steps:

  1. Launch OpenCode in a git repo with multiple worktrees/workspaces.
  2. Use /warp to switch between worktrees.
  3. Open /sessions from each worktree.

Actual: sessions from all worktrees for the same git project are mixed together.

Expected: the TUI defaults to sessions for the current workspace/worktree, with a visible "show all" escape hatch or filter indicator so users do not think sessions disappeared.

Why this matters: a worktree is usually one isolated thread of work. Mixing sessions across worktrees defeats the main reason to use /warp in the terminal, especially now that the web UI already makes workspace-specific sessions feel separate.

The existing API/schema looks like it has enough metadata to support this without changing project identity: sessions expose directory and workspaceID, and session list endpoints accept workspace/path-style filters. So the useful fix seems to be TUI scoping/UX rather than changing projectID.

rodrigojimenezdencker avatar May 22 '26 22:05 rodrigojimenezdencker

To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

github-actions[bot] avatar Jul 22 '26 03:07 github-actions[bot]