Repository navigation
Description
Summary
Fix #209 at its cause instead of correcting the README: declare the template's volumes in docker-compose.yml with an explicit name:, so Compose doesn't prefix them with the project name. The default and sandbox variants then mount the same volumes, as the README already promises.
The same mechanism lets every project's devcontainer share one Bun package store. A downstream pilot has tested that part. It was waiting for a Bun release with the fix for oven-sh/bun#36795, and Bun 1.4.4 (2026-10-22) has it.
Why mounts can't do this
The devcontainer CLI turns every mounts entry into a Compose service volume. Its top-level volumes: entry never gets a name:, only external: true when the mount asks for it (convertMountToVolumeTopLevelElement in src/spec-node/dockerCompose.ts). An external volume must already exist, which needs a host-side initializeCommand in each repo. Otherwise Compose stores it as <project>_<volume>, and the variants have different project names (myproject and myproject-sandbox). Only a volume declared in the compose file with a fixed name: keeps the same name in both. Compose still creates it on first use.
services:
devcontainer:
volumes:
- ..:/workspace:cached
- claude-config:/home/node/.claude
volumes:
claude-config:
name: myproject-claude-configPart 1: per-project volumes shared by both variants (#209)
Move node_modules, ~/.claude, zsh history, ~/.config/gh and ~/.config/cloudflare from mounts to both variants' docker-compose.yml, with the same fixed names in each.
Open questions:
- Worktrees. The
mountsnames use${localWorkspaceFolderBasename}, so each worktree has its ownnode_modules. Compose can't see that variable. Check whether Compose interpolation (e.g.${COMPOSE_PROJECT_NAME}or a host env var) can keep worktrees apart, or whether a sharednode_modulesacross worktrees is acceptable now that packages link from a store (Part 2). - Existing volumes. Moving to new names drops the old prefixed volumes: users sign in again and reinstall. Document it, and how to remove the old ones.
- Sandbox and the shared
~/.claude. Sharing gives the sandbox the default variant's Claude sign-in, which is what "Sandbox Authentication" describes. It also lets an agent in the default variant (no firewall) write plugins, hooks and settings that the sandbox loads. Decide whether that's acceptable or~/.claudestays per-variant. - Logins.
gh/cflogins once per machine is claude-code: persist CLI logins (gh, cf) once per machine, not as per-repo copies #231 (undecided), so this issue only shares them between one project's two variants.
Part 2: one Bun store for every project (default variant)
Piloted downstream:
- Shared cache volume.
bun-global-storemounted at~/.bun/install/cache, with a fixedname:and no project prefix, so every project's devcontainer mounts the same volume. - Global store. The project sets
globalStore = trueinbunfig.toml: Bun keeps each package once in the store'slinks/, andnode_modulesholds symlinks to it. It goes inbunfig.toml, not the devcontainer, so CI installs the same layout and catches a package that breaks under the store. - Results.
node_modulesdropped from about 720 MB to 80–300 MB per project. The project's in-container Bun cache (about 700 MB) moved to the shared volume. A second project with the same packages installs in under a second, and switching an existing devcontainer took 0.8 s after a rebuild. Before this, Docker's disk filled up and the devcontainer stopped starting. - Ownership. A new volume and the parents Docker creates for it start root-owned. The pilot chowns
~/.bun,~/.bun/installand~/.bun/install/cacheinupdateContentCommand, without-R(the store can be gigabytes). In this image, pre-create/home/node/.bun/install/cachenode-owned with the other mount points, so Docker seeds the volume's ownership and no chown is needed. - CI cache. If CI caches
~/.bun/install/cache, exclude!~/.bun/install/cache/links:bun installrebuilds it from the downloads, and caching it about doubles what every job restores. - Trust model. Every devcontainer that mounts the store can change packages the others run: a malicious install script in one project could edit a package another project loads. It's the same as projects sharing
~/.bunon a laptop, but per-project containers had isolated them. The sandbox variant must not mount it. - Reset. Stop every devcontainer,
docker volume rm bun-global-store, thenbun installin each project. Until then, theirnode_modulessymlinks point at nothing.
Bun version
- Bun 1.4.3 and earlier can drop a package's
@types/*peer types under the global store with no error (globalStore = true makes @types/* unreachable to TypeScript from inside the link store oven-sh/bun#36795). In the pilot,cmdk's React types went missing (TS7006). The fix (install: consolidate the open package manager pull requests oven-sh/bun#44968) shipped in Bun 1.4.4. - The fix keeps such packages project-local, so a React project keeps about 300 MB instead of about 80 MB. install.globalStore: share entries whose peer is typed by
@types/*, instead of keeping them project-local oven-sh/bun#45563 asks to share them again. - A package with install scripts (wrangler, workerd) also stays project-local.
- If a package breaks under the store, add the missing dependency with
packageExtensionsinpackage.json, or setglobalStore = false.
Affected files
claude-code/.devcontainer/docker-compose.yml,claude-code/.devcontainer/claude-sandbox/docker-compose.ymlclaude-code/.devcontainer/devcontainer.json,claude-code/.devcontainer/claude-sandbox/devcontainer.json(mounts, chown commands)claude-code/.devcontainer/Dockerfile(pre-created mount points)claude-code/README.md("Shared volumes", "Sandbox Authentication"), plus a section on the shared Bun store
Acceptance
- Opening both variants of one project shows one set of volumes in
docker volume ls, and a sign-in in the default variant works in the sandbox. - Two projects on the default variant share
bun-global-store, and the secondbun installlinks from it. - The sandbox doesn't mount
bun-global-store. - A new volume is node-owned without a recursive chown.
- The README gives the upgrade steps for existing volumes and the trust model.
Related
- [BUG] default and sandbox variants don't share volumes (Compose project-name prefix) #209 (this fixes it), claude-code: persist CLI logins (gh, cf) once per machine, not as per-repo copies #231 (machine-wide logins, same mechanism, on hold), claude-code: CLAUDE_CODE_OAUTH_TOKEN over-specified as Required; no path for plugins needing a personal token (github MCP) #118 (sandbox token wording depends on the shared
~/.claude) - globalStore = true makes @types/* unreachable to TypeScript from inside the link store oven-sh/bun#36795, install: consolidate the open package manager pull requests oven-sh/bun#44968, install.globalStore: share entries whose peer is typed by
@types/*, instead of keeping them project-local oven-sh/bun#45563
Activity