Skip to content

api: session list by ?directory= returns nothing when the path has a trailing separator #53735

Open

Description

@vc

Summary

GET /api/session?directory=... returns zero sessions when the directory query parameter carries a trailing path separator (/ or \), while the same path without the trailing separator returns the sessions. The filter is otherwise tolerant (case- and separator-insensitive), so the trailing separator is an un-normalized special case.

Observed consequence: the TUI session list (ctrl+x l) can be empty in a directory that has sessions — the same sessions are visible via opencode session list and via ?directory= without the trailing separator.

Environment

  • opencode version: 2.0.24 (npm @opencode/cli)
  • OS: Microsoft Windows 10 Pro, win32 x64
  • Shells: Cygwin bash and pwsh; one project directory is a git repository

Reproduction

A project with sessions whose directory is D:/Users/strelok/.opencode-notes:

GET /api/session?directory=D:/Users/strelok/.opencode-notes&subpath            -> 1
GET /api/session?directory=D:/Users/strelok/.opencode-notes/&subpath           -> 0   (trailing /)
GET /api/session?directory=D:\Users\strelok\.opencode-notes&subpath            -> 1
GET /api/session?directory=D:\Users\strelok\.opencode-notes\&subpath           -> 0   (trailing \)

Same behaviour on a large project (50 = page limit, not the real count):

GET /api/session?directory=D:/MyDocs/My%20Devices/_lan/_OS/node3.home&subpath  -> 50
GET /api/session?directory=D:/MyDocs/My%20Devices/_lan/_OS/node3.home/&subpath -> 0

Adding an explicit project parameter does not help: ?directory=.../&project=<id>&subpath also returns 0.

Expected Behavior

The directory filter should normalize the incoming path the same way it already handles case and separators — i.e. strip a trailing path separator before matching. A directory with a trailing separator should return the same sessions as without.

Actual Behavior

A single trailing separator turns the match into "no sessions".

Impact

The TUI session list for the current directory can be empty even though the sessions exist and are reachable. On the affected machine the TUI showed an empty list for D:\Users\strelok\.opencode-notes, while opening the same directory through a junction path (D:\home\strelok\.opencode-notes) showed the session. This is the same family of "sessions invisible in the list" issues as #53450 and #53454.

Suggested fix

Normalize the directory query parameter (and any path compared against it) by trimming trailing separators before matching, in both the API layer and the project/session listing path.

Activity

  1. github-actions commented on Oct 7, 2026

    @github-actions
    Contributor

    This issue might be a duplicate of existing issues. Please check:

  2. opencode-agent commented on Oct 7, 2026

    @opencode-agent
    Contributor

    Thanks for the clear report! I could reproduce this on 2.0.24 (on Linux, with /):

    1. Create a session in a directory, e.g. POST /api/session with {"location":{"directory":"<dir>"}}.
    2. GET /api/session?directory=<dir>&subpath returns the session.
    3. GET /api/session?directory=<dir>/&subpath returns {"data":[]}. Leaving out &subpath or encoding the slash as %2F gives the same result.

    It looks like the directory filter compares the stored session directory with the query value exactly, so a trailing separator never matches. Oddly, opencode2 api GET /api/session --param directory=<dir>/ does return the session, so the CLI seems to normalize the value before sending it. I haven't checked the Windows-specific parts (trailing \, junction paths) or the TUI list myself.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions