opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(session): filter sessions by current directory

Open harshav167 opened this issue 1 week ago • 0 comments

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 where session.directory matches the current working directory (Instance.directory)
  • Opt-out: Pass { all: true } to get all sessions (previous behavior)
  • CLI: Added --all / -a flag to oc session list
  • API: Added ?all=true query parameter to /session endpoint

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 list returns empty when no sessions match current directory
    • oc session list --all returns all sessions (previous behavior)
    • --help shows the new flag correctly

harshav167 avatar Jan 03 '26 04:01 harshav167