Skip to content

devcontainer: add agent variant with host-mirrored worktree paths - #2365

Merged
Curtis Man (curtisman) merged 3 commits into
microsoft:mainfrom
curtisman:agentcontainer
May 19, 2026
Merged

Curtis Man (curtisman) merged 3 commits into
microsoft:mainfrom
curtisman:agentcontainer

Conversation

@curtisman

@curtisman Curtis Man (curtisman) commented May 19, 2026 •

Copy link
Copy Markdown
Member

Summary

Adds a new .devcontainer/agent/ variant designed for VS Code agent windows that auto-create git worktrees, and cleans up some related dead code in the existing variants.

Why

VS Code's Copilot agent window creates worktrees at <dirname(repo)>/<basename(repo)>.worktrees/<branch>. That base path is computed as a pure function of the repository root, with no setting to override it. In the existing devcontainer setup the worktree therefore lives at /workspaces/<repo>.worktrees/<branch> inside the container, which a separate host VS Code window cannot open. The agent variant mirrors the host path inside the container so both sides see identical paths.

(Note: this only applies to the agent-host code path. The Git extension's manual Create Worktree command is a separate code path that does honor a stored root and prompts for a destination; it is unaffected by this change.)

Tracked upstream as microsoft/vscode#293884.

What changed

New agent variant (.devcontainer/agent/devcontainer.json, local-only):

  • bind-mounts the repo at its host absolute path (instead of /workspaces/<repo>)
  • bind-mounts <repo>.worktrees at the matching host path
  • initializeCommand pre-creates the worktrees dir on the host
  • updateRemoteUserUID: true so codespace can write through the bind mount
  • keeps ts/node_modules on a named volume (native modules stay container-local)
  • hardening: userEnvProbe: none, --cap-drop=ALL with a minimal allowlist for the post-create chown/sudo path and sshd, and --pids-limit

Cleanup in standard / vnc:

  • Removed the unused typeagent-agent-worktrees-* named volume. The volume only existed to give agent worktrees a writable spot inside the container, but the worktrees were not visible from the host so the agent flow did not actually work end-to-end. Codespaces handles agent worktrees natively (single VM, shared paths); local Docker uses the agent variant.
  • Dropped the matching worktree-prep step from post-create.sh and the matching prefix from start-devcontainer.sh --clean.
  • post-create.sh now discovers ts/node_modules via git rev-parse rather than scanning /workspaces, so it works for variants that bind-mount outside /workspaces.

start-devcontainer.sh:

  • --config accepts short names (vnc, agent) that resolve to .devcontainer/<name>/devcontainer.json. Full paths still work.

README: reorganized by reader intent (TL;DR -> variant selection -> quick start -> variants in detail -> working inside -> SSH -> AI agents + hardening -> reference -> troubleshooting). Clarified the three startup paths (VS Code "Reopen in Container", CLI wrapper, Codespaces) and how each handles ~/.gitconfig. De-duplicated EACCES recipes and removed a stale chown -R workspace footgun.

Validation

  • .devcontainer/scripts/start-devcontainer.sh --config agent --recreate builds and runs post-create cleanly.
  • Standard / vnc continue to build; existing Codespaces flow unaffected.

Adds .devcontainer/agent/ - a local-only variant designed for VS Code
agent windows that auto-create git worktrees. VS Code's Copilot CLI
agent writes worktrees to a hardcoded <dirname(repo)>/<basename(repo)>.worktrees
and that path is not configurable, so a host VS Code window cannot
otherwise open a worktree the in-container agent created. The agent
variant mirrors the host path inside the container so both sides see
identical paths:

- bind-mounts the repo at its host absolute path (instead of /workspaces/<repo>)
- bind-mounts <repo>.worktrees at the matching host path
- initializeCommand pre-creates the worktrees dir on the host
- updateRemoteUserUID: true so codespace can write through the bind
- keeps ts/node_modules on a named volume (native modules stay container-local)

Hardening on the agent variant: userEnvProbe none, cap-drop ALL with a
minimal allowlist for the post-create chown/sudo path, and pids-limit.

Other devcontainer changes:

- start-devcontainer.sh --config accepts short names (vnc, agent) that
  resolve to .devcontainer/<name>/devcontainer.json.
- Remove the unused typeagent-agent-worktrees-* named volume from
  standard and vnc. The volume only existed to give agent worktrees a
  writable spot inside the container, but the worktrees weren't visible
  from the host so the agent flow didn't actually work end-to-end.
  Codespaces handles agent worktrees natively (single VM, shared paths);
  local Docker uses the agent variant.
- Drop the matching worktree-prep step from post-create.sh, and the
  matching prefix from start-devcontainer.sh --clean.
- Make post-create.sh discover ts/node_modules via git rev-parse rather
  than scanning /workspaces, so it works for variants that bind-mount
  outside /workspaces.

README: reorganized by reader intent (TL;DR -> variant selection ->
quick start -> variants in detail -> working inside -> SSH -> AI agents
+ hardening -> reference -> troubleshooting). Clarified that VS Code
'Reopen in Container' projects host ~/.gitconfig automatically via
dev.containers.copyGitConfig, distinguishing the three startup paths
(VS Code, CLI wrapper, Codespaces). De-duplicated EACCES recipes and
removed a stale chown -R workspace footgun.
@curtisman
Curtis Man (curtisman) added this pull request to the merge queue May 19, 2026
Merged via the queue into microsoft:main with commit 973b32f May 19, 2026
13 of 15 checks passed
@curtisman
Curtis Man (curtisman) deleted the agentcontainer branch May 19, 2026 17:09

This branch had an error being deployed

1 failed deployment
development-fork — f32453ea Deployed May 19, 2026 by curtisman via shell_and_cli (windows-latest, 22) #5596
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