Skip to content

opencode sessions command fails to list historical sessions when run inside a Git repository #15678

Closed

Description

@lightrao

Description

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

  1. Open a terminal in a directory that is a Git repo (ls -a shows .git).

  2. Run opencode session list. Result: Empty. (or use /sessions command)

  3. Move out of the directory or rename .git.

  4. Run opencode session list. Result: All sessions appear. (or use /sessions command)

Screenshot and/or share link

No response

Operating System

macOS (MacBook Air M2) version 26.3

Terminal

zsh

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Mar 2, 2026
  2. github-actions commented on Mar 2, 2026

    @github-actions
    Contributor

    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.

  3. lightrao commented on Mar 2, 2026

    @lightrao
    Author

    Thanks for the heads-up, @github-actions.

    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:

    1. In a non-git directory, session list works perfectly.

    2. Once a .git folder is present, the list becomes empty.

    3. 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.

  4. lightrao commented on Mar 2, 2026

    @lightrao
    Author

    One more crucial detail regarding the reproduction steps:
    In my project directory, I actually used opencode first (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.

  5. lightrao commented on Mar 2, 2026

    @lightrao
    Author

    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).

  6. lightrao commented on Mar 2, 2026

    @lightrao
    Author

    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:

    1. 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".

    2. 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...).

    3. Phase 3 (The ID Shift): OpenCode immediately switches the active projectID to this new commit hash (and caches it in .git/opencode).

    4. 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.

  7. lightrao commented on Mar 2, 2026

    @lightrao
    Author

    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.

  8. added a commit that references this issue on Mar 9, 2026
    dc90982
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingcoreAnything pertaining to core functionality of the application (opencode server stuff)

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions