Skip to content

feat(cli): add -a global mode for session list#15178

Open
cavanaug wants to merge 2 commits intoanomalyco:devfrom
cavanaug:session_list_all
Open

feat(cli): add -a global mode for session list#15178
cavanaug wants to merge 2 commits intoanomalyco:devfrom
cavanaug:session_list_all

Conversation

@cavanaug
Copy link

@cavanaug cavanaug commented Feb 26, 2026

Issue for this PR

Closes #14561
Related: #8836

Type of change

  • Bug fix
  • New feature
  • Refactor / code improvement
  • Documentation

What does this PR do?

Adds -a/--all to opencode session list so users can list sessions across all projects.
Without -a, behavior stays project-scoped as before.
When -a is used with table output, the list includes a Project ID column to make cross-project results readable.

How did you verify your code works?

Ran:

  • bun test test/cli/session-list.test.ts test/server/global-session-list.test.ts test/server/session-list.test.ts from packages/opencode

All tests passed.

Screenshots / recordings

N/A (CLI output change only)

Checklist

  • I have tested my changes locally
  • I have not included unrelated changes in this PR

Add a -a/--all option to session list so users can view sessions across projects without relying on current directory detection. Include a Project ID column in table output for global lists and add coverage for formatting and global root filtering.
Copilot AI review requested due to automatic review settings February 26, 2026 07:06
@github-actions github-actions bot added the needs:compliance This means the issue will auto-close after 2 hours. label Feb 26, 2026
@github-actions
Copy link
Contributor

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

Based on my search, I found one potentially related PR:

Related PR:

The current PR (#15178) is building upon this related work by adding a way to explicitly show all sessions across projects when needed, rather than just showing sessions in the current directory context.

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a -a/--all flag to the opencode session list command to enable viewing sessions across all projects, addressing issue #14561. The default behavior (without -a) continues to scope session listings to the current project context, fixing the issue reported in #8836.

Changes:

  • Add -a/--all CLI option to list sessions globally across all projects
  • Conditionally display a "Project ID" column in table output when using -a flag
  • Add comprehensive tests for CLI formatting functions and global session filtering

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
packages/opencode/src/cli/cmd/session.ts Added -a/--all option, conditional routing to Session.listGlobal(), and exported formatting functions with project ID column support
packages/opencode/test/cli/session-list.test.ts New test file for CLI formatting functions verifying Project ID column visibility and JSON output
packages/opencode/test/server/global-session-list.test.ts Added test verifying root session filtering works correctly across multiple projects

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

const lines: string[] = []

const maxIdWidth = Math.max(20, ...sessions.map((s) => s.id.length))
const maxProjectWidth = Math.max(10, ...sessions.map((s) => s.projectID.length))
Copy link

Copilot AI Feb 26, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The maxProjectWidth calculation on line 138 is performed even when all is false/undefined, meaning it's computed but never used. Consider moving this calculation inside the conditional block where all is true to avoid unnecessary computation when displaying the default table format.

Copilot uses AI. Check for mistakes.
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good call. Addressed in 4eb2755: maxProjectWidth is now computed only when --all is enabled.

@github-actions github-actions bot removed the needs:compliance This means the issue will auto-close after 2 hours. label Feb 26, 2026
@github-actions
Copy link
Contributor

Thanks for updating your PR! It now meets our contributing guidelines. 👍

@cavanaug
Copy link
Author

Addressed feedback:

  • Updated PR description to match the required template sections
  • Applied the suggested optimization in 4eb2755 so is only computed when is enabled
  • Re-ran: bun test v1.3.9 (cf6cdbbb) (all passing)

@cavanaug
Copy link
Author

Addressed feedback:

  • Updated PR description to match the required template sections
  • Applied the suggested optimization in commit 4eb2755 so maxProjectWidth is only computed when --all is enabled
  • Re-ran from packages/opencode: bun test test/cli/session-list.test.ts test/server/global-session-list.test.ts test/server/session-list.test.ts (all passing)

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE]:add session list global cli

2 participants