feat(session): filter sessions by current directory
Summary
This PR adds directory-based filtering to session listing, so sessions are scoped to the current working directory by default rather than showing all sessions across the entire project.
Problem
Currently, when running oc in different directories within the same git repository, all sessions from all directories are visible. This creates noise and confusion - for example, running oc session list in /project/frontend shows sessions created in /project/backend, /project/docs, etc.
This is a common workflow issue for developers working on monorepos or projects with multiple subdirectories.
Solution
- Default behavior:
Session.list()now filters to only return sessions wheresession.directorymatches the current working directory (Instance.directory) - Opt-out: Pass
{ all: true }to get all sessions (previous behavior) - CLI: Added
--all/-aflag tooc session list - API: Added
?all=truequery parameter to/sessionendpoint
Prior Art
This behavior aligns with how Codex and Claude Code handle session visibility - they scope sessions to the current working directory rather than globally across the machine or project. This provides better isolation when:
- Working in different subdirectories of a monorepo
- Running opencode in non-git folders where sessions should be folder-specific
- Switching between related but distinct workspaces
Changes
| File | Change |
|---|---|
src/session/index.ts |
Added ListOptions interface, modified list() to filter by directory |
src/cli/cmd/session.ts |
Added --all flag to session list command |
src/server/server.ts |
Added ?all=true query param support |
Testing
- Built locally and verified:
oc session listreturns empty when no sessions match current directoryoc session list --allreturns all sessions (previous behavior)--helpshows the new flag correctly