anomalyco / anomalyco/opencode
opencode session list silently outputs empty result (exit 0) when run in a git repo with an origin remote
@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.2marker 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
origindoes not exist,git remote get-url originfails (exit 2), and opencode falls back to listing all sessions globally. - When
originexists,git remote get-url originsucceeds (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:
- Undocumented —
opencode session list --helpshows no--projector--allflag, and no mention of project-based filtering. - Silent — empty results are returned with no indication that filtering occurred, no warning on stderr, and exit code 0.
- Inconsistent — only the
originremote 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 jsonalways 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:
- Add a
--allflag to list sessions across all projects, bypassing the project filter. - Always output valid JSON when
--format jsonis specified — output[]instead of an empty string when no sessions match the current project filter. - Print a notice to stderr when project filtering is active, e.g.:
Showing sessions for project <origin-url>. Use --all to list all sessions. - Don't scope by default — list all sessions unless a
--projectflag 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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.