Repository navigation
Description
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:
- User works in
/root/opencode/orca, finishes a session, exits - User navigates to
/root/opencodeand runsopencode -c - Due to hierarchical session filtering,
-cpicks up the orca session ctx.directoryis/root/opencode(launch dir), NOT/root/opencode/orca(session dir)- Everything under
/root/opencode/is now considered "internal" — including sibling directories like/root/opencode/northerner/ - 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. - For non-git projects where
worktree = "/", the worktree fallback atinstance-context.ts:22returnsfalse, soctx.directoryis the only boundary — making this even more impactful. - With the sidebar collapsed and the parent CWD invisible, the user has no indication that the permission boundary is broader than expected.
Related issues
- Sessions from different non-git directories are mixed when using --continue #18890 — Sessions from different non-git directories mixed with
--continue --continueresumes latest session across root-level git worktrees instead of current worktree #25963 —--continueresumes latest session across root-level git worktrees- session list is showing all sessions not only the ones scopes to the curent dir #8836 — Session list showing all sessions not scoped to current dir
- feat: move sidebar footer directory path to status bar at the bottom #23507 — Collapsed sidebar CWD visibility
Proposed fixes
- Add an exact-match mode for session filtering (
scope: "directory"or three-value KV flag) - When selecting a session whose
directorydiffers from the active CWD, warn the user or offer to switch - Scope
opencode -cto the current directory - Ensure
external_directoryboundary 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
github-actions commentedon Jul 8, 2026
To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.