Skip to content

Hierarchical session filter from #24849 has no exact-match mode; -c from parent dir picks wrong child session and widens permission scope #26099

Closed as not planned

Description

@malventano

Description

Problem 1: No exact directory matching for sessions

The session list filter (added in #24849) uses a hierarchical prefix match on path:

eq(path, input.path) OR like(path, input.path + "/%")

When launching opencode at /root/opencode, all sessions from child subdirectories appear in /sessions. The KV flag session_directory_filter_enabled only offers two modes:

Value Behavior
true (default) Hierarchical — current dir + all children
false { scope: "project" } — ALL sessions in the project

No option for exact directory matching, which was the behavior before #24849:

if (input?.directory) { conditions.push(eq(SessionTable.directory, input.directory)) }

Problem 2: Selecting a child-directory session leaves CWD unchanged

Selecting a session whose directory differs from where opencode was launched keeps the TUI CWD at the launch directory (directory.ts:10 reads project.instance.path().directory, not the session's directory). No warning is shown. When the sidebar is collapsed, the parent CWD isn't visible at all — making it even harder to realize you're in the wrong session. (Related fix discussed in #23507.)

Problem 3: opencode -c from a parent path lands in the wrong session

Running opencode -c from /root/opencode picks up the most recent session across all child subdirectories due to the hierarchical path filter. The user lands in a session from a different directory, at the wrong CWD, unaware of the mismatch.

Problem 4: external_directory boundary evaluated against launch directory, not session directory

external_directory uses containsPath(filepath, ctx) (instance-context.ts:18) which checks if the path is inside ctx.directory (the instance's launch directory). When -c lands you in a child-directory session but the CWD stays at the parent:

  1. User works in /root/opencode/orca, finishes a session, exits
  2. User navigates to /root/opencode and runs opencode -c
  3. Due to hierarchical session filtering, -c picks up the orca session
  4. ctx.directory is /root/opencode (launch dir), NOT /root/opencode/orca (session dir)
  5. Everything under /root/opencode/ is now considered "internal" — including sibling directories like /root/opencode/northerner/
  6. If the user had "external_directory": "ask" or "deny", tool calls to sibling directories would pass the check since they're still under /root/opencode. The user unknowingly has a wider boundary than intended.
  7. For non-git projects where worktree = "/", the worktree fallback at instance-context.ts:22 returns false, so ctx.directory is the only boundary — making this even more impactful.
  8. With the sidebar collapsed and the parent CWD invisible, the user has no indication that the permission boundary is broader than expected.

Related issues

Proposed fixes

  1. Add an exact-match mode for session filtering (scope: "directory" or three-value KV flag)
  2. When selecting a session whose directory differs from the active CWD, warn the user or offer to switch
  3. Scope opencode -c to the current directory
  4. Ensure external_directory boundary considers the session's original directory

Plugins

No response

OpenCode version

No response

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

No response

Terminal

No response

Activity

  1. assigned and unassigned on May 7, 2026
  2. github-actions commented on Jul 8, 2026

    @github-actions
    Contributor

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

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions