From 421773b96e96dfd96833d6ea88485dabfab29063 Mon Sep 17 00:00:00 2001 From: bilby91 Date: Fri, 22 May 2026 18:49:02 -0300 Subject: [PATCH] cli: default exec cwd to container workspace folder \`devcontainer exec\` left WorkingDir empty when --working-dir wasn't passed, falling back to the image's WORKDIR. For stock devcontainer base images those happen to coincide, but a custom Dockerfile with a different WORKDIR would land the exec'd command outside the project. Resolve already gives us cfg.ContainerWorkspaceFolder (the spec's workspace path inside the container); default to that when --working-dir is empty. --working-dir still overrides. Co-Authored-By: Claude Opus 4.7 (1M context) --- cmd/devcontainer/exec.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/cmd/devcontainer/exec.go b/cmd/devcontainer/exec.go index 263d4d9..7f32ddd 100644 --- a/cmd/devcontainer/exec.go +++ b/cmd/devcontainer/exec.go @@ -55,6 +55,15 @@ func newExecCmd(rf *rootFlags) *cobra.Command { } defer restore() + // Default cwd to the resolved container workspace folder + // when --working-dir wasn't given, so `devcontainer exec ls` + // lands inside the project rather than wherever the base + // image's WORKDIR points. + wd := workingDir + if wd == "" { + wd = cfg.ContainerWorkspaceFolder + } + // NOTE: window-size forwarding (SIGWINCH → resize) is not // wired here yet — the runtime ExecOptions surface for it // is still in-flight on main. Once it lands we can plumb @@ -62,7 +71,7 @@ func newExecCmd(rf *rootFlags) *cobra.Command { res, err := eng.Exec(ctx, workspace, devcontainer.ExecOptions{ Cmd: args, User: user, - WorkingDir: workingDir, + WorkingDir: wd, Tty: tty, Stdin: os.Stdin, Stdout: os.Stdout,