opencode icon indicating copy to clipboard operation
opencode copied to clipboard

feat(session): filter sessions by current directory

Open harshav167 opened this issue 4 weeks ago • 2 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

Thanks for your contribution!

This PR doesn't have a linked issue. All PRs must reference an existing issue.

Please:

  1. Open an issue describing the bug/feature (if one doesn't exist)
  2. Add Fixes #<number> or Closes #<number> to this PR description

See CONTRIBUTING.md for details.

github-actions[bot] avatar Jan 13 '26 08:01 github-actions[bot]

Bumping this with a fresh force-push that now sits on v1.1.16 plus the three session-filtering files. Ran • Packages in scope: @opencode-ai/app, @opencode-ai/console-app, @opencode-ai/console-core, @opencode-ai/console-function, @opencode-ai/console-mail, @opencode-ai/console-resource, @opencode-ai/desktop, @opencode-ai/enterprise, @opencode-ai/function, @opencode-ai/plugin, @opencode-ai/script, @opencode-ai/sdk, @opencode-ai/slack, @opencode-ai/ui, @opencode-ai/util, @opencode-ai/web, opencode • Running typecheck in 17 packages • Remote caching disabled @opencode-ai/plugin:typecheck: cache hit, replaying logs e9de2b2b263d8292 @opencode-ai/slack:typecheck: cache hit, replaying logs 090668a9b53753cd @opencode-ai/desktop:typecheck: cache hit, replaying logs af3abedc14465f05 @opencode-ai/plugin:typecheck: $ tsgo --noEmit @opencode-ai/desktop:typecheck: $ tsgo -b @opencode-ai/slack:typecheck: $ tsgo --noEmit @opencode-ai/enterprise:typecheck: cache hit, replaying logs d3f3de3a459a6a7f @opencode-ai/enterprise:typecheck: $ tsgo --noEmit @opencode-ai/console-function:typecheck: cache hit, replaying logs af8894bff26be78d @opencode-ai/console-function:typecheck: $ tsgo --noEmit @opencode-ai/sdk:typecheck: cache hit, replaying logs 54073f55f7e6b875 @opencode-ai/sdk:typecheck: $ tsgo --noEmit @opencode-ai/app:typecheck: cache hit, replaying logs 079500c6a97aab9e @opencode-ai/app:typecheck: $ tsgo -b @opencode-ai/ui:typecheck: cache hit, replaying logs 3cab659f1e2cbe9a @opencode-ai/ui:typecheck: $ tsgo --noEmit @opencode-ai/util:typecheck: cache hit, replaying logs 78fb0a35d25f1957 @opencode-ai/util:typecheck: $ tsc --noEmit @opencode-ai/console-core:typecheck: cache hit, replaying logs 24cf33269fb2c13d @opencode-ai/console-core:typecheck: $ tsgo --noEmit opencode:typecheck: cache hit, replaying logs aeb81070b67a1486 opencode:typecheck: $ tsgo --noEmit @opencode-ai/console-app:typecheck: cache hit, replaying logs a7244c85fa1630ca @opencode-ai/console-app:typecheck: $ tsgo --noEmit

Tasks: 12 successful, 12 total Cached: 12 cached, 12 total Time: 178ms >>> FULL TURBO and opencode script { "channel": "feature/session-directory-filtering", "version": "0.0.0-feature/session-directory-filtering-202601130856", "preview": true } bun add v1.3.5 (1e86cebd)

installed @opentui/[email protected]

[209.00ms] done bun add v1.3.5 (1e86cebd)

installed @parcel/[email protected]

[113.00ms] done building opencode-linux-arm64 building opencode-linux-x64 building opencode-linux-x64-baseline building opencode-linux-arm64-musl building opencode-linux-x64-musl building opencode-linux-x64-baseline-musl building opencode-darwin-arm64 building opencode-darwin-x64 building opencode-darwin-x64-baseline building opencode-windows-x64 building opencode-windows-x64-baseline (macOS/Linux/Windows binaries) on this branch — builds succeed and binaries generated. Could someone from @anomalyco/opencode take a look when you have a moment?

harshav167 avatar Jan 13 '26 08:01 harshav167