Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/claude-code/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.

---

Expand Down
12 changes: 11 additions & 1 deletion src/claude-code/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand Down
14 changes: 14 additions & 0 deletions src/claude-code/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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'"
Expand All @@ -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
Expand Down