diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 57c3de2..5e4c566 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -11,9 +11,11 @@ jobs: runs-on: ubuntu-latest continue-on-error: true strategy: + fail-fast: false matrix: features: - claude-code + - claude-code-mounts baseImage: - debian:latest - ubuntu:latest @@ -24,6 +26,15 @@ jobs: - name: "Install latest devcontainer CLI" run: npm install -g @devcontainers/cli + - name: "Create test prerequisites" + run: | + mkdir -p ~/.claude/agents + mkdir -p ~/.claude/commands + mkdir -p ~/.claude/hooks + touch ~/.claude/settings.json + touch ~/.claude/CLAUDE.md + + - name: "Generating tests for '${{ matrix.features }}' against '${{ matrix.baseImage }}'" run: devcontainer features test --skip-scenarios -f ${{ matrix.features }} -i ${{ matrix.baseImage }} . diff --git a/src/claude-code-mounts/NOTES.md b/src/claude-code-mounts/NOTES.md new file mode 100644 index 0000000..89dda4b --- /dev/null +++ b/src/claude-code-mounts/NOTES.md @@ -0,0 +1,56 @@ +# Using Claude Code Mounts in devcontainers + +## Requirements + +This feature requires: + +1. The Claude Code CLI to be installed (use the `claude-code` feature first) +2. Claude Code configuration files to exist on your host machine at `~/.claude/` +3. HOME environment variable to be properly set on the host system + +Note: On Windows, ensure the HOME environment variable is set (e.g. using "Edit user environment variables" in the system settings). + +## Recommended configuration + +For most setups, we recommend using this feature together with the main Claude Code feature: + +```json +"features": { + "ghcr.io/devcontainers/features/node:1": {}, + "ghcr.io/anthropics/devcontainer-features/claude-code:1": {}, + "ghcr.io/anthropics/devcontainer-features/claude-code-mounts:1": {} +} +``` + +## What gets mounted + +This feature mounts the following Claude Code configuration files and directories from your host machine: + +- `~/.claude/CLAUDE.md` - Global project instructions (read-only) +- `~/.claude/settings.json` - Claude Code configuration (read-only) +- `~/.claude/agents/` - Custom agent configurations (read-only) +- `~/.claude/commands/` - Custom command definitions (read-only) +- `~/.claude/hooks/` - Event-driven shell commands (read-only) + +All mounts are read-only to prevent accidental modification from within the container. + +## Installation order + +This feature uses `installsAfter` to ensure it runs after: +1. Node.js feature (if used) +2. Claude Code feature + +This ensures the Claude Code CLI is available before mounting configuration files. + +## Troubleshooting + +### Errors when building the dev container + +- Ensure that mounted files and directories exist on host machine +- Check that the HOME environment variable is set correctly +- Ensure the devcontainer has been rebuilt after adding this feature + +### Permission issues + +- All mounts are read-only by design +- If you need to modify configuration, do so on the host machine and restart the container \ No newline at end of file diff --git a/src/claude-code-mounts/devcontainer-feature.json b/src/claude-code-mounts/devcontainer-feature.json new file mode 100644 index 0000000..e11d596 --- /dev/null +++ b/src/claude-code-mounts/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "name": "Claude Code CLI Mounts", + "id": "claude-code-mounts", + "version": "1.0.5", + "description": "Mounts the directories and files required for Claude Code", + "options": {}, + "documentationURL": "https://github.com/anthropics/devcontainer-features/tree/main/src/claude-code", + "licenseURL": "https://github.com/anthropics/devcontainer-features/blob/main/LICENSE", + "installsAfter": [ + "ghcr.io/devcontainers/features/node:1", + "ghcr.io/anthropics/devcontainer-features/claude-code:1" + ], + "mounts": [ + "source=${localEnv:HOME}/.claude/CLAUDE.md,target=/home/vscode/.claude/CLAUDE.md,type=bind,ro", + "source=${localEnv:HOME}/.claude/settings.json,target=/home/vscode/.claude/settings.json,type=bind,ro", + "source=${localEnv:HOME}/.claude/agents,target=/home/vscode/.claude/agents,type=bind,ro", + "source=${localEnv:HOME}/.claude/commands,target=/home/vscode/.claude/commands,type=bind,ro", + "source=${localEnv:HOME}/.claude/hooks,target=/home/vscode/.claude/hooks,type=bind,ro" + ] +} \ No newline at end of file diff --git a/src/claude-code-mounts/install.sh b/src/claude-code-mounts/install.sh new file mode 100644 index 0000000..085edd5 --- /dev/null +++ b/src/claude-code-mounts/install.sh @@ -0,0 +1,7 @@ +#!/bin/sh +set -eu + +echo "Activating feature 'claude-code-mounts'" + +mkdir -p $_REMOTE_USER_HOME/.claude +chown $_REMOTE_USER:$_REMOTE_USER $_REMOTE_USER_HOME/.claude