Skip to content

claude-code: persist CLI logins (gh, cf) once per machine, not as per-repo copies #231

Open

Description

@gatezh

Summary

CLI logins (gh, cf) only survive a rebuild if a repo's own devcontainer.json declares a volume for them, and most repos made from this template don't. cf persistence landed in c560581 (2026-10-08) as two more lines to copy into every repo. Most repos never got them, so cf auth login is lost on every rebuild there.

Each project also logs in separately (one volume per project, and per variant: #209). Every gh auth login mints another OAuth token, and GitHub's cap of 10 per user and app revokes the least recently used one. So logging in to one project can sign another out.

How far repos have drifted

Of 10 downstream repos checked on 2026-10-20, only 2 have the cf volume, and 5 lack the older gh volume too.

Why a copy per repo can't be fixed from here

  • Image metadata or a Feature could carry mounts centrally. The spec puts mounts in the devcontainer.metadata label, and Features support mounts with ${devcontainerId} (the docker-in-docker Feature does this).
  • But under Compose (this template), devcontainers/cli turns every mount into a Compose service volume. It writes only external: true into the top-level volumes: entry, never name: (src/spec-node/dockerCompose.ts, convertMountToVolumeTopLevelElement). So any mount from devcontainer.json, a label or a Feature gets Compose's project prefix ([BUG] default and sandbox variants don't share volumes (Compose project-name prefix) #209). An external volume has to exist first, which needs a host-side initializeCommand in each repo.
  • A fixed top-level name: in docker-compose.yml is the one way to get an unprefixed volume that Compose creates on first use. It works: a Bun package store shared across projects already uses it downstream.

Proposal

  1. Declare the login volumes in docker-compose.yml with fixed names, one per machine:

    services:
      devcontainer:
        volumes:
          - gh-config:/home/node/.config/gh
          - cloudflare-config:/home/node/.config/cloudflare
    volumes:
      gh-config:
        name: devcontainers-gh-config
      cloudflare-config:
        name: devcontainers-cloudflare-config

    Then remove the two mounts entries from both devcontainer.json files. chown stays as it is (the Dockerfile already pre-creates both directories). The sandbox variant gets the same block, so it shares the login. That resolves the login part of [BUG] default and sandbox variants don't share volumes (Compose project-name prefix) #209.

    • Benefit: you log in once per machine. There is one gh token, so projects stop revoking each other's.
    • Cost: every devcontainer on the machine holds the same gh and cf credentials. That is already true of the account; per-project volumes isolate only the token, not what it can reach.
  2. Keep repos in step: add the block to the sync manifest of the devcontainer-upstream-sync skill, so an audit catches a repo without it. That is the per-repo step that remains until devcontainers/cli passes name: through.

  3. Optional, upstream of this repo: ask devcontainers/cli to pass a mount's name (or a "no project prefix" flag) through to Compose. Mounts could then move into the image's devcontainer.metadata label, and repos would need no edit at all.

Open questions

Related

Activity

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions