From 596572efefb63a2e3382a48f3df32c5a4ab38883 Mon Sep 17 00:00:00 2001 From: John Haley Date: Tue, 12 Aug 2025 21:02:04 -0700 Subject: [PATCH 1/2] feat: Add support for Claude agents in ClaudeBox containers MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Sync agents from ~/.claude/agents to project-specific directories - Create symlink in containers to make agents available at standard location - Follow same pattern as commands with checksum-based change detection - Enable per-project agent isolation This allows users to use their locally defined Claude agents within ClaudeBox containers, maintaining the same project isolation model used for commands. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- build/docker-entrypoint | 8 +++++++ lib/project.sh | 49 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+) diff --git a/build/docker-entrypoint b/build/docker-entrypoint index 1964b1b..5e24391 100644 --- a/build/docker-entrypoint +++ b/build/docker-entrypoint @@ -306,6 +306,14 @@ else fi fi + # Create symlink from ~/.claude/agents to ~/.claudebox/agents + # The ~/.claudebox folder is mounted from the host + if [ -d "$HOME/.claudebox/agents" ]; then + if [ ! -e "$HOME/.claude/agents" ]; then + ln -s "$HOME/.claudebox/agents" "$HOME/.claude/agents" + fi + fi + cd /workspace # Check if .claude/projects exists and filter out -c/--continue if not diff --git a/lib/project.sh b/lib/project.sh index 4c76ea7..1159a7d 100755 --- a/lib/project.sh +++ b/lib/project.sh @@ -594,6 +594,55 @@ sync_commands_to_project() { echo "$user_checksum" > "$user_checksum_file" fi + # Sync user agents (similar to commands) + local agents_source="$HOME/.claude/agents" + local agents_dir="$project_parent/agents" + local agents_checksum_file="$project_parent/.agents_checksum" + local agents_checksum="" + + # Calculate checksum for agents if directory exists + if [[ -d "$agents_source" ]]; then + agents_checksum=$(find "$agents_source" -type f -exec stat -f "%m" {} \; 2>/dev/null | sort | md5 2>/dev/null || \ + find "$agents_source" -type f -exec stat -c "%Y" {} \; 2>/dev/null | sort | md5sum | cut -d' ' -f1) + + # Check if sync needed + local sync_agents=false + if [[ ! -f "$agents_checksum_file" ]]; then + sync_agents=true + elif [[ "$(cat "$agents_checksum_file" 2>/dev/null)" != "$agents_checksum" ]]; then + sync_agents=true + fi + + # Sync agents if needed + if [[ "$sync_agents" == "true" ]]; then + if [[ "$VERBOSE" == "true" ]]; then + echo "[DEBUG] Syncing agents to $agents_dir" >&2 + fi + + # Remove old agents and recreate + rm -rf "$agents_dir" + mkdir -p "$agents_dir" + + # Copy preserving directory structure + cd "$agents_source" + find . -type f | while read -r file; do + local dir=$(dirname "$file") + mkdir -p "$agents_dir/$dir" + cp "$file" "$agents_dir/$file" + done + cd - >/dev/null + + # Save checksum + echo "$agents_checksum" > "$agents_checksum_file" + fi + fi + + # Clean up agents directory if source doesn't exist + if [[ ! -d "$agents_source" ]] && [[ -d "$agents_dir" ]]; then + rm -rf "$agents_dir" + rm -f "$agents_checksum_file" + fi + # Clean up empty directories if sources don't exist if [[ ! -d "$cbox_source" ]] && [[ -d "$commands_dir/cbox" ]]; then rm -rf "$commands_dir/cbox" From a65fc551615ad7b2071c8752fbb97c6fb3f6fdaa Mon Sep 17 00:00:00 2001 From: John Haley Date: Wed, 13 Aug 2025 06:48:40 -0700 Subject: [PATCH 2/2] fix: Address shellcheck warning for cd command in agent sync MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Wrap cd command in if statement to handle potential failures - Ensures proper error handling as per shellcheck SC2164 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- .claude/settings.local.json | 4 +++- lib/project.sh | 15 ++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/.claude/settings.local.json b/.claude/settings.local.json index 97393f7..8409758 100644 --- a/.claude/settings.local.json +++ b/.claude/settings.local.json @@ -5,7 +5,9 @@ "Bash(tmux list-windows:*)", "Bash(ls:*)", "Bash(cat:*)", - "Bash(grep:*)" + "Bash(grep:*)", + "Bash(test:*)", + "Bash(shellcheck:*)" ] }, "enableAllProjectMcpServers": true, diff --git a/lib/project.sh b/lib/project.sh index 1159a7d..5fc801e 100755 --- a/lib/project.sh +++ b/lib/project.sh @@ -624,13 +624,14 @@ sync_commands_to_project() { mkdir -p "$agents_dir" # Copy preserving directory structure - cd "$agents_source" - find . -type f | while read -r file; do - local dir=$(dirname "$file") - mkdir -p "$agents_dir/$dir" - cp "$file" "$agents_dir/$file" - done - cd - >/dev/null + if cd "$agents_source"; then + find . -type f | while read -r file; do + local dir=$(dirname "$file") + mkdir -p "$agents_dir/$dir" + cp "$file" "$agents_dir/$file" + done + cd - >/dev/null + fi # Save checksum echo "$agents_checksum" > "$agents_checksum_file"