Skip to content

session list and TUI expose non-git/global sessions that can resume with wrong cwd #28972

@samiralibabic

Description

@samiralibabic

Description

opencode session list and the TUI session picker can expose sessions from unrelated non-git directories.

This appears related to #18890, but it affects more than --continue.

Observed behavior:

  • opencode session list can show sessions from unrelated non-git directories because it calls Session.list({ roots: true, limit }) without passing directory or path.
  • In non-git contexts, sessions are grouped under the global project bucket, so listing from $HOME or another non-git directory can expose sessions that were started elsewhere.
  • The TUI applies a path-prefix query plus a 30-day cutoff. With non-git worktree = "/", launching from $HOME can match descendant paths, so subfolder sessions can appear from the parent/global context.
  • Legacy sessions with path = NULL can also disappear from the TUI because the TUI query passes path but not directory, so the legacy directory fallback is not used.

The risky part is resume/switch behavior. A visible session can belong to directory A, but if it is resumed from directory B, the old transcript is loaded while the runtime/model environment can still be based on the current launch directory.

That can affect:

  • working directory
  • workspace root
  • config loading
  • instruction files
  • shell commands
  • LSP context
  • file tools
  • model assumptions

Expected behavior:

  • Default session list should be scoped to the current launch directory, not just the current project/global bucket.
  • TUI should not silently include parent/subfolder/global sessions unless the user explicitly chooses project/recursive/global scope.
  • Legacy sessions with path = NULL should still match by stored directory, or be migrated.
  • Resuming/switching a session should either restore the session’s stored directory, or warn/refuse when the current launch directory differs.

Related:

Plugins

None

OpenCode version

v1.2.15+ / current dev behavior

Steps to reproduce

  1. Create two unrelated non-git directories:

    mkdir -p /tmp/oc-a /tmp/oc-b
    
  2. Start OpenCode in the first directory and create a session:

    cd /tmp/oc-a
    opencode
    
  3. Exit, then start OpenCode in the second directory and create another session:

    cd /tmp/oc-b
    opencode
    
  4. Run session listing from a broader non-git context, for example $HOME:

    cd ~
    opencode session list --format json
    
  5. Observe that sessions from unrelated non-git directories can appear together under the global project bucket.

  6. Open the TUI from $HOME or another parent/global context and inspect the session picker.

  7. Observe that sessions from subfolders/global non-git contexts may be visible, while older legacy sessions with path = NULL may be hidden due to the TUI path filter and 30-day cutoff.

  8. Resume or switch to a session that was created in another directory.

  9. Observe that the transcript belongs to the old session, but the runtime/model environment can still reflect the current launch directory.

Screenshot and/or share link

No response

Operating System

macOS

Terminal

iTerm2 / zsh

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions