Skip to content

Commit f4aae83

Browse files
blue126claude
andcommitted
fix(devcontainer): mount the checkout at the host path, and pin the server's PATH
The opencode desktop app sends the host's path when opening a project and lists sessions by exact string match on it, while the server stores whatever realPath() resolves to. A symlink from the host path to /workspaces/IaC satisfied the first half and broke the second: every session was filed under a path the app never asks about, so the list came up empty — including sessions the app had just created. Mount the checkout a second time at its host path instead; a bind mount has nothing to resolve, so write and read agree. This also makes `docker run -v $(pwd)` work, which the host Docker daemon could never resolve before. Existing rows were rewritten to the host path out of band. Also drop remoteEnv. Setting PATH there replaced the probed user PATH rather than extending it, which lost ~/.local/bin and made postCreateCommand fail on ansible-galaxy. opencode-serve.sh now puts both user bin directories on PATH itself, so the server hands the agent a working toolchain no matter how the script was invoked — a lifecycle hook gets the probed PATH, a plain docker exec does not. Refs: anomalyco/opencode#44150, #44216 Co-Authored-By: Claude Opus 5 <[email protected]>
1 parent 1deb085 commit f4aae83

2 files changed

Lines changed: 34 additions & 40 deletions

File tree

‎.devcontainer/devcontainer.json‎

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -77,21 +77,30 @@
7777
"source=iac-home,target=/home/vscode,type=volume",
7878
// Share Claude Code config (auth, settings, memory) between host and container
7979
"source=${localEnv:HOME}/.claude,target=/home/vscode/.claude,type=bind",
80-
"source=${localWorkspaceFolder}/.opencode/auth.json,target=/mnt/opencode-auth.json,type=bind"
80+
"source=${localWorkspaceFolder}/.opencode/auth.json,target=/mnt/opencode-auth.json,type=bind",
81+
// WORKAROUND — the same checkout, mounted a second time at the exact path it
82+
// has on the host, so /workspaces/IaC and /Users/<you>/Projects/IaC are both
83+
// this repository.
84+
//
85+
// The opencode desktop app runs on the host: it sends its own path when
86+
// opening a project, and lists sessions by exact string match on that same
87+
// path. The server, meanwhile, stores whatever realPath() resolves to. A
88+
// symlink here resolves to /workspaces/IaC, so what gets stored never
89+
// matches what the app asks for and the app lists nothing. A bind mount has
90+
// nothing to resolve: realPath returns the path the app sent, so write and
91+
// read agree.
92+
//
93+
// Remove this once the app can browse the server's filesystem when attached
94+
// to a remote server (anomalyco/opencode#44150, #44216).
95+
"source=${localWorkspaceFolder},target=${localWorkspaceFolder},type=bind"
8196
],
8297
// Environment variables available in container
8398
"containerEnv": {
84-
// Host workspace path. Two consumers, both of them symlink workarounds for
85-
// tools that assume the host and the container see the same paths:
86-
// post-create.sh links Claude Code's project history, whose directory
87-
// name is derived from the workspace path, so host and
88-
// container sessions land in one place
89-
// opencode-serve.sh links the host path itself to /workspaces/IaC. The
90-
// opencode desktop app's project picker browses the
91-
// HOST filesystem and sends what you pick to the server
92-
// in here, so without this every prompt dies in
93-
// FileSystem.realPath and the app shows no reply at
94-
// all. See anomalyco/opencode#44150.
99+
// Host workspace path, used by post-create.sh to link Claude Code's project
100+
// history: its directory name is derived from the workspace path, so host
101+
// and container sessions would otherwise land in two separate places.
102+
// (opencode's version of the same problem is handled by the second mount
103+
// above, not here.)
95104
"HOST_WORKSPACE_FOLDER": "${localWorkspaceFolder}",
96105
// Install the latest Codex CLI release during post-create
97106
"CODEX_CLI_VERSION": "latest",
@@ -100,12 +109,6 @@
100109
// published to the host's loopback).
101110
"OPENCODE_SERVER_PASSWORD": "${localEnv:OPENCODE_SERVER_PASSWORD}"
102111
},
103-
// Where opencode-serve.sh's installer puts opencode. Its own PATH handling is
104-
// skipped whenever the version is already current, so it cannot be relied on.
105-
// remoteEnv, not containerEnv: only remoteEnv can expand ${containerEnv:PATH}.
106-
"remoteEnv": {
107-
"PATH": "/home/vscode/.opencode/bin:${containerEnv:PATH}"
108-
},
109112
// Runs on the HOST, on create and on every start. Brings up the Playwright MCP
110113
// server the container's agents drive, so the browser they open is a real one
111114
// on your screen. Detaches immediately; no-op when it is already running.

‎.devcontainer/opencode-serve.sh‎

Lines changed: 13 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,19 @@
1616

1717
set -euo pipefail
1818

19+
# The server inherits this PATH and hands it to every command the agent runs, so
20+
# it has to be right regardless of how this script was invoked. A lifecycle hook
21+
# gets the profile-probed PATH, but a plain `docker exec` gets the bare container
22+
# one — and then the agent cannot find ansible, which lives in ~/.local/bin.
23+
# Declare both user bin directories rather than depending on the caller.
24+
for d in "${HOME}/.local/bin" "${HOME}/.opencode/bin"; do
25+
case ":${PATH}:" in
26+
*":${d}:"*) ;;
27+
*) PATH="${d}:${PATH}" ;;
28+
esac
29+
done
30+
export PATH
31+
1932
port="${OPENCODE_SERVE_PORT:-4096}"
2033
workdir="${OPENCODE_SERVE_DIR:-/workspaces/IaC}"
2134
log="${HOME}/.local/share/opencode/serve.log"
@@ -52,28 +65,6 @@ else
5265
echo "opencode serve: ${host_auth} not readable; server will have no providers" >&2
5366
fi
5467

55-
# WORKAROUND — make the host's path for this repo resolve in here too.
56-
#
57-
# The opencode desktop app runs on the host and its project picker browses the
58-
# HOST filesystem, but the server runs in this container. Picking the project
59-
# hands the server a path like /Users/<you>/Projects/IaC, which it opens
60-
# literally; with no such path here, every prompt dies in FileSystem.realPath
61-
# and the app shows no reply at all — no error, nothing. See
62-
# anomalyco/opencode#44150, and #40136 / #5380 for the same class of bug.
63-
#
64-
# Known limitation: realPath resolves this symlink back to ${workdir}, so
65-
# anything the server reports back to the app carries the container's path,
66-
# which means nothing on the host. Reads work; a round trip may not. Mounting
67-
# the checkout a second time at the host's own path avoids that, at the cost of
68-
# a second mount in devcontainer.json.
69-
#
70-
# HOST_WORKSPACE_FOLDER comes from devcontainer.json's containerEnv.
71-
if [[ -n "${HOST_WORKSPACE_FOLDER:-}" && ! -e "${HOST_WORKSPACE_FOLDER}" ]]; then
72-
sudo mkdir -p "$(dirname "${HOST_WORKSPACE_FOLDER}")"
73-
sudo ln -sfn "${workdir}" "${HOST_WORKSPACE_FOLDER}"
74-
echo "opencode serve: mapped ${HOST_WORKSPACE_FOLDER} -> ${workdir}"
75-
fi
76-
7768
# Keep the server in step with the desktop app, which updates itself on the host.
7869
# Installing here rather than through the devcontainer feature means the version
7970
# is not frozen by the image layer cache, and the installer's target,

0 commit comments

Comments
 (0)