[PR #4558] Session command with list subcommand added #11019

Closed
opened 2026-02-16 18:15:47 -05:00 by yindo · 0 comments
Owner

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

State: closed
Merged: No


Perfect! Now let me create a final summary of what I've implemented:

Summary

I have successfully implemented a new session command with a list subcommand for the opencode CLI. Here's what was created:

Files Created/Modified:

  1. /src/cli/cmd/session.ts - New command file containing:

    • SessionListCommand - Handles the session list subcommand
    • SessionCommand - Main session command that registers the list subcommand
  2. /src/index.ts - Modified to register the new SessionCommand

  3. /test/cli/session.test.ts - Basic test file for the command structure

Features Implemented:

Command Structure:

  • opencode session list - Main command invocation

Output Formats:

  • Default format (--format default): Git log-style table with Session ID, Last Updated, and Title
  • JSON format (--format json): Full session data as JSON
  • IDs format (--format ids): Just session IDs, one per line (CI-friendly)

Options:

  • --format, -f: Output format choice (default, json, ids)
  • --limit, -l: Limit number of sessions shown

Key Features:

  • CI-friendly: The --format ids option outputs just session IDs for easy scripting
  • Git log-like: Default format shows a clean table similar to git log
  • Sortable: Sessions are sorted by most recently updated
  • Responsive: Terminal width detection for proper formatting
  • Comprehensive: JSON format provides full session data for advanced use cases

Usage Examples:

# List all sessions in default format
opencode session list

# Get just session IDs for CI scripting
opencode session list --format ids

# Get full session data as JSON
opencode session list --format json

# Show only 5 most recent sessions
opencode session list --limit 5

# Combine options
opencode session list --format ids --limit 3

Design Choices:

  1. CI-friendly focus: The --format ids option directly addresses the user's need for easily extractable session IDs
  2. Multiple formats: Provides flexibility for different use cases (human-readable, machine-readable, script-friendly)
  3. Git log inspiration: Familiar table format for developers
  4. Limit option: Helps with large numbers of sessions
  5. Consistent patterns: Follows the same structure as other CLI commands in the codebase

The implementation directly addresses the GitHub issue where users couldn't easily find session IDs to use with the --session flag, providing both human-friendly and CI-friendly ways to list and access session information.

Closes #4557

New%20session%20-%202025-11-20T21%3A50%3A32.854Z
opencode session  |  github run

**Original Pull Request:** https://github.com/anomalyco/opencode/pull/4558 **State:** closed **Merged:** No --- Perfect! Now let me create a final summary of what I've implemented: ## Summary I have successfully implemented a new `session` command with a `list` subcommand for the opencode CLI. Here's what was created: ### Files Created/Modified: 1. **`/src/cli/cmd/session.ts`** - New command file containing: - `SessionListCommand` - Handles the `session list` subcommand - `SessionCommand` - Main session command that registers the list subcommand 2. **`/src/index.ts`** - Modified to register the new SessionCommand 3. **`/test/cli/session.test.ts`** - Basic test file for the command structure ### Features Implemented: #### Command Structure: - `opencode session list` - Main command invocation #### Output Formats: - **Default format** (`--format default`): Git log-style table with Session ID, Last Updated, and Title - **JSON format** (`--format json`): Full session data as JSON - **IDs format** (`--format ids`): Just session IDs, one per line (CI-friendly) #### Options: - `--format, -f`: Output format choice (default, json, ids) - `--limit, -l`: Limit number of sessions shown #### Key Features: - **CI-friendly**: The `--format ids` option outputs just session IDs for easy scripting - **Git log-like**: Default format shows a clean table similar to `git log` - **Sortable**: Sessions are sorted by most recently updated - **Responsive**: Terminal width detection for proper formatting - **Comprehensive**: JSON format provides full session data for advanced use cases ### Usage Examples: ```bash # List all sessions in default format opencode session list # Get just session IDs for CI scripting opencode session list --format ids # Get full session data as JSON opencode session list --format json # Show only 5 most recent sessions opencode session list --limit 5 # Combine options opencode session list --format ids --limit 3 ``` ### Design Choices: 1. **CI-friendly focus**: The `--format ids` option directly addresses the user's need for easily extractable session IDs 2. **Multiple formats**: Provides flexibility for different use cases (human-readable, machine-readable, script-friendly) 3. **Git log inspiration**: Familiar table format for developers 4. **Limit option**: Helps with large numbers of sessions 5. **Consistent patterns**: Follows the same structure as other CLI commands in the codebase The implementation directly addresses the GitHub issue where users couldn't easily find session IDs to use with the `--session` flag, providing both human-friendly and CI-friendly ways to list and access session information. Closes #4557 <a href="https://opencode.ai/s/pV7LWIjI"><img width="200" alt="New%20session%20-%202025-11-20T21%3A50%3A32.854Z" src="https://social-cards.sst.dev/opencode-share/TmV3IHNlc3Npb24gLSAyMDI1LTExLTIwVDIxOjUwOjMyLjg1NFo=.png?model=opencode/glm-4.6&version=1.0.81&id=pV7LWIjI" /></a> [opencode session](https://opencode.ai/s/pV7LWIjI)&nbsp;&nbsp;|&nbsp;&nbsp;[github run](/sst/opencode/actions/runs/19552433577)
yindo added the pull-request label 2026-02-16 18:15:47 -05:00
yindo closed this issue 2026-02-16 18:15:48 -05:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: anomalyco/opencode#11019