GeezerVison is showing github.com — fix(tui): scope non-git sessions by directory, not hierarchical path by malventano · Pull Request #31210 · anomalyco/opencode
Conversation
malventano
commented
Jun 7, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Issue for this PR
Closes #8836, Closes #18890, Closes #19340, Closes #26099, Closes #28972, Closes #9881
Type of change
- Bug fix
- New feature
- Refactor / code improvement
- Documentation
What does this PR do?
PR #24849 introduced hierarchical path filtering (eq(path, X) OR like(path, X + "/%")) for git repos to support worktrees. But non-git projects set worktree = "/" (a truthy value), so the TUI's sessionListQuery() check !worktree never triggered — it fell through to the path branch instead.
path.relative("/", "<parent>") → "<parent>" then matched ALL sessions under that parent hierarchically, including sessions from unrelated subdirectories.
Changes:
packages/tui/src/context/sync.tsx: Check worktree === "/" explicitly and return { directory } for non-git projects so the server's existing eq(directory) fallback is used.
packages/opencode/src/cli/cmd/session.ts: Pass directory: process.cwd() to CLI session list so it's also scoped.
The server already has the else if (scope !== "project") fallback that performs eq(directory, ...) matching - no server changes needed. Git repo hierarchical filtering is untouched.
Security impact
This is not only a listing/filtering annoyance. Because subdir sessions surface at the parent, opencode -c from the parent reopens the most recently closed child session (started in a subdir) under the parent's pwd. The session's stored context/history assumes the subdir scope, but the process now runs with the parent's working directory and filesystem access. This effectively bypasses the external_directory security setting for that session, since tool calls execute against the broader parent tree instead of the subdir the session was authored in.
The broader the parent, the wider the unintended access. A session intended for a nested subdirectory would, reopened from its parent, be free to read/edit any sibling under that parent.
This PR restores exact eq(directory) matching for non-git projects, so subdir sessions no longer surface at the parent and cannot be reopened outside their original directory scope.
How did you verify your code works?
Tested locally with a local build:
Screenshots / recordings
N/A - not a UI change.
Checklist
- I have tested my changes locally
- I have not included unrelated changes in this PR
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
mtt0 and samiralibabic reacted with thumbs up emoji
PR #24849 introduced hierarchical path filtering for git repos. But non-git
projects set worktree = "/" (truthy), so sessionListQuery() never triggered
the !worktree fallback and fell through to the path branch instead.
path.relative("/", "/root/oc") -> "root/oc" then matched ALL sessions
under /root/oc/ hierarchically, including sessions from unrelated
subdirectories.
Fix:
- sync.tsx: check worktree === "/" explicitly, return { directory } for
non-git projects so server-side eq(directory) matching is used
- session.ts: pass directory: process.cwd() to CLI session list
Closes #8836, Closes #18890, Closes #19340, Closes #26099, Closes #28972, Closes #9881
|
The following comment was made by an LLM, it may be inaccurate:
Potential Duplicates Found
PR #29026 - fix(tui): scope session list to current worktree directory
PR #29582 - fix(tui): show home sessions in global project
PR #20361 - fix(sdk): avoid implicit directory filtering on /session list
PR #29539 - fix(tui): handle non-git project paths in autocomplete and session fi…
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
malventano
commented
Jun 7, 2026
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
|
This PR focuses on non-git directory filtering, restoring the behavior to what it was pre-#24849 (while not impacting that PR's intent for git repos). The 4 potential duplicates address different problems:
All 4 remain open. None supersede this fix.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
Looks like #30804 partially addresses the issue, but this PR is still needed to correctly address path scope for non-git sessions.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This was referenced Jun 18, 2026
|
Updated this PR to include text about the vulnerability it also corrects.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
For reviewers: #34842 is a server-side complement to this PR, not a replacement.
- This PR (fix(tui): scope non-git sessions by directory, not hierarchical path #31210) fixes the TUI client.
sessionListQuery() was sending the wrong query shape for non-git projects (worktree = "/" is truthy), so subdir sessions leaked into parent listings. The fix sends { directory } for exact eq(directory) matching instead of falling into the hierarchical path branch.
- fix(opencode): filter session list by resolved instance directory #34842 fixes the server. The
directory query param was passed through verbatim without resolving it against InstanceState.directory, so path separator differences (e.g. trailing path.sep) could cause eq(directory) matches to miss sessions that should have matched. The fix resolves the query through InstanceState.directory before matching.
Both are needed. This PR ensures the client sends the right query shape; #34842 ensures the server normalizes the directory value before comparing. Neither alone closes the full bug.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
#38532 is the current-dev alternative for #38529. It adds automated CLI/TUI query regression coverage and intentionally applies exact-directory default filtering in both Git and non-Git contexts; this PR preserves hierarchical Git filtering. Linking the two so maintainers can choose the intended default behavior.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
closed due to no action by devs
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
|