GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — server: mkdir EEXIST on shell/<projectID> makes session silently fall back to home directory · Issue #59817 · anomalyco/opencode

server: mkdir EEXIST on shell/<projectID> makes session silently fall back to home directory #59817

New issue
Copy link
New issue
Copy link
Closed
Closed
server: mkdir EEXIST on shell/<projectID> makes session silently fall back to home directory#59817
Copy link
Labels
reproduced

Description

@iadelas
iadelas
opened on Oct 28, 2026
Issue body actions

Summary

When the per-project shell directory cannot be created (EEXIST because a file with the project-ID name exists in ~/.local/share/opencode/shell/), every request against that location returns HTTP 500 and the TUI silently starts the session in the user's home directory instead of the directory it was launched from. The agent then reads and edits files in the wrong folder with no error shown.

Environment

  • opencode version: v2.2.0
  • OS: Windows 11 Pro 10.0.26300 (win32 x64)
  • Terminal: VS Code integrated terminal (TERM_PROGRAM=vscode, TERM=xterm-256color, COLORTERM=truecolor)
  • Shell: PowerShell 5.1
  • Install/channel: npm (@opencode/cli), channel latest, connected to the shared background service (opencode serve --service)
  • Active plugins: @dietrichgebert/ponytail 5.3.2, local plugin <config-dir>/plugins/i-have-adhd.js

Reproduction

  1. Ensure <data-dir>/shell/<projectID> exists as a 0-byte file rather than a directory (in my case 7 such files were created in one batch, all named after project IDs).
  2. cd into that project (a git repo) and run opencode.
  3. Send one message.

Expected Behavior

The new session uses the launch directory. If the location cannot be loaded, OpenCode should report the failure instead of moving the session elsewhere.

Actual Behavior

  • The location fails to load and returns HTTP 500 on GET /api/fs/list:
cause="Error: EEXIST: file already exists, mkdir '<data-dir>\shell\<projectID>'"
    at ServerProcess.start (...)
http.method=GET http.url=/api/fs/list http.status=500
  • The TUI subscribes to a watcher for the launch directory and then stops it a few dozen milliseconds later, subscribing to the home directory instead.
  • The session row ends up with directory = C:\Users\<me> while the tab record is stored under the launch directory, so the two disagree.
  • opencode session list run inside the project also returns UnexpectedStatus: 500.
  • No warning or error is shown in the TUI; the agent just works in the wrong directory.

Additional Context

  • ~/.local/share/opencode/shell/ contained normal per-project directories plus several 0-byte files whose names are project IDs, all created within the same second. mkdir then fails with EEXIST for those projects.
  • Deleting the empty files and running opencode service restart fixes it: the location loads and the session gets the correct directory.
  • Duplicate project rows exist for the same checkout (one row with ID global and one with the hash ID). The stale shell entry belongs to the hash ID, so this may also involve project deduplication.
  • Suggested fixes: ignore or clean up non-directory entries in <data-dir>/shell/ before mkdir, and if a location fails to load, keep the launch directory or surface the error rather than silently falling back to home.

Activity

  1. opencodejr commented on Oct 28, 2026

    @opencodejr
    opencodejrBot
    on Oct 28, 2026
    Contributor
    More actions

    Thanks for the detailed report. I can reproduce this on v2.2.0, and it still happens on the latest dev (86ce19d).

    What I did, in a fresh git project:

    1. Put an empty file (not a directory) at <data-dir>/shell/<projectID>.
    2. Started the service and opened the TUI in the project.
    3. Sent a message.

    What happened:

    • The server fails to load the location with EEXIST: file already exists, mkdir '<data-dir>/opencode/shell/<projectID>', and GET /api/fs/list returns 500.
    • The TUI drops the project's watchers right after subscribing and starts the session in the home directory. The prompt footer shows ~ instead of the project, and no error is shown.
    • opencode session list in the project fails with UnexpectedStatus: 500.

    The first screenshot below shows the home screen with the stale file present, and the second is the same run without it, where the footer shows ~/files:main. The recording shows the full run. The script below reproduces it.

    The server problem looks like it comes from the per-project shell output directory being created at location startup without handling an existing non-directory entry. Until it's fixed, deleting the empty files in <data-dir>/shell/ and running opencode service restart works around it, as you found.

    Possibly related: #59371 (duplicate project rows for one checkout) and #55670 (location/project errors not shown in the TUI).

    recording.mp4

    Screenshot

    Screenshot

    Reproduction script (drive.ts)
    // Reproduces #59817: a regular file at <data>/shell/<projectID> makes the location fail (EEXIST)
    // and the TUI silently starts the session somewhere other than the launch directory.
    // Run: opencode-drive start --script ./drive.ts   (add --dev /path/to/opencode for a checkout)
    import { Effect } from "effect"
    import { execFileSync } from "node:child_process"
    import { mkdirSync, rmSync, writeFileSync, readdirSync } from "node:fs"
    import { join } from "node:path"
    import { defineScript, Llm } from "opencode-drive"
    
    export default defineScript({
      launch: "manual",
      project: { git: true, files: { "README.md": "launch directory project\n" } },
      tui: { recording: true },
      run: ({ server, tuis, llm, artifacts }) =>
        Effect.gen(function* () {
          const project = join(artifacts, "files")
          const id = execFileSync("git", ["rev-list", "--max-parents=0", "HEAD"], { cwd: project }).toString().trim()
          // Drive sets XDG_DATA_HOME=<artifacts>/logs, so the shell dir is <artifacts>/logs/opencode/shell
          const shell = join(artifacts, "logs", "opencode", "shell")
          mkdirSync(shell, { recursive: true })
          rmSync(join(shell, id), { recursive: true, force: true })
          writeFileSync(join(shell, id), "") // 0-byte FILE named after the project ID
          console.log("project dir:", project, "project id:", id, "shell entries:", readdirSync(shell))
    
          yield* server.launch()
          const tui = yield* tuis.launch("main", { recording: true })
          yield* Effect.sleep("3 seconds")
          yield* tui.ui.screenshot("before-submit")
          yield* llm.queue(Llm.text("Hello from the simulated model."))
          yield* tui.ui.submit("Which directory am I in?")
          // The footer of the home screen shows "~" (home) instead of the launch directory.
          yield* Effect.sleep("6 seconds")
          yield* tui.ui.screenshot("after-reply")
        }),
    })

    Run it with opencode-drive: opencode-drive run ./drive.ts. It drives opencode from your PATH.

  2. opencodejr
    added
    reproduced
    on Oct 28, 2026
  3. Shubham-Padkonde commented on Oct 28, 2026

    @Shubham-Padkonde
    Shubham-Padkonde
    on Oct 28, 2026
    More actions

    I'd like to investigate the failed-location fallback and add regression coverage so a session cannot silently switch away from its requested directory.

  4. dawalberto commented on Oct 29, 2026

    @dawalberto
    dawalberto
    on Oct 29, 2026
    More actions

    I encountered the same symptoms on macOS with an Apple Silicon M1 MacBook Pro and OpenCode v2.2.1, but my root cause was different from the one described in this issue.

    Symptoms:

    • Running opencode from a project directory silently opened the session in ~ instead of the project.
    • The /cd command failed with Failed to change directory and UnexpectedStatus: 500.
    • The same issue occurred in the desktop app.
    • No zero-byte files were found in ~/.local/share/opencode/shell/.

    Root cause: an incompatible Intel Git executable was taking precedence over macOS's system Git.

    The OpenCode logs showed:

    Error: EBADARCH: unknown error, posix_spawn '/usr/local/bin/git'
    

    My terminal was running natively on ARM (arch returned arm64). However, /usr/local/bin/git was a symlink to ../git/bin/git, and file -L /usr/local/bin/git showed only Intel architectures (x86_64 and i386). The system Git at /usr/bin/git worked correctly on Apple Silicon.

    Running type -a git showed /usr/local/bin/git before /usr/bin/git, explaining why OpenCode was trying to launch the incompatible executable.

    Fix:

    I backed up the old symlink instead of deleting it:

    sudo mv /usr/local/bin/git /usr/local/bin/git.intel-backup
    rehash

    After that, command -v git returned /usr/bin/git, and OpenCode successfully opened the project in the correct directory again.

    No project files needed to be changed, and there was no need to delete anything from OpenCode's shell directory.

    Takeaway: If you experience the same symptoms but find no zero-byte files in shell, check the OpenCode logs for EBADARCH and verify which Git executable is being used. An incompatible Git binary earlier in PATH can cause the same HTTP 500 errors and silent fallback to the home directory.

  5. neriousy commented on Nov 23, 2026

    @neriousy
    neriousy
    on Nov 23, 2026
    Member
    More actions

    This was fixed in #64889, which creates the shell output directory per command, so a stray file there no longer breaks session loading. If you still see this on the latest version, comment here and we'll reopen.

  6. neriousy
    closed this as completedon Nov 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    reproduced

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      You are visitor 01402775 — GeezerVison does not store the pages you look up.
      Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.