feat: Copy project subagents to Claude runtime environment

Enables custom subagents defined in .claude/agents/ to work in GitHub Actions by:
- Checking for project agents in GITHUB_WORKSPACE/.claude/agents/
- Creating ~/.claude/agents/ directory if needed
- Copying all .md agent files to Claude's runtime location
- Following same pattern as slash commands for consistency

Includes comprehensive test coverage for the new functionality.
This commit is contained in:
km-anthropic
2025-08-14 15:29:05 -07:00
parent d91030de69
commit 632f04bbcf
2 changed files with 93 additions and 0 deletions

View File

@@ -79,4 +79,31 @@ export async function setupClaudeCodeSettings(
console.log(`Slash commands directory not found or error copying: ${e}`);
}
}
// Copy project subagents to Claude's agents directory
// Use GITHUB_WORKSPACE if available (set by GitHub Actions), otherwise use current directory
const workspaceDir = process.env.GITHUB_WORKSPACE || process.cwd();
const projectAgentsDir = `${workspaceDir}/.claude/agents`;
const claudeAgentsDir = `${home}/.claude/agents`;
try {
await $`test -d ${projectAgentsDir}`.quiet();
console.log(`Found project agents directory at ${projectAgentsDir}`);
// Ensure target agents directory exists
await $`mkdir -p ${claudeAgentsDir}`.quiet();
// Copy all .md files from project agents to Claude's agents directory
await $`cp ${projectAgentsDir}/*.md ${claudeAgentsDir}/ 2>/dev/null || true`.quiet();
// Count copied agents for logging
const agentFiles = await $`ls ${claudeAgentsDir}/*.md 2>/dev/null | wc -l`
.quiet()
.text();
const agentCount = parseInt(agentFiles.trim()) || 0;
console.log(`Copied ${agentCount} agent(s) to ${claudeAgentsDir}`);
} catch (e) {
// Directory doesn't exist or no agents to copy - this is expected in most cases
console.log(`No project agents directory found at ${projectAgentsDir}`);
}
}