Skip to content

create persistent claude config storage using named volume#39

Open
IlmLV wants to merge 1 commit into
anthropics:mainfrom
IlmLV:main
Open

create persistent claude config storage using named volume#39
IlmLV wants to merge 1 commit into
anthropics:mainfrom
IlmLV:main

Conversation

@IlmLV
Copy link
Copy Markdown

@IlmLV IlmLV commented Apr 16, 2026

Summary

  • Mounts a named volume at /claude-config (scoped to devcontainerId) so Claude data survives container rebuilds without manual configuration
  • Sets CLAUDE_CONFIG_DIR=/claude-config in the container user's shell profiles, consolidating all Claude data — including the normally homeless ~/.claude.json — into the
    mounted volume
  • postCreateCommand fixes volume directory ownership after mounting (Docker creates volumes as root)
    • Config is isolated from the host — the container gets its own Claude credentials and settings, independent of the host machine

Problem

Claude Code stores most data in ~/.claude/ but writes its main config file to ~/.claude.json (outside the directory). A volume mount at ~/.claude alone does not persist ~/.claude.json, requiring re-login on every rebuild.

Symlinking ~/.claude to a mounted volume does not work — the Claude CLI cannot read credentials through a symlinked directory.

Solution

Using CLAUDE_CONFIG_DIR redirects all Claude storage, including ~/.claude.json, into a single directory that is directly volume-mounted. No symlinks involved. The named volume is scoped to the devcontainer instance, keeping credentials isolated from the host and other containers.

Try it out

  "features": {
    "ghcr.io/ilmlv/anthropics-devcontainer-features-persistent-config/claude-code:1": {}
  },

Test plan

  • First devcontainer run, execute Claude CLI — login required
  • Rebuild devcontainer without cache, execute Claude CLI — config and auth still present
  • echo $CLAUDE_CONFIG_DIR in terminal shows /claude-config
  • ls /claude-config shows .claude.json and credentials after first login

PR very similar to #34, difference is usage of ENV defined config directory.
Closes: #24
Related to: #34

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.

[feature request] Mounts for Claude config

1 participant