[PR #6724] feat(session): filter sessions by current directory #12066

Open
opened 2026-02-16 18:17:00 -05:00 by yindo · 0 comments
Owner

Original Pull Request: https://github.com/anomalyco/opencode/pull/6724

State: open
Merged: No


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
**Original Pull Request:** https://github.com/anomalyco/opencode/pull/6724 **State:** open **Merged:** No --- ## 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
yindo added the pull-request label 2026-02-16 18:17:00 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#12066