Analyze how Claude Code is used and surface concrete improvements — new agents/skills to reduce repetition, or consolidate lessons into governance files (rules, agent instructions, skill updates) — without duplicating what exists.
NOT for single-file edits or quality checks — see when_to_use.
NOT for audit-only scan for extraction candidates (use /foundry:audit --efficiency instead of distill executables for detection-only).
- $ARGUMENTS: optional. Modes:
- Omitted — analyze existing patterns and agents; generate suggestions proactively.
prune [--eager]— evaluate project memory file for stale, redundant, or verbose entries. Default: advisory diff + apply prompt.--eager: score every entry (Usage likelihood × Impact → Tier P0/P1/P2), print full scored table with#column, let user select by tier or item numbers, delegate edits tofoundry:curator.lessons [--eager]— read.notes/lessons.mdand memory feedback files, distill recurring patterns into proposed rule files, agent instruction updates, and skill workflow changes.--eager: include Pattern count, Strength, and Tier columns in proposal table; let user select clusters to promote by tier or item numbers; delegate writes tofoundry:curator.review [--eager]— review existing agent/skill roster for quality and gaps without suggesting new additions.--eager: lower overlap flag threshold from >50% to >30% scope coverage; surface any shared single capability between agents as boundary issue; add "Sharpen Boundary" section to output.external <source> [--eager]— analyse external plugin, skill, or agentic resource and produce structured adoption proposal.<source>is URL, file path, or local directory.--eager: lower adoption bar — recommend partial adoption even for single useful components.executables [--eager] [<run-dir-or-report-path>]— perform bin/ extraction from/foundry:audit --efficiencyCheck 33 candidates. Auto-detects latest run dir under.reports/audit/; pass optional path to target a specific run dir or report file. Runs inline Check 33 scan when no report exists. Default gates on HIGH/MEDIUM verdict.--eager: also surface LOW verdict clusters as extraction candidates. Spawnsfoundry:sw-engineerper cluster. Skip to Mode: Executables Extraction below.[--eager] <recurring task description>— use description as context when generating suggestions.--eager: lower frequency threshold from 3+ to 2+ occurrences; single high-effort occurrence also qualifies.
Task hygiene:
# audit-skip: resilience-replication
_FS=$(python "${CLAUDE_PLUGIN_ROOT:-plugins/foundry}/bin/resolve_shared_path.py" foundry skills/_shared 2>/dev/null || echo "plugins/foundry/skills/_shared") # timeout: 5000
Read $_FS/task-hygiene.md — follow task hygiene protocol.
# Parse --eager flag; strip from ARGUMENTS before mode dispatch
EAGER=false
[[ "$ARGUMENTS" == *"--eager"* ]] && EAGER=true
ARGUMENTS=$(echo "$ARGUMENTS" | sed 's/--eager//g' | xargs) # timeout: 3000
Step 1: Inventory existing agents and skills
Use Glob tool to enumerate agents and skills across all sources — project-local AND plugin-namespaced — to avoid false-gap findings when candidate already exists in plugin:
- Project-local: pattern
agents/*.md, path.claude/; patternskills/*/SKILL.md, path.claude/ - Plugin source (workspace): pattern
*/agents/*.md, pathplugins/; pattern*/skills/*/SKILL.md, pathplugins/ - Installed plugin cache (if accessible): resolve cache root —
PLUGIN_CACHE="${CLAUDE_PLUGIN_ROOT:-plugins/foundry}"— then use Glob tool on$PLUGIN_CACHEfor pattern*/agents/*.mdand*/skills/*/SKILL.md
For each agent/skill found, extract: name, description, tools, purpose. Tag each entry with plugin namespace (e.g. foundry:sw-engineer, oss:resolve) — used in Step 3 gap analysis to prevent recommending duplicates of plugin-namespaced agents/skills.
Step 2: Analyze work patterns
If $ARGUMENTS first whitespace-delimited token equals executables (i.e. executables alone or executables <path>, NOT a path or word that merely starts with the string executables): skip Steps 2–5 entirely and go to "Mode: Executables Extraction" below.
If $ARGUMENTS is prune: skip Steps 2–5 entirely and go to "Mode: Memory Pruning" below.
If $ARGUMENTS is lessons: skip Steps 2–5 entirely and go to "Mode: Lessons Distillation" below.
If $ARGUMENTS first whitespace-delimited token equals external (i.e. external <source>, NOT a word that merely starts with the string external): skip Steps 2–5 entirely and go to "Mode: External Distillation" below.
If $ARGUMENTS is review: skip git analysis below and go directly to Step 3 (Gap analysis). Use agent/skill descriptions from Step 1 as sole input — goal is to assess quality and coverage of existing roster, not look for new patterns in recent work. In Step 5, suppress all "Recommend: New Agent/Skill" sections and output only "Existing Coverage", "Recommend: Enhance Existing", and "No Action Needed" entries. With --eager: apply stricter overlap detection in Step 4 (threshold drops to >30%; any shared single named capability flags as boundary issue); add "Recommend: Sharpen Boundary" section to Step 5 output listing all partial-overlap pairs with specific capability to split.
Otherwise, look for signals of repetitive or specialist work. First three git commands are independent — run in parallel:
# timeout: 3000
# --- run these three in parallel ---
# Recent git history — what kinds of changes are common?
git log --oneline -50
# What file types are being worked on?
git log --name-only --pretty="" -30 | sort | uniq -c | sort -rn | head -20
# Commit message patterns — what verbs appear most?
git log --oneline -100 | cut -d' ' -f2 | sort | uniq -c | sort -rn | head -15
Then use Glob tool (pattern todo_*.md, path .plans/active/) to list active task files; read each with Read tool. Also read .notes/lessons.md (if exists) for task history and conversation hints.
If $ARGUMENTS provided, use as additional context for pattern analysis.
Frequency Heuristics
- 3+ occurrences of pattern in recent history → candidate for automation
- 2+ different projects using same manual process → cross-project skill
- significant manual effort per occurrence (subjective — use git history context) → high-value automation target
- Domain-specific knowledge required → candidate for specialist agent (not just skill)
With --eager (lower thresholds):
- 2+ occurrences → candidate for automation
- 1 occurrence with significant manual effort → qualifies as high-value candidate
- Domain-specific threshold unchanged
Step 3: Gap analysis
reviewmode: focus on agent/skill quality and coverage gaps — skip "Recommend: New Agent/Skill" analysis and focus on "Existing Coverage" and "Recommend: Enhance Existing".
For each identified pattern, check:
- Already covered? — search existing agent/skill descriptions for overlap
- Frequent enough? — recurring ≥ 3 times or clearly domain-specialized (See Step 2 heuristics — combine ≥3 occurrences with effort/frequency signals from Steps 1–2)
- Would specialist add quality? — does it require deep domain knowledge?
- Too narrow? — single-use task doesn't warrant persistent agent
Thresholds for recommendation:
- New agent: recurring specialist role, complex decision-making, 5+ distinct capabilities
- New skill: workflow orchestration, multi-step process with fixed structure
- No new file needed: one-off or already covered by existing agent
Step 4: Check for duplication
reviewmode: duplication checks still apply — review mode does not skip this step.
Before recommending anything, run overlap check and anti-pattern checklist:
For ea