diff --git a/src/claude-code/README.md b/src/claude-code/README.md index c383602..9ccbe37 100644 --- a/src/claude-code/README.md +++ b/src/claude-code/README.md @@ -60,7 +60,11 @@ If your container already has Node.js installed (for example, a container based When using with containers that have nvm pre-installed, you can use the Claude Code feature directly, and it will use the existing Node.js installation. +## Persistent configuration +This feature automatically mounts a named volume at `/claude-config` and sets `CLAUDE_CONFIG_DIR=/claude-config` in the container user's shell profiles. This consolidates all Claude data — including `~/.claude.json` — into a single persisted location, so credentials, settings, and login state survive container rebuilds with no manual configuration required. + +The `postCreateCommand` provided by this feature fixes ownership of the volume directory after mounting. --- diff --git a/src/claude-code/devcontainer-feature.json b/src/claude-code/devcontainer-feature.json index c9ba494..9f42b7c 100644 --- a/src/claude-code/devcontainer-feature.json +++ b/src/claude-code/devcontainer-feature.json @@ -1,9 +1,19 @@ { "name": "Claude Code CLI", "id": "claude-code", - "version": "1.0.5", + "version": "1.1.0", "description": "Installs the Claude Code CLI globally", "options": {}, + "mounts": [ + { + "source": "claude-config-${devcontainerId}", + "target": "/claude-config", + "type": "volume" + } + ], + "postCreateCommand": { + "fix-claude-config-ownership": "sudo chown -R $(id -u):$(id -g) /claude-config || true" + }, "documentationURL": "https://github.com/anthropics/devcontainer-features/tree/main/src/claude-code", "licenseURL": "https://github.com/anthropics/devcontainer-features/blob/main/LICENSE", "customizations": { diff --git a/src/claude-code/install.sh b/src/claude-code/install.sh index b115c9e..c323de0 100755 --- a/src/claude-code/install.sh +++ b/src/claude-code/install.sh @@ -118,6 +118,17 @@ EOF exit 1 } +# Set CLAUDE_CONFIG_DIR=/claude-config in shell profiles so all Claude data +# (including .claude.json) is stored in the mounted volume at /claude-config. +setup_persist_config() { + REMOTE_HOME=$(getent passwd "${_REMOTE_USER:-}" 2>/dev/null | cut -d: -f6 || echo "$HOME") + for profile in "$REMOTE_HOME/.bashrc" "$REMOTE_HOME/.profile" "$REMOTE_HOME/.zshrc" "$REMOTE_HOME/.bash_profile"; do + if [ -f "$profile" ] && ! grep -q "CLAUDE_CONFIG_DIR" "$profile"; then + echo 'export CLAUDE_CONFIG_DIR="/claude-config"' >> "$profile" + fi + done +} + # Main script starts here main() { echo "Activating feature 'claude-code'" @@ -134,6 +145,9 @@ main() { # Install Claude Code CLI install_claude_code || exit 1 + + # Point CLAUDE_CONFIG_DIR at the mounted volume for persistent storage + setup_persist_config } # Execute main function