Skip to content

cli: default exec cwd to container workspace folder#80

Merged
bilby91 merged 1 commit into
mainfrom
cli/exec-default-cwd
May 22, 2026
Merged

cli: default exec cwd to container workspace folder#80
bilby91 merged 1 commit into
mainfrom
cli/exec-default-cwd

Conversation

@bilby91
Copy link
Copy Markdown
Member

@bilby91 bilby91 commented May 22, 2026

Summary

devcontainer exec used to leave WorkingDir empty when --working-dir wasn't passed, which made the runtime fall back to the image's WORKDIR. For stock devcontainer base images those happen to coincide with the spec's containerWorkspaceFolder, but a custom Dockerfile with a different WORKDIR would land the exec'd command outside the project — surprising for users running devcontainer exec ls.

Default to cfg.ContainerWorkspaceFolder when --working-dir is empty. The flag still overrides.

Test plan

  • `devcontainer exec --no-tty -- pwd` → `/workspaces/`
  • `devcontainer exec --no-tty --working-dir /tmp -- pwd` → `/tmp` (override still works)
  • `go vet`, `golangci-lint run`, linux cross-build clean

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes
    • The exec command now defaults to the container workspace folder as the working directory when --working-dir is not specified, providing more intuitive behavior for common use cases.

Review Change Stack

\`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) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 61059bf9-5af5-4796-85db-ea5b5f810c2b

📥 Commits

Reviewing files that changed from the base of the PR and between 47b6958 and 421773b.

📒 Files selected for processing (1)
  • cmd/devcontainer/exec.go

📝 Walkthrough

Walkthrough

The exec command in cmd/devcontainer/exec.go now defaults the container execution working directory to the resolved container workspace folder (cfg.ContainerWorkspaceFolder) when the --working-dir flag is not provided, rather than leaving it empty. This computed default is wired into the ExecOptions structure.

Changes

Exec Working Directory Default

Layer / File(s) Summary
Working directory defaulting logic
cmd/devcontainer/exec.go
A computed wd variable defaults WorkingDir to cfg.ContainerWorkspaceFolder when --working-dir is omitted, and this value is passed to ExecOptions.WorkingDir.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Poem

🐰 A rabbit hops through working paths,
No flag means home—a sensible default.
The workspace blooms where execution lands,
No empty strings to break our hopeful stance.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'cli: default exec cwd to container workspace folder' accurately and concisely describes the main change: making the exec command default its working directory to the container workspace folder.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch cli/exec-default-cwd

Comment @coderabbitai help to get the list of available commands and usage tips.

@bilby91 bilby91 merged commit 5e9ef13 into main May 22, 2026
18 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant