Persisting Claude CLI Login Between Container Builds
Goal Keep Claude Code's account/session login ( ~/.claude.json ) alive across devcontainer rebuilds, instead of having to re-authenticate every time the image is rebuilt. The problem Claude Code keeps two things on disk: ~/.claude/ — a directory, already persisted via a named Docker volume ( claude-playwright-setup ). ~/.claude.json — a single file holding account/session state, which was not…
The Claude Code application stores account and session information in a file named ~/.claude.json. However, this file was not being persisted during container rebuilds, requiring users to re-authenticate every time the container was rebuilt. Mounting a named volume directly onto ~/.claude.json caused issues, as Docker Desktop failed to detect the single file and resulted in an empty directory.
To resolve this, the solution was to create a directory, such as ~/.claude-json, mount the named volume onto this directory, and then create a symbolic link from ~/.claude.json to the new directory. The Dockerfile was updated to include these steps, and the post-container-install.sh script ensured proper ownership was set for the new mount.
This approach allowed the ~/.claude.json file to persist across container rebuilds, eliminating the need for re-authentication.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — it may contain errors, so check the original before relying on it.