Skip to content

claude-code: share volumes via fixed compose names (variants per project, Bun store across projects) #236

Closed

Description

@gatezh

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-config

Part 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 mounts names use ${localWorkspaceFolderBasename}, so each worktree has its own node_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 shared node_modules across 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 ~/.claude stays per-variant.
  • Logins. gh/cf logins 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-store mounted at ~/.bun/install/cache, with a fixed name: and no project prefix, so every project's devcontainer mounts the same volume.
  • Global store. The project sets globalStore = true in bunfig.toml: Bun keeps each package once in the store's links/, and node_modules holds symlinks to it. It goes in bunfig.toml, not the devcontainer, so CI installs the same layout and catches a package that breaks under the store.
  • Results. node_modules dropped 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/install and ~/.bun/install/cache in updateContentCommand, without -R (the store can be gigabytes). In this image, pre-create /home/node/.bun/install/cache node-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 install rebuilds 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 ~/.bun on 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, then bun install in each project. Until then, their node_modules symlinks point at nothing.

Bun version

Affected files

  • claude-code/.devcontainer/docker-compose.yml, claude-code/.devcontainer/claude-sandbox/docker-compose.yml
  • claude-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 second bun install links 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

Activity

  1. added
    enhancement
    on Oct 22, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancement

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions