Skip to content

Comments

fix(session): scope session list to current directory#14443

Closed
Aegis-commits wants to merge 1 commit intoanomalyco:devfrom
Aegis-commits:fix/session-directory-scoping
Closed

fix(session): scope session list to current directory#14443
Aegis-commits wants to merge 1 commit intoanomalyco:devfrom
Aegis-commits:fix/session-directory-scoping

Conversation

@Aegis-commits
Copy link

Summary

opencode session list and the TUI /sessions dialog show sessions from all directories instead of only the current working directory. This is because four call sites don't pass the existing directory filter parameter to Session.list().

This PR wires the directory parameter through all four missing call sites. No server, API, or schema changes required — the filtering infrastructure already exists and is already used by the web app.

Fixes #8836

Problem

Session.list() accepts an optional directory parameter that filters sessions by working directory. The server route (GET /session?directory=) and the web app's session-load.ts already use this parameter correctly. However, four TUI/CLI entry points call Session.list() without it:

  1. CLI session list command — fetches all sessions globally
  2. TUI bootstrap — loads all sessions into state on startup
  3. TUI /sessions dialog — searches all sessions when user opens session picker
  4. TUI SSE handler — blindly inserts new sessions from session.updated events regardless of directory

For git repositories, this is partially masked because project_id is derived from the repo root. But for non-git directories, project_id is "global" — so sessions from every non-git directory get mixed together.

Changes

File Change
packages/opencode/src/cli/cmd/session.ts Pass directory: Instance.directory to Session.list()
packages/opencode/src/cli/cmd/tui/context/sync.tsx Pass directory: sdk.directory in bootstrap fetch (line ~353)
packages/opencode/src/cli/cmd/tui/context/sync.tsx Add directory guard in SSE session.updated handler — only insert sessions matching current directory (lines ~208-220)
packages/opencode/src/cli/cmd/tui/component/dialog-session-list.tsx Pass directory to search call
packages/opencode/src/cli/cmd/tui/context/sdk.tsx Expose directory property on SDK context return object (plumbing for the above)

+7 lines, -4 lines across 4 files.

Approach

This follows the same pattern the web app already uses in packages/app/src/context/global-sync/session-load.ts. Each caller explicitly passes the directory it cares about — no server-side default changes, no new CLI flags, no API contract modifications.

The SSE handler fix deserves a note: without it, a session created in directory B would still appear in the TUI running in directory A via the real-time event stream, even though the initial fetch was correctly filtered.

Testing

  • tsgo --noEmit passes for both packages/opencode and packages/app (full monorepo typecheck via turborepo: 12/12 packages pass)
  • Existing test suite: 997 pass, 5 skip, 135 pre-existing failures (unrelated — caused by missing git user identity in test fixture tmpdir())
  • Verified via SQLite that Instance.directory stores the literal CWD, confirming exact-match filtering works correctly

Related

Pass the existing `directory` parameter to all session list call sites
that were missing it, so sessions are filtered to the current working
directory instead of showing all sessions globally.

Fixes four entry points:
- CLI `session list` command
- TUI bootstrap session fetch
- TUI /sessions dialog search
- TUI SSE session.updated event handler (new session inserts)

Uses the existing Session.list() directory filter and GET /session?directory=
API parameter — no server or API contract changes required.

Fixes anomalyco#8836
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 20, 2026
@github-actions
Copy link
Contributor

This PR doesn't fully meet our contributing guidelines and PR template.

What needs to be fixed:

  • PR description is missing required template sections. Please use the PR template.

Please edit this PR description to address the above within 2 hours, or it will be automatically closed.

If you believe this was flagged incorrectly, please let a maintainer know.

@github-actions
Copy link
Contributor

The following comment was made by an LLM, it may be inaccurate:

Related PRs Found

Note: PR #14443 is the current PR being checked, so it's excluded from the duplicate list below.

Highly Related PRs:

  1. PR fix(tui): scope session list to current directory (#8836) #8886 - fix(tui): scope session list to current directory (#8836)

  2. PR feat(session): filter sessions by current directory #6724 - feat(session): filter sessions by current directory

  3. PR fix: filter CLI sessions by current directory for worktree support #12008 - fix: filter CLI sessions by current directory for worktree support

Why These Are Related:

@Aegis-commits
Copy link
Author

Closing — fix is incomplete, sessions still cross directories in the TUI. Will investigate further before resubmitting.

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

Labels

needs:compliance This means the issue will auto-close after 2 hours.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

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

1 participant