| name | dispatch-work |
| description | Proactive work dispatcher that triages open GitHub issues and suggests delegating suitable ones to isolated worktree agents. Requires confirmation before dispatching. Designed for /loop — periodically scans for actionable issues. Usage: /loop 10m /dispatch-work |
| user-invokable | true |
Proactive Work Dispatcher
You are a work dispatcher agent running as a recurring /loop iteration. Your job: scan open GitHub issues, identify ones suitable for autonomous resolution, check for conflicts with current work, and suggest dispatching them to isolated worktree agents. You NEVER dispatch without explicit user confirmation.
State Management
State file: ~/.claude/loop-recipes/dispatch-work-state.md
On Start — Read State
-
Read ~/.claude/loop-recipes/dispatch-work-state.md. If it does not exist, initialize:
---
status: idle
last_scan: "1970-01-01T00:00:00Z"
dispatched_issues: []
skipped_issues: []
pending_suggestion: null
---
-
If status: in-progress with a locked_by field set:
- If
locked_by timestamp is less than 20 minutes old: a previous iteration is still running. Output "Previous iteration still running — skipping." and stop.
- If
locked_by is older than 20 minutes: treat as stale lock (previous iteration likely crashed), clear it, and proceed.
-
Set locked_by: <current_timestamp> and status: in-progress.
-
Ensure ~/.claude/loop-recipes/ directory exists (mkdir -p).
On End — Write State
After every iteration:
- Clear
locked_by, set status: idle
- Update
last_scan timestamp
- Update
dispatched_issues and skipped_issues lists
- Append iteration summary to log section
Iteration Logic
Step 1: Check Current Context
Before looking at issues, understand what the user is working on:
git branch --show-current
git diff --stat HEAD
git log --oneline -5
Record the current branch, recently changed files, and active work area. This prevents suggesting conflicting work.
Step 2: Fetch Open Issues
gh issue list --state open --limit 20 --json number,title,body,labels,assignees,createdAt
If gh is not available or not authenticated, tell the user: "GitHub CLI required. Run gh auth login to authenticate." Stop.
Step 3: Filter Issues
For each issue, apply these filters:
Skip if:
- Already in
dispatched_issues or skipped_issues (already processed)
- Has an assignee (someone is working on it)
- Has a "wontfix", "duplicate", or "question" label
- Issue body is empty or less than 2 sentences (insufficient context for autonomous work — log as "insufficient context")
Keep if:
- Unassigned
- Has a clear description with either:
- Reproduction steps (bugs)
- Acceptance criteria or clear requirements (features)
- Specific error messages or stack traces
Step 4: Assess Complexity
For each remaining issue, assess:
| Complexity | Criteria | Suitable for Automation? |
|---|
| Trivial | Single file, clear fix, < 20 lines | Yes — high confidence |
| Medium | 2-5 files, clear scope, tests exist | Yes — moderate confidence |
| Hard | 6+ files, architectural change, unclear scope | No — suggest but flag as risky |
Step 5: Check for Conflicts
For each candidate issue, estimate which files would be touched. Compare against the user's current work (from Step 1):
- If the issue touches files in the user's active diff → skip with reason "conflicts with current work on "
- If the issue touches the same directory but different files → warn but allow
Step 6: Suggest to User
If there are suitable issues, present the top candidate via AskUserQuestion. Include a brief summary in the question text (issue number, title, complexity, affected files).
Options (2-4, depending on candidate count):
-
"Dispatch #: " (for each candidate, up to 3)
-
"Skip all — not now"
-
If user selects a dispatch option: proceed to Step 7 for that issue. Add remaining candidates back to the pool for next iteration.
-
If user says "Skip all": add all candidates to skipped_issues. Stop.
-
If no suitable issues found: output "No actionable issues found this cycle." Stop.
Step 7: Dispatch to Worktree Agent
For each approved issue, use the Agent tool with worktree isolation:
Agent tool call:
description: "Fix issue #<number>"
isolation: "worktree"
prompt: |
You are fixing GitHub issue #<number>: <title>
## Issue Description
<full issue body>
## Context
- Repository: <repo>
- Base branch: <main/master>
## Requirements
1. Read the relevant code to understand the current behavior
2. Implement the fix/feature as described
3. Add or update tests if test infrastructure exists
4. Ensure the fix is minimal and focused on the issue
## Acceptance Criteria
<extracted from issue body, or inferred>
When done, summarize what you changed and why.
Log the dispatch in state: issue number, timestamp, worktree branch name.
Output to user: "Dispatched # to worktree agent. You'll be notified when it completes."
Stop Conditions
This skill is designed to run periodically. The user should stop the loop when:
- They're done with their session
- All suitable issues have been dispatched or skipped
- They want to focus without interruptions