--- description: Build a complete autonomous agent system. Guided 7-phase workflow that interviews you, scaffolds agents, skills, hooks, and configures deployment. argument-hint: Optional focus area (e.g., "marketing pipeline" or "research agent") allowed-tools: ["Read", "Write", "Edit", "Glob", "Grep", "Bash", "Agent", "AskUserQuestion"] --- You are running `/agent-builder:build` — a guided 7-phase workflow for building a complete autonomous agent system with Claude Code. If $ARGUMENTS is provided, use it as context for the system being built. Tailor every phase to that domain. Work through phases sequentially. After completing each phase, tell the user what files were created or modified and offer to continue to the next phase or stop. The user can resume any time by invoking this command again. --- ## Phase 1: Map Your Work Goal: Understand the user's actual workflows before designing anything. Ask the user the following questions using AskUserQuestion. Ask them one at a time, wait for each answer before proceeding. **Question 1 — Repeating tasks:** "What weekly tasks do you do that follow a pattern? List 3-5 specific tasks. For each one, describe: what triggers it, what inputs it needs, what processing happens, and what the output looks like." **Question 2 — Roles:** "If you could hire 2-3 assistants for these tasks, what roles would they fill? For each role, describe: what expertise they'd have, what they'd produce, and how you'd know they did a good job." **Question 3 — Hard limits:** "What must NEVER happen automatically? List actions that always need your approval, things that should never be logged, and any systems or files that are off-limits." After collecting all three answers, produce a design sketch in this format: ``` PIPELINE DESIGN =============== Trigger: [what starts the pipeline] Stage 1: [Role A] takes [input] → produces [output] Stage 2: [Role B] takes [Stage 1 output] → produces [output] Stage 3: [Role C] takes [Stage 2 output] → produces [final output] Hard limits enforced by hooks: - [limit 1] - [limit 2] Files to create in Phase 3: - .claude/agents/[role-a].md - .claude/agents/[role-b].md - .claude/agents/[role-c].md ``` Show this sketch to the user and confirm before proceeding. --- ## Phase 2: Operating Manual Goal: Create or improve CLAUDE.md so agents have accurate context. Interview the user across 5 categories. Use AskUserQuestion. Ask one category at a time. **Category 1 — Who you are:** "Describe yourself and your role. What's your job, your domain, and your main focus right now?" **Category 2 — How you communicate:** "How do you prefer Claude to communicate with you? Language, tone, format, things you want Claude to never say or do?" **Category 3 — What you're working on:** "What are your active projects right now? What's the current priority and what does 'done' look like?" **Category 4 — Tools and environment:** "What tools, APIs, and systems do you use regularly? Any platform constraints (OS, shell version, paths)?" **Category 5 — Hard rules:** "What should Claude never do? Any actions, files, systems, or topics that are strictly off-limits?" Generate CLAUDE.md in the project root. Structure it with these sections: - Who I am - How I communicate - What I'm working on - Tools and environment - What you must never do - Memory (leave blank for now — the pipeline will populate this) Validate against 5 criteria before writing: 1. Specific enough — no vague phrases like "be helpful" 2. Priorities are current — reflects what the user said, not generic goals 3. Boundaries are clear — hard limits are explicit and actionable 4. Tools are documented — includes versions or paths where relevant 5. Format preferences stated — language, length, tone are specified If any criterion fails, ask a follow-up question before writing. Tell the user: "Created CLAUDE.md. Review it and edit freely — this is your operating manual, not mine." --- ## Phase 3: Agent Team Goal: Create .claude/agents/*.md files for each role identified in Phase 1. Read the design sketch from Phase 1. Create one agent file per role. Default starting roles (adapt to the user's domain from Phase 1): - researcher.md — gathers information, verifies sources, produces research briefs - writer.md — produces first drafts from research briefs - reviewer.md — evaluates quality, flags issues, requests revisions Read ${CLAUDE_PLUGIN_ROOT}/scripts/templates/pre-tool-use.sh for reference on the security patterns used — agents should be scoped to avoid the same dangerous patterns. Each agent file must follow this structure: ```markdown --- name: [role name] description: [one sentence — what this agent does and when to invoke it] tools: [comma-separated list of tools this agent needs] model: claude-sonnet-4-5 --- You are [role name] for [user's domain]. ## How you work [3-5 bullet points describing the agent's process] ## Rules - [rule 1 — specific to this role] - [rule 2] - [rule 3 — include at least one "never do" rule] ## Output format [Describe the exact output format: headings, length, structure] ``` Create the directory .claude/agents/ if it does not exist. After creating each agent file, tell the user: "Created .claude/agents/[name].md — [one-line summary of what it does]." After all agents are created, test each one individually: - Run each agent on a simple representative task from the user's domain - Ask the user: "Does [agent name]'s output look right? What would you change?" - Make adjustments before moving to Phase 4. --- ## Phase 4: Pipeline Goal: Create a skill that chains the agents into an end-to-end pipeline. Ask the user using AskUserQuestion: "What should we name this pipeline? This becomes the slash command: /[name]" Create .claude/skills/[pipeline-name].md with a 9-step structure: ```markdown --- description: [One sentence describing what this pipeline produces] argument-hint: [What to pass as input, e.g., "topic or URL"] allowed-tools: ["Read", "Write", "Edit", "Bash", "Agent"] --- Run this pipeline end-to-end. $ARGUMENTS is the input. **Step 1 — Load context** Read CLAUDE.md. Read memory state if it exists (look for a Memory section in CLAUDE.md or a separate memory file). Summarize current priorities in one sentence before proceeding. **Step 2 — Research** Use the researcher agent: pass $ARGUMENTS and the current context. The agent produces a research brief. Save it to pipeline-output/research-[date].md. **Step 3 — Draft** Use the writer agent: pass the research brief. The agent produces a first draft. Save it to pipeline-output/draft-[date].md. **Step 4 — Review** Use the reviewer agent: pass the draft. The agent produces a scored evaluation with specific revision requests. Save it to pipeline-output/review-[date].md. **Step 5 — Revision loop** If the reviewer flagged issues: - Pass the draft and review back to the writer agent with instruction to revise - Re-run the reviewer - Repeat up to 2 times - If still below threshold after 2 revisions, stop and report to the user **Step 6 — Save output** Write the final draft to pipeline-output/final-[date].md. **Step 7 — Update memory** Update the Memory section in CLAUDE.md with: - Date of last run - Topic processed - Quality score from reviewer - Any recurring issues to watch for **Step 8 — Confirm** Report to the user: - What was produced (file path) - Reviewer score - Time taken (approximate) - Any issues encountered **Evaluation rubric:** - Level 4 (send as-is): Meets all quality criteria, no changes needed - Level 3 (minor edits): Good structure and content, needs 10 minutes of editing - Level 2 (rework): Structure is right, content needs significant work - Level 1 (not usable): Does not meet minimum quality threshold — escalate to user ``` Tell the user: "Created .claude/skills/[pipeline-name].md. Run it with /[pipeline-name] [your topic]." --- ## Phase 5: Security Goal: Add hooks that enforce the hard limits from Phase 1. Read the user's "hard limits" from Phase 1. Read the template at ${CLAUDE_PLUGIN_ROOT}/scripts/templates/pre-tool-use.sh. Read the template at ${CLAUDE_PLUGIN_ROOT}/scripts/templates/post-tool-use.sh. Create the .claude/hooks/ directory if it does not exist. **Pre-tool-use hook:** Copy pre-tool-use.sh from the template into .claude/hooks/pre-tool-use.sh. Customize the blocked_patterns array to include: - All patterns from the template (keep the safe defaults) - One pattern per hard limit the user specified in Phase 1 - Any file paths or systems the user marked as off-limits (e.g., blocking rm on those paths) **Post-tool-use hook:** Copy post-tool-use.sh from the template into .claude/hooks/post-tool-use.sh. Keep the default audit logging behavior. Change the log_file path to .claude/hooks/audit.log. **Settings file:** Create .claude/settings.json: ```json { "permissions": { "allow": [ "Bash(git *)", "Bash(npm *)", "Read(*)", "Write(.claude/*)", "Write(pipeline-output/*)" ], "deny": [ "Bash(rm -rf *)" ] }, "hooks": { "PreToolUse": [ { "matcher": "*", "hooks": [ { "type": "command", "command": "bash .claude/hooks/pre-tool-use.sh" } ] } ], "PostToolUse": [ { "matcher": "*", "hooks": [ { "type": "command", "command": "bash .claude/hooks/post-tool-use.sh" } ] } ] } } ``` Customize permissions.deny to match the user's hard limits from Phase 1. Ask the user using AskUserQuestion before writing settings.json: "I'm about to create .claude/settings.json with these permissions. Does this match what you want? [show the deny list]" Tell the user: "Created hooks and settings.json. The audit log will be written to .claude/hooks/audit.log after each tool call." --- ## Phase 6: Deployment Goal: Configure automated scheduling for the pipeline. Ask the user using AskUserQuestion: "Where will this pipeline run? Choose one: 1. Local — your own machine, cron schedule 2. Mac Mini — dedicated Mac, launchd + tmux 3. VPS — Linux server, systemd 4. Managed Agents — Anthropic API (no local scheduling needed)" Create the automation/ directory if it does not exist. **Option 1 — Local (cron):** Read ${CLAUDE_PLUGIN_ROOT}/scripts/templates/automation.sh. Copy it to automation/run-pipeline.sh. Replace SKILL_NAME with the pipeline name from Phase 4. Replace OUTPUT_DIR with pipeline-output. Ask the user: "What time should this run, and how often? (e.g., daily at 07:00)" Generate a cron entry and show it to the user with instructions: ``` # Add to crontab with: crontab -e 0 7 * * * /bin/bash /path/to/your-project/automation/run-pipeline.sh >> /tmp/claude-pipeline.log 2>&1 ``` **Option 2 — Mac Mini (launchd):** Read ${CLAUDE_PLUGIN_ROOT}/scripts/templates/launchd.plist. Copy it to automation/com.yourdomain.claude-pipeline.plist. Ask the user: "What time should this run? (e.g., 07:00)" and "What is your reverse-DNS label? (e.g., com.yourname)" Customize Label, ProgramArguments, and log paths. Copy automation.sh template to automation/run-pipeline.sh and customize it. Provide setup instructions: ``` cp automation/com.yourdomain.claude-pipeline.plist ~/Library/LaunchAgents/ launchctl load ~/Library/LaunchAgents/com.yourdomain.claude-pipeline.plist launchctl list | grep claude ``` **Option 3 — VPS (systemd):** Read ${CLAUDE_PLUGIN_ROOT}/scripts/templates/systemd-service.unit. Copy it to automation/claude-pipeline.service. Ask the user: "What Linux user runs the agent?" and "What is the absolute path to your project?" Customize User, WorkingDirectory, ExecStart, and EnvironmentFile. Copy automation.sh template to automation/run-pipeline.sh and customize it. Provide setup instructions including the timer unit from the template comments. **Option 4 — Managed Agents:** Use the deployment-advisor agent to generate API code. Pass the pipeline name, agent list, and any relevant context from previous phases. Save generated code to automation/managed-agents-client.ts (TypeScript) or automation/managed-agents-client.py (Python) based on user preference. Tell the user what files were created and provide the exact commands needed to activate the schedule. --- ## Phase 7: Test and Iterate Goal: Run the pipeline on real work and calibrate based on results. Ask the user using AskUserQuestion: "Give me a real task from your actual week — something you'd normally spend time on — so we can test the pipeline end-to-end." Run the pipeline skill on that task. Use the evaluation rubric from Phase 4: - Level 4 (send as-is): No changes needed. Tell the user: "Pipeline is working well." - Level 3 (needs 10 min editing): Identify the specific gaps. Ask: "Want me to adjust the writer or reviewer agent to close these gaps?" - Level 2 (structure right, content off): Diagnose which stage broke down. Suggest targeted changes to that agent's prompt. - Level 1 (not usable): Stop. Ask the user to describe what a good output would look like. Revise the agents based on that description, then re-run. After the test, provide a day-by-day plan for the first week: ``` Day 1: Run the pipeline manually on 2-3 tasks. Note what needs editing. Day 2: Review audit.log. Identify the most common edit you made. Day 3: Update the agent prompt that caused that edit. Re-run one task. Day 4: Let the automation schedule run. Check the output. Day 5: Review the week. What worked? What still needs manual work? ``` Ask the user using AskUserQuestion: "Based on the test run, what one thing would make this pipeline most useful to you right now?" Implement that one change before closing the session. --- ## Summary After all phases are complete (or the user stops early), print a summary: ``` AGENT SYSTEM BUILT ================== Agents: .claude/agents/[list] Pipeline: .claude/skills/[name].md Hooks: .claude/hooks/pre-tool-use.sh, post-tool-use.sh Settings: .claude/settings.json Schedule: automation/[script or config] Run your pipeline: /[pipeline-name] [your topic] Review logs: .claude/hooks/audit.log ``` If the user stopped early, tell them which phase to continue from and remind them that this command can be re-invoked at any time.