AgentSkillsCN

work

利用Agent Teams执行计划,或直接依据描述开展工作。通过组建专业化的团队成员,实现任务的并行执行。

SKILL.md
--- frontmatter
name: work
description: Execute a plan using Agent Teams, or work directly from a description. Spawns specialized teammates to implement tasks in parallel.
argument-hint: "[<plan-name>] [--resume] | <description of what to do>"
allowed-tools: Read, Grep, Glob, Bash, Task, TeamCreate, TeamDelete, SendMessage, TaskCreate, TaskList, TaskUpdate, TaskGet, AskUserQuestion
disable-model-invocation: true

You Are The Orchestrator — Execution Team Lead

Identity: Team coordinator using Claude Code's Agent Teams Core Principle: Delegate ALL implementation. You NEVER edit files directly — you coordinate.

You are now acting as The Orchestrator. You spawn teammates, assign tasks, verify results, and extract wisdom. You do NOT write code yourself.


Arguments

$ARGUMENTS

  • <plan-name>: Load a specific plan by name. Matches against filenames in .maestro/plans/ (with or without .md extension). Skips the selection prompt.
  • --resume: Resume a previously interrupted execution. Already-completed tasks (- [x]) are skipped.
  • Default (no args): Auto-load if one plan exists, or prompt for selection if multiple.

MANDATORY: Agent Teams Workflow

You MUST follow these steps in order. Do NOT skip team creation. Do NOT implement tasks yourself.

Step 1: Load Plan

Check for in-progress designs first:

code
Glob(pattern: ".maestro/handoff/*.json")

If any handoff file has "status": "designing", warn the user:

Design in progress for "{topic}". The plan may not be finalized yet. Run /design to continue the design session, or /reset to clean up and start fresh.

Ask the user whether to proceed anyway or stop.

Then load available plans from .maestro/plans/:

code
Glob(pattern: ".maestro/plans/*.md")

If a <plan-name> argument was provided (any argument that is not --resume):

  1. Look for .maestro/plans/{plan-name}.md (try exact match first, then with .md appended)

  2. If found, load it — skip the selection prompt entirely

  3. If not found, check if the argument looks like a work description using this heuristic:

    • Contains spaces, OR
    • Length > 40 characters, OR
    • Contains common action verbs: "add", "fix", "create", "update", "implement", "refactor", "remove", "change", "move", "build"

    If it looks like a description → store it as the planless work description and skip to the planless flow below.

    If it does NOT look like a description → show available plans and stop with error:

    Plan "{plan-name}" not found. Available plans: {list of plan filenames}

If no plan name argument was provided:

If 0 plans found: Stop with error:

No plans found. Run /design to create a plan, or /work <description> to work directly.

If 1 plan found: Load it automatically.

If multiple plans found: Cross-reference handoff metadata to recommend the most relevant plan.

  1. Parse all .maestro/handoff/*.json files
  2. Find handoff files with status: "complete" — sort by completed timestamp (latest first)
  3. If the latest completed handoff's plan_destination matches an existing plan file, mark it as the recommended plan

Present all plans via AskUserQuestion, with the recommended plan listed first:

code
AskUserQuestion(
  questions: [{
    question: "Which plan would you like to execute?",
    header: "Select Plan",
    options: [
      { label: "{plan title} (Recommended)", description: "Most recently designed. {objective excerpt}. {N} tasks." },
      { label: "{other plan title}", description: "{objective excerpt}. {N} tasks." },
      ...
    ],
    multiSelect: false
  }]
)

For each plan option:

  • Title: First # heading from the plan file
  • Objective excerpt: First 80 characters of the ## Objective section content
  • Task count: Number of - [ ] lines in the plan

Graceful degradation: If no handoff files exist or none have status: "complete", fall back to listing all plans with title and last modified date (current behavior).

Step 1.5: Validate & Confirm

Validate required sections in the loaded plan:

SectionRequired?On Missing
## ObjectiveYesStop with error
## Tasks (with at least one - [ ])YesStop with error
## VerificationYesStop with error
## ScopeNoWarn and proceed

If any required section is missing, stop with:

Plan is missing required sections: {list}. Fix the plan manually or run /plan-template to scaffold one with all required sections.

Check for code style guides in the host project's CLAUDE.md:

bash
grep -q "maestro:code-styleguides:start" CLAUDE.md 2>/dev/null

If the marker is NOT found (grep exits non-zero), log a non-blocking suggestion:

Tip: Run /styleguide to inject language-specific code style guides into your project's CLAUDE.md. This helps all agents produce consistent, idiomatic code.

Do NOT block execution or prompt the user. This is informational only — proceed to the next step regardless.

Show plan summary to user:

  • Plan title (first # heading)
  • Objective (content of ## Objective)
  • Task count (number of - [ ] lines)
  • Scope summary (if present)

Ask user to confirm before proceeding:

code
AskUserQuestion(
  questions: [{
    question: "Execute this plan?",
    header: "Confirm",
    options: [
      { label: "Yes, execute", description: "Proceed with team creation and task execution" },
      { label: "Cancel", description: "Stop without executing" }
    ],
    multiSelect: false
  }]
)

If user cancels, stop execution.

Common Errors

ErrorCauseFix
"unknown tool: TeamCreate"Agent Teams not enabledAdd CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS: "1" to ~/.claude/settings.json env, restart Claude Code
"team already exists"Previous session not cleaned upRun /reset to clean stale state
"No plans found"No plan file existsRun /design or /plan-template first
Plan missing required sectionsIncomplete plan fileRun /plan-template to scaffold, or add missing sections manually

Step 1.7: Worktree Isolation (Optional)

Ask the user whether to execute in an isolated worktree or in the current working tree:

code
AskUserQuestion(
  questions: [{
    question: "Where should this plan execute?",
    header: "Execution Environment",
    options: [
      { label: "Execute in worktree (isolated)", description: "Creates a git worktree on a new branch. Safe for parallel execution." },
      { label: "Execute in main tree (current behavior)", description: "Run directly in the current working directory." }
    ],
    multiSelect: false
  }]
)

If main tree chosen: Proceed to Step 2. No worktree fields are added to the handoff JSON.

If worktree chosen, follow the git-worktrees skill workflow:

1. Resolve Worktree Directory

Determine the worktree root using this priority chain:

PriorityLocationNotes
1.worktrees/Default — at project root
2worktrees/Alternate — same level
3CLAUDE.md preferenceIf project CLAUDE.md specifies a custom path
4Ask userPrompt for directory if none of the above exist

2. Safety Check — Gitignore

bash
git check-ignore -q .worktrees
  • If exit 0: .worktrees/ is already ignored — proceed.
  • If exit 1: auto-add to .gitignore:
bash
echo "" >> .gitignore
echo "# Maestro worktrees (auto-added)" >> .gitignore
echo ".worktrees/" >> .gitignore

3. Create Worktree

Derive <plan-slug> from the plan filename (without .md).

bash
git worktree add "<worktree-dir>/<plan-slug>" -b "maestro/<plan-slug>"

4. Copy Plan and Create Runtime Directories

bash
mkdir -p "<worktree-dir>/<plan-slug>/.maestro/plans"
cp ".maestro/plans/<plan-slug>.md" "<worktree-dir>/<plan-slug>/.maestro/plans/"

mkdir -p "<worktree-dir>/<plan-slug>/.maestro/handoff"
mkdir -p "<worktree-dir>/<plan-slug>/.maestro/drafts"
mkdir -p "<worktree-dir>/<plan-slug>/.maestro/wisdom"
mkdir -p "<worktree-dir>/<plan-slug>/.maestro/archive"

5. Project Setup

Detect and run the project's setup command inside the worktree directory:

FileSetup Command
package.jsonbun install
Cargo.tomlcargo build
pyproject.tomluv sync
go.modgo mod download
build.gradle / gradlew./gradlew build
pom.xml / mvnw./mvnw install

6. Test Baseline Verification

Run the project's test command inside the worktree to confirm a clean baseline. If tests fail, warn the user that failures are pre-existing and proceed.

7. Update Handoff

Update the handoff JSON with worktree metadata:

json
{
  "worktree": true,
  "worktree_path": "<absolute path to worktree>",
  "worktree_branch": "maestro/<plan-slug>"
}

All subsequent steps operate inside the worktree directory.

Error Handling

If worktree creation fails (e.g., branch name collision, dirty state, disk issues), fall back to main tree execution with a warning:

Worktree creation failed: {error}. Falling back to main tree execution.

Proceed to Step 2 without worktree fields in the handoff.

Step 1.8: Write Execution Handoff

Write (or overwrite) .maestro/handoff/{plan-slug}.json to signal that this plan is actively executing:

bash
mkdir -p .maestro/handoff/
json
{
  "topic": "{plan-slug}",
  "status": "executing",
  "started": "{ISO timestamp}",
  "plan_destination": ".maestro/plans/{plan-slug}.md"
}

Where {plan-slug} is the plan filename without .md (e.g., refactor-auth), and {ISO timestamp} is the current time in ISO 8601 format.

If a handoff file already exists (e.g., from /design with status: "complete"), overwrite it with the new "executing" status.

Step 2: Create Your Team

Do this FIRST. You are the team lead.

code
TeamCreate(
  team_name: "work-{plan-slug}",
  description: "Executing {plan name}"
)

Step 3: Create Tasks

Convert every checkbox (- [ ]) from the plan into a shared task:

code
TaskCreate(
  subject: "Task title from plan",
  description: "Full description, acceptance criteria, relevant file paths, constraints",
  activeForm: "Implementing task title"
)

Set up dependencies between tasks using TaskUpdate(addBlockedBy: [...]) where needed.

Resume mode (--resume flag): Only create tasks for unchecked items (- [ ]). Skip already-completed items (- [x]). Show summary:

Resuming: N complete, M remaining

Fresh mode (default): Create tasks for all items. Show summary:

Starting fresh: N tasks

Step 3.5: Discover Available Skills

Before spawning teammates, discover skills that can provide guidance for task delegation.

Important: The Glob tool doesn't follow symlinks. Use Bash with find to discover all skills. Note: Remove -type f for plugin paths on macOS:

bash
# Project skills (highest priority) - use -L to follow symlinks
find .claude/skills -L -name "SKILL.md" -type f 2>/dev/null
find .agents/skills -L -name "SKILL.md" -type f 2>/dev/null

# Global skills
find ~/.claude/skills -name "SKILL.md" 2>/dev/null

# Plugin-installed skills (lowest priority) - no -L or -type f for macOS compatibility
find ~/.claude/plugins/marketplaces -name "SKILL.md" 2>/dev/null

For each SKILL.md file found:

  1. Read the file
  2. Parse YAML frontmatter (between --- markers)
  3. Extract: name, description, triggers (optional), priority (default: 100)
  4. Store the full content after frontmatter

Priority: Project skills override global skills, which override plugin skills (same name = skip lower priority).

See .claude/lib/skill-registry.md for the complete discovery process.

Build a skill registry for use in Step 4:

yaml
skills:
  - name: "skill-name"
    description: "What this skill does"
    triggers: ["trigger1", "trigger2"]
    priority: 100
    content: "Full SKILL.md content after frontmatter"
    source: "project"  # or "global"

Graceful degradation: If no skills are found, proceed without skill injection. Do not error or warn.

Step 4: Spawn Teammates IN PARALLEL

Spawn ALL workers at once — not one at a time. Workers self-coordinate via the shared task list.

Send a single message with multiple parallel Task calls:

code
Task(
  description: "TDD implementation of feature X",
  name: "impl-1",
  team_name: "work-{plan-slug}",
  subagent_type: "kraken",
  prompt: "## TASK\n[Goal]\n\n## EXPECTED OUTCOME\n- [ ] File: [path]\n- [ ] Tests pass\n\n## CONTEXT\n[Background]"
)
Task(
  description: "TDD implementation of feature Y",
  name: "impl-2",
  team_name: "work-{plan-slug}",
  subagent_type: "kraken",
  prompt: "..."
)
Task(
  description: "Fix config for Z",
  name: "fixer-1",
  team_name: "work-{plan-slug}",
  subagent_type: "spark",
  prompt: "..."
)

Choose the right teammate for each task:

Teammatesubagent_typeWhen to Use
krakenkrakenTDD, new features, multi-file changes
sparksparkQuick fixes, single-file changes, config updates
exploreexploreCodebase research, finding patterns
oracleoracleStrategic decisions (uses opus — spawn sparingly)

Sizing: Spawn 2-4 workers for most plans. Each has team tools and will self-claim tasks after their first assignment.

Step 5: Assign Initial Tasks, Then Let Workers Self-Claim

Assign the first round explicitly:

code
TaskUpdate(taskId: "1", owner: "impl-1", status: "in_progress")
TaskUpdate(taskId: "2", owner: "impl-2", status: "in_progress")
TaskUpdate(taskId: "3", owner: "fixer-1", status: "in_progress")

After the first round, workers self-claim from TaskList() when they finish. You don't need to micro-manage every assignment.

Step 6: Monitor & Verify

TEAMMATES CAN MAKE MISTAKES. ALWAYS VERIFY.

Messages from teammates arrive automatically. After each teammate reports completion:

  1. Read files claimed to be created/modified
  2. Run tests claimed to pass: Bash("bun test") or project-specific command
  3. Check for lint/type errors
  4. Verify behavior matches the plan's acceptance criteria

If verification fails, message the teammate with feedback:

code
SendMessage(
  type: "message",
  recipient: "impl-1",
  content: "Tests fail: [error]. Fix and re-verify.",
  summary: "Test failure feedback"
)

Auto-Commit on Verified Task Completion

After a task passes verification (files confirmed, tests pass, lint clean), immediately commit the changes:

  1. Stage only the files related to the completed task:

    bash
    git add <file1> <file2> ...
    
  2. Commit with a descriptive message using the plan title (first # heading from the plan file) as the scope:

    bash
    git commit -m "$(cat <<'EOF'
    feat(<plan-title-as-scope>): <short description of what the task accomplished>
    
    Plan: <plan-name>
    Task: <task subject>
    
    Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
    EOF
    )"
    
    • Use conventional commit prefixes: feat, fix, refactor, test, docs, chore
    • <plan-title-as-scope> is derived from the plan's # heading, lowercased and shortened to a slug (e.g., plan titled "Code Styleguides — CLAUDE.md Injection" → scope styleguides, plan titled "Add User Auth Flow" → scope auth)
    • Keep the first line under 72 characters
  3. If there are no changes to commit (e.g., task was research-only), skip the commit silently.

This ensures each working increment is saved and the session never ends with 0 commits.

Handling Stalled Workers

If a worker stops reporting progress:

  1. Check task status: TaskGet(taskId: "N") — look for tasks stuck in in_progress
  2. Send status check:
    code
    SendMessage(
      type: "message",
      recipient: "impl-1",
      content: "Status check — are you blocked on anything?",
      summary: "Worker status check"
    )
    
  3. Reassign if no response: TaskUpdate(taskId: "N", owner: "impl-2", status: "pending")
  4. Resolve blockers: If the task has a dependency issue, create a new task to resolve the blocker first

Step 7: Extract Wisdom

After all tasks complete, record learnings to .maestro/wisdom/{plan-name}.md:

markdown
# Wisdom: {Plan Name}

## Conventions Discovered
- ...

## Successful Approaches
- ...

## Failed Approaches to Avoid
- ...

## Technical Gotchas
- ...

If executing in a worktree (handoff has "worktree": true): Copy the wisdom file back to the main tree so it persists after worktree removal:

bash
cp "<worktree-path>/.maestro/wisdom/{plan-name}.md" ".maestro/wisdom/{plan-name}.md"

Where <worktree-path> is the worktree_path value from the handoff JSON.

Step 8: Cleanup Team

Shutdown all teammates and cleanup:

code
SendMessage(type: "shutdown_request", recipient: "impl-1")
SendMessage(type: "shutdown_request", recipient: "impl-2")
// ... for each teammate
TeamDelete()

IMPORTANT: Do NOT pass any parameters to TeamDelete() — no reason, no arguments. The tool accepts no parameters and will error if any are provided.

Step 8.5: Archive Plan

Move the executed plan to the archive so .maestro/plans/ only contains unexecuted plans:

bash
mkdir -p .maestro/archive/
mv .maestro/plans/{name}.md .maestro/archive/{name}.md

Where {name} is the plan filename loaded in Step 1 (e.g., if the plan was .maestro/plans/refactor-auth.md, move it to .maestro/archive/refactor-auth.md).

Log: "Archived plan to .maestro/archive/{name}.md"

Update the handoff file to reflect the archived status:

json
{
  "topic": "{plan-slug}",
  "status": "archived",
  "started": "{original started timestamp}",
  "completed": "{ISO timestamp}",
  "plan_destination": ".maestro/archive/{plan-slug}.md"
}

Where {original started timestamp} is preserved from the existing handoff file, and {ISO timestamp} is the current time.

Only the specific executed plan is moved — other plans in .maestro/plans/ are untouched.

Step 8.7: Worktree Cleanup

Skip this step if the handoff does not have "worktree": true.

If execution ran in a worktree, perform cleanup from the main tree (not from inside the worktree):

1. Report Branch

Tell the user which branch contains the changes:

Plan complete. Changes are on branch: maestro/<plan-slug> Worktree path: <worktree-path> You can merge with: git merge maestro/<plan-slug> Or create a PR from this branch.

2. Ask User About Worktree Removal

code
AskUserQuestion(
  questions: [{
    question: "Remove the worktree now?",
    header: "Worktree Cleanup",
    options: [
      { label: "Remove worktree", description: "Delete the worktree directory. The branch is preserved for merge/PR." },
      { label: "Keep worktree", description: "Leave it in place for manual inspection. Remove later with: git worktree remove <path>" }
    ],
    multiSelect: false
  }]
)

3. If Remove

bash
git worktree remove "<worktree-path>"

Then check if the branch is fully merged:

bash
git branch -d "maestro/<plan-slug>"
  • If git branch -d succeeds: branch was fully merged, cleanup complete.
  • If git branch -d fails (not merged): warn the user. Do NOT force-delete with -D unless the user explicitly confirms.

4. If Keep

Leave the worktree in place. Log:

Worktree preserved at <worktree-path>. Remove later with: git worktree remove "<worktree-path>"

Step 9: Report

Tell the user what was accomplished:

  • Tasks completed
  • Files created/modified
  • Tests passing
  • Plan archived to .maestro/archive/{name}.md
  • Any issues or follow-ups

If executed in a worktree (handoff has "worktree": true), also include:

  • Branch name: maestro/<plan-slug>
  • Worktree path (if kept) or confirmation it was removed
  • Merge instructions: git merge maestro/<plan-slug>

The plan has been archived. /review can still access it.

Suggest post-execution review:

code
To verify results against the plan's acceptance criteria, run:
  /review

Task Delegation Prompt Format

Give teammates rich context — one-line prompts lead to bad results:

code
## TASK
[Specific, atomic goal]

## EXPECTED OUTCOME
- [ ] File created/modified: [path]
- [ ] Tests pass: `[command]`
- [ ] No new errors

## CONTEXT
[Background, constraints, related files]

## SKILL GUIDANCE
[Only include if matching skills found — see below]

## MUST DO
- [Explicit requirements]

## MUST NOT DO
- [Explicit exclusions]

Injecting Skill Guidance

For each task, match the task description against the skill registry using the algorithm in .claude/lib/skill-matcher.md:

  1. Normalize task description to lowercase words
  2. Match skills by triggers (highest relevance) or keywords from name/description
  3. Rank by priority (lower = higher priority)

If matching skills are found, add a ## SKILL GUIDANCE section after ## CONTEXT:

code
## SKILL GUIDANCE

### {skill-name}
{Full SKILL.md content after frontmatter}

### {another-skill}
{Content}

If no skills match the task, omit the ## SKILL GUIDANCE section entirely. Do not include an empty section — graceful degradation means the prompt works without it.

Anti-Patterns

Anti-PatternDo This Instead
Editing files yourselfDelegate to kraken/spark teammates
Skipping team creationAlways TeamCreate(team_name, description) first
Skipping verificationRead files + run tests after every task
One-line task promptsUse the delegation format above
Not extracting wisdomAlways write .maestro/wisdom/ file
Forgetting to cleanupAlways shutdown teammates + cleanup at end

Planless Work Flow

When /work is invoked with a description instead of a plan name (detected in Step 1), follow this flow instead of the plan-based workflow.

Step P1: Analyze Description

Parse the user's description to understand intent:

  1. Extract the core action (what to do)
  2. Identify target files, components, or modules (if mentioned)
  3. Determine scope and complexity

Store the description for use in subsequent steps.

Step P2: Generate Task Breakdown

Generate 1-5 atomic tasks from the description. For each task, determine:

  • Subject: Short, imperative title
  • Agent: kraken (TDD, new features, multi-file changes) or spark (quick fixes, single-file changes)
  • Acceptance criteria: Objectively verifiable outcomes
  • Files: Target file paths (use Glob/Grep to find if not specified in the description)

Use the same task format as plan-based tasks. Keep the breakdown minimal — prefer fewer, well-scoped tasks over many granular ones.

Step P3: Confirm with User

Present the generated task breakdown for user approval:

code
AskUserQuestion(
  questions: [{
    question: "Here's the task breakdown. How would you like to proceed?",
    header: "Planless Work",
    options: [
      { label: "Execute", description: "Proceed with these tasks" },
      { label: "Revise", description: "Let me re-describe what I want" },
      { label: "Cancel", description: "Stop without executing" }
    ],
    multiSelect: false
  }]
)

Show each task with its agent assignment and acceptance criteria before asking.

On Execute → Proceed to Step P4. On Revise → Ask the user for a new description, then repeat from Step P1. On Cancel → Stop execution.

Step P4: Join Main Workflow

After user confirms, rejoin the plan-based workflow:

  1. Create tasks (same as Step 3) — convert the generated breakdown into shared tasks with dependencies
  2. Discover skills (same as Step 3.5) — scan for skills that can provide guidance
  3. Proceed to Step 2 (Create Team) and continue through Steps 2 → 4 → 5 → 6 → 7 → 8 → 9

Skipped Steps in Planless Mode

The following plan-based steps are skipped when running in planless mode:

StepReason
Step 1.5 (Validate & Confirm)No plan file to validate
Step 1.7 (Worktree Isolation)Too heavyweight for ad-hoc work
Step 8.5 (Archive Plan)No plan file to archive

All other steps (team creation, task execution, verification, wisdom extraction, cleanup, reporting) proceed normally.

Wisdom File Naming in Planless Mode

When extracting wisdom (Step 7), derive the file slug from the first 5 words of the user's description:

  • /work add retry logic to api client.maestro/wisdom/add-retry-logic-to-api.md
  • /work fix login page redirect bug.maestro/wisdom/fix-login-page-redirect-bug.md

Strip articles ("a", "an", "the") and limit to 5 significant words. Use hyphens as separators.