You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
opencode sessions command fails to list historical sessions when run inside a Git repository #15678
I have discovered that the presence of a .git directory in the current working directory prevents opencode sessions (or opencode session list) from displaying global session history.
The Bug:
When running the command in a non-git directory (e.g., ~/Documents/test), all global historical sessions are displayed correctly.
When running the command inside a Git repository (where a .git folder exists), the session list returns empty, even if those sessions were created globally.
Renaming .git to something else (e.g., gitbak) immediately restores the visibility of the session history.
Expected Behavior:
The tool should either merge global sessions with project-specific sessions or provide a flag (like --global) to access history regardless of the current Git context.
Plugins
No response
OpenCode version
1.2.15
Steps to reproduce
Open a terminal in a directory that is a Git repo (ls -a shows .git).
Run opencode session list. Result: Empty. (or use /sessions command)
Move out of the directory or rename .git.
Run opencode session list. Result: All sessions appear. (or use /sessions command)
If this is the same underlying issue (sessions being scoped/filtered by directory context), please add any additional info there or confirm if your issue differs.
I want to clarify that my issue (#15678) is distinct from #14668. While the symptoms are similar, I have identified a specific trigger: workspace isolation logic tied to the presence of a .git directory.
In my tests:
In a non-git directory, session list works perfectly.
Once a .git folder is present, the list becomes empty.
Renaming .git immediately fixes the visibility.
This suggests the core logic is filtering sessions by the repository root, but fails to fallback to or include global sessions when a repo is detected.
One more crucial detail regarding the reproduction steps:
In my project directory, I actually used opencodefirst (which successfully created and listed sessions). It was only after those sessions existed that I ran git init in the same directory. The behavior change was immediate: > * **Pre-git init**: opencode sessions displayed all historical sessions (global context).
**Post-git init**: opencode sessions returned an empty list, even though the sessions were created in the exact same physical path.
This suggests that once a directory is initialized as a Git repository, the tool strictly scopes its session lookups to the newly defined "Workspace ID" (or repo root), effectively "orphaning" or hiding sessions created in that directory before it was a Git repo.
After further testing, I noticed something very strange: not every directory with a .git folder triggers this issue. >
In some of my other Git-enabled project directories, opencode sessions correctly lists the global history.
However, in this specific project (Hp450G4SshAccess), the presence of .git consistently hides all sessions.
This suggests the bug isn't just triggered by "any" .git folder, but perhaps by a specific configuration or metadata within certain Git repositories (e.g., repository depth, origin URL format, or nested structures).
Deep Dive: Root Cause Identified (ProjectID Hash Shift)
I’ve conducted a detailed comparison between a "working" repo and a "broken" repo, including an inspection of the opencode binary logic. I have identified the exact cause of this behavior.
The Underlying Mechanism
OpenCode (v1.2.15) generates a projectID for workspace isolation by executing:
git rev-list --max-parents=0 --all
(This retrieves the hash of the root commit).
The Bug Trigger Sequence:
Phase 1 (Unborn Branch): In a newly initialized repo with 0 commits, the above command returns nothing. OpenCode falls back to a default ID (likely based on the absolute folder path). All sessions created at this stage are linked to this "Fallback ID".
Phase 2 (Initial Commit): As soon as the first commit is made, git rev-list suddenly returns a valid root commit hash (e.g., b5c3cd4...).
Phase 3 (The ID Shift): OpenCode immediately switches the active projectID to this new commit hash (and caches it in .git/opencode).
The Result: Because the ID has shifted from the "Fallback ID" to the "Commit-based ID", all sessions created before the first commit are instantly orphaned. They still exist in the database but are no longer queryable under the new workspace identity.
Proof:
Deleting .git forces OpenCode to fail the Git check, revert to the "Fallback ID", and the "lost" sessions instantly reappear.
Empty .git (no commits) works because it stays on the "Fallback ID".
Suggested Fix:
OpenCode should consistently use the repository's root absolute path for the projectID, or implement a migration logic that transfers sessions from the "unborn" state to the "first-commit" state once the root hash becomes available.
Conclusion for maintainers:
The workspace identity is non-deterministic during the transition from an empty repository to the first commit. This causes a permanent loss of visibility for any sessions created in that "pre-commit" window.
Activity
github-actions commentedon Mar 2, 2026
This issue might be a duplicate of existing issues. Please check:
If this is the same underlying issue (sessions being scoped/filtered by directory context), please add any additional info there or confirm if your issue differs.
lightrao commentedon Mar 2, 2026
lightrao commentedon Mar 2, 2026
lightrao commentedon Mar 2, 2026
Update on my findings:
After further testing, I noticed something very strange: not every directory with a .git folder triggers this issue. >
In some of my other Git-enabled project directories, opencode sessions correctly lists the global history.
However, in this specific project (Hp450G4SshAccess), the presence of .git consistently hides all sessions.
This suggests the bug isn't just triggered by "any" .git folder, but perhaps by a specific configuration or metadata within certain Git repositories (e.g., repository depth, origin URL format, or nested structures).
lightrao commentedon Mar 2, 2026
lightrao commentedon Mar 2, 2026
Conclusion for maintainers:
The workspace identity is non-deterministic during the transition from an empty repository to the first commit. This causes a permanent loss of visibility for any sessions created in that "pre-commit" window.
fix: list all sessions regardless of git context (anomalyco#15678)
fix(session): scope session list to current directory to prevent cros…