anomalyco / anomalyco/opencode

opencode session list silently outputs empty result (exit 0) when run in a git repo with an origin remote

Open
#40,616 1 comment 0 reactions 1 assignee View on GitHub

@nexxeln is already working on this.

Since Aug 5, 2026.

Dominant language
TypeScript
Stars
209k
Forks
27.5k
PR merge metrics
PR metrics pending

Description

Description

Bug Report: opencode session list silently outputs nothing when run in a git repository with an origin remote

Summary

opencode session list (including --format json) produces zero output and exits with code 0 when invoked in a directory that is a git repository with an origin remote configured. The command appears to scope session results to the current project (identified via the origin remote URL), but when no sessions exist for that project, it returns an empty result without any warning, message, or error. This is indistinguishable from "no sessions exist at all" and breaks programmatic consumers that rely on --format json always returning valid JSON.

Environment

  • opencode version: 1.18.10
  • OS: Ubuntu 24.04 (Linux 6.x, x86_64)
  • Install method: npm global (~/.npm-global/bin/opencode)
  • Binary type: Bun-compiled standalone ELF (BUN_1.2 marker present)

Reproduction

Minimal script
#!/bin/bash
set -e

# Test 1: non-git directory -> works
cd /tmp
opencode session list --format json | wc -c   # prints: 3976

# Test 2: git repo without remotes -> works
REPO=$(mktemp -d)
cd "$REPO"
git init --quiet
opencode session list --format json | wc -c   # prints: 3976

# Test 3: git repo with origin remote -> BUG: empty output
git remote add origin https://github.com/example/repo.git
opencode session list --format json | wc -c   # prints: 0
echo "exit: $?"                                # prints: 0

# Test 4: git repo with non-origin remote -> works
git remote remove origin
git remote add upstream https://github.com/example/repo.git
opencode session list --format json | wc -c   # prints: 3976

rm -rf "$REPO"
Actual output (opencode 1.18.10)
3976
3976
0
exit: 0
3976

Behavior matrix

Working directory stdout stderr exit code
Non-git directory Full JSON array empty 0
Git repo, no remotes Full JSON array empty 0
Git repo, upstream remote only Full JSON array empty 0
Git repo, origin remote empty (0 bytes) empty 0

Root cause analysis

Via strace, when opencode session list is run inside a git repository, it executes:

git rev-parse --show-toplevel
git rev-parse --git-dir
git rev-parse --git-common-dir
git remote get-url origin
  • When origin does not exist, git remote get-url origin fails (exit 2), and opencode falls back to listing all sessions globally.
  • When origin exists, git remote get-url origin succeeds (exit 0), and opencode scopes the session list to the current project (identified by the origin URL). If no sessions exist for that project, the result is empty.

This project-scoping behavior is:

  1. Undocumentedopencode session list --help shows no --project or --all flag, and no mention of project-based filtering.
  2. Silent — empty results are returned with no indication that filtering occurred, no warning on stderr, and exit code 0.
  3. Inconsistent — only the origin remote triggers scoping; other remotes (upstream, etc.) do not.

Impact

Any tool or script that calls opencode session list --format json programmatically will silently receive empty output when run from a git repository with an origin remote that has no associated sessions. This includes:

  • CI/CD pipelines running in cloned repos (almost always have origin)
  • Management/dashboard tools that wrap the CLI (our case: a Go service using exec.Command("opencode", "session", "list", "--format", "json").Output())
  • Any automation assuming --format json always returns valid JSON

The combination of exit code 0 + empty stdout is especially problematic. In Go, cmd.Output() returns ([]byte{}, nil) — empty bytes with no error — giving the caller no signal that anything went wrong. The JSON parser then fails with unexpected end of JSON input rather than a meaningful error.

Suggested fixes

Any of the following would resolve the issue:

  1. Add a --all flag to list sessions across all projects, bypassing the project filter.
  2. Always output valid JSON when --format json is specified — output [] instead of an empty string when no sessions match the current project filter.
  3. Print a notice to stderr when project filtering is active, e.g.: Showing sessions for project <origin-url>. Use --all to list all sessions.
  4. Don't scope by default — list all sessions unless a --project flag is explicitly provided (current behavior is surprising and undocumented).

--help output for reference

opencode session list

list sessions

Options:
  -h, --help        show help                                                              [boolean]
  -v, --version     show version number                                                    [boolean]
      --print-logs  print logs to stderr                                                   [boolean]
      --log-level   log level                   [string] [choices: "DEBUG", "INFO", "WARN", "ERROR"]
      --pure        run without external plugins                                           [boolean]
  -n, --max-count   limit to N most recent sessions                                         [number]
      --format      output format             [string] [choices: "table", "json"] [default: "table"]

No --all, --project, or filtering-related options are documented.

Plugins

none

OpenCode version

1.18.10

Steps to reproduce

No response

Screenshot and/or share link

No response

Operating System

Ubuntu 24.04 (Linux 6.x, x86_64)

Terminal

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.