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 #59817DescriptionSummary
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
- 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).
cd into that project (a git repo) and run opencode.
- 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.
Activityopencodejr commented on Oct 28, 2026 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:
- Put an empty file (not a directory) at
<data-dir>/shell/<projectID>.
- Started the service and opened the TUI in the project.
- 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


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.
Shubham-Padkonde commented on Oct 28, 2026 I'd like to investigate the failed-location fallback and add regression coverage so a session cannot silently switch away from its requested directory. dawalberto commented on Oct 29, 2026 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. neriousy commented on Nov 23, 2026 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.
MetadataMetadataDevelopmentNo branches or pull requestsIssue actions
|