Skip to content

POST /session ignores directory query parameter for session record #23607

Closed as not planned

Description

@Arthur-GH

Summary

When creating a session via POST /session?directory=/path/to/project, the server ignores the directory query parameter and sets the session's directory field to process.cwd() instead.

Context

OpenChamber (desktop GUI) runs a single OpenCode server and uses the directory query parameter to scope sessions to different project directories. The SDK correctly sends directory as a query param on session creation:

// From @opencode-ai/sdk
create(D, B) {
  let F = p0([D], [{args: [
    {in: "query", key: "directory"},  // ← sent but ignored
    {in: "query", key: "workspace"},
    {in: "body", key: "parentID"},
    {in: "body", key: "title"},
    ...
  ]}]);
  return this.client.post({url: "/session", ...});
}

But the resulting session in the SQLite DB always has directory = process.cwd(), regardless of the query param value.

Evidence

  • Launched OpenCode server from /Users/me (via OpenChamber desktop)
  • Created session with directory=/Users/me/projects/myapp via the SDK
  • DB shows: directory: /Users/me, project_id: global
  • Changed server cwd to /Users/me/projects via a wrapper script
  • New sessions now show directory: /Users/me/projects — confirming the field comes from process.cwd(), not the query param

Expected behavior

When directory is provided as a query parameter on POST /session, the session record should use that value for its directory field (and resolve the matching project accordingly).

Environment

  • opencode-ai: 1.14.19
  • OS: macOS (arm64)
  • Client: OpenChamber 1.9.6

Activity

  1. added
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on Apr 20, 2026
  2. removed
    coreAnything pertaining to core functionality of the application (opencode server stuff)
    on May 3, 2026
  3. github-actions commented on Jul 6, 2026

    @github-actions
    Contributor

    To stay organized issues are automatically closed after 60 days of no activity. If the issue is still relevant please open a new one.

  4. GuoChen-thlg commented on Aug 27, 2026

    @GuoChen-thlg

    OpenCode 的"新建会话"按钮不调用 POST /session API
    它创建一个 draft(草稿) 存储在前端内存中
    然后导航到 /new-session?draftId=xxx 页面
    用户在该页面输入消息后,才会调用 POST /session 创建实际会话
    这就是为什么 API 忽略 projectID 的原因 — OpenCode 自己的前端也不通过 API 指定项目,而是通过 ctx.projects.open(directory) 设置当前项目上下文,然后在该上下文中创建会话。

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