From code-quality
Run competing implementations in parallel with isolated worktrees, then judge and select the best approach. Use when multiple viable approaches exist and "try both and compare" beats "guess and commit."
npx claudepluginhub wgordon17/personal-claude-marketplace --plugin code-qualityThis skill is limited to using the following tools:
You MUST follow the phased approach described here. Do not collapse phases or implement
Searches, retrieves, and installs Agent Skills from prompts.chat registry using MCP tools like search_skills and get_skill. Activates for finding skills, browsing catalogs, or extending Claude.
Searches prompts.chat for AI prompt templates by keyword or category, retrieves by ID with variable handling, and improves prompts via AI. Use for discovering or enhancing prompts.
Guides Next.js Cache Components and Partial Prerendering (PPR) with cacheComponents enabled. Implements 'use cache', cacheLife(), cacheTag(), revalidateTag(), static/dynamic optimization, and cache debugging.
You MUST follow the phased approach described here. Do not collapse phases or implement the task yourself. Your role is orchestration — you define the spec, spawn competitors, coordinate the judge, and present the result to the user.
Gather the problem and success criteria before spawning anything.
Use AskUserQuestion to clarify the task if the request is ambiguous. Resolve:
Research competing approaches — If the user's answer to step 1 named specific approaches
that involve third-party libraries, frameworks, SDKs, or external services not already present
in the codebase, invoke /deep-research (via the Skill tool) in External mode before proceeding. If the user
specified no approaches (approach hint is null), invoke /deep-research (via the Skill tool) in External mode to
identify viable alternatives and their trade-offs. (For tasks that are purely about internal
architecture or refactoring with no external dependencies, /deep-research may return quickly,
but it should still be invoked so the skill does not rely solely on training data.) Use research
findings to populate the SpeculativeSpec with informed approach descriptions rather than
relying on training data.
Define the evaluation criteria as a weighted list (weights must sum to 1.0):
Generate a run-ID using the convention in code-quality/references/project-memory-reference.md
(Run-ID Naming Convention section) and create the audit trail directory at
{memory_dir}/speculative/{run-id}/.
Create all tasks upfront with TaskCreate so the plan is visible from the start.
Spawn N competitor agents (sonnet, general-purpose) in parallel, each with
isolation: "worktree" and mode: "bypassPermissions" (they write code).
Each competitor receives a SpeculativeSpec (see references/communication-schema.md) containing:
competitor-1)ImplementationResultCompetitors work in full isolation — they do NOT communicate with each other or with the lead during implementation. The lead does not intervene unless a competitor explicitly signals it is blocked.
CronCreate watchdog: After spawning competitors, create a CronCreate job with a 60-second
interval. The watchdog checks TaskList for competitor tasks with no recent updates and sends
a status alert to the lead if any competitor has been idle for 2+ consecutive checks. The
watchdog monitors — it does NOT intervene directly. CronDelete the watchdog before
transitioning to Phase 2, including when all competitors fail or are timed out. Delete on all
paths — never leave orphaned cron jobs at phase boundaries.
Completion: Each competitor writes its ImplementationResult to
{run_dir}/implementations/competitor-{id}.json and signals completion via SendMessage.
The lead waits for all competitors before proceeding to Phase 2.
Time cap: If a competitor is significantly slower than others and all others have finished, the lead sends one status check. If the competitor does not complete within a reasonable additional time, the lead marks it as timed-out and proceeds with the results it has. A run with 1 of 2 competitors can still proceed — the judge evaluates what it received.
Failed competitor: If a competitor sends an ImplementationResult with status: "failed",
the lead records the failure, CronDeletes the watchdog, and proceeds with remaining results.
If ALL competitors fail, escalate to the user via AskUserQuestion before continuing.
Spawn a single judge agent (opus, general-purpose) — this is a high-judgment task.
The judge receives a JudgmentRequest containing:
ImplementationResult objects from Phase 1SpeculativeSpec (problem + success criteria + weights)Important — judge independence: The judge receives competitor self-assessments and approach descriptions, NOT raw code by default. This prevents bias from code style. If the judge needs to inspect code to make an informed decision, it reads specific files from each worktree path using the Read tool. The judge should only inspect code when self-reported results are insufficient to distinguish approaches.
The judge produces a JudgmentResult (see references/communication-schema.md) with:
hybrid_recommended flag with specific elements to combine (if applicable)The judge writes its result to {run_dir}/judgment.json and signals the lead.
Present the judgment to the user and execute the selection.
Present the JudgmentResult to the user via AskUserQuestion:
hybrid_recommended, explain what elements could be combined and from which competitorsBased on user response:
Merge procedure for winner:
git diff <main-branch> <worktree-branch> to show the changesCleanup: Delete all loser worktrees. The winning worktree is cleaned up after its changes
are confirmed merged. Write the final report to {run_dir}/speculative-report.md.
Only triggered if the judge recommends hybrid AND the user approves. This is NOT the default path.
The judge's hybrid_elements field lists specific elements to combine
(e.g., "competitor-1's error handling approach with competitor-2's data structure choice").
Spawn a synthesis agent (sonnet, general-purpose, mode: "bypassPermissions") with:
The synthesis agent combines the specified elements and produces a final implementation. It reports back with files changed and test results.
After synthesis, run the test suite to verify. Clean up all competitor worktrees.
Write the final report to {run_dir}/speculative-report.md.
User request
|
v
Phase 0: Specification
+-- AskUserQuestion (ambiguity, criteria, competitor count)
+-- /deep-research (if third-party involved, or approach hint is null)
+-- Generate run-ID, create {memory_dir}/speculative/{run-id}/
+-- TaskCreate for all phases
|
v
Phase 1: Fork (parallel, isolated)
+-- Spawn N competitors (sonnet, worktree isolation)
+-- CronCreate watchdog (60s interval)
+-- Wait for all ImplementationResults
+-- CronDelete watchdog
|
v
Phase 2: Evaluate
+-- Spawn judge (opus)
+-- Judge reads ImplementationResults (+ worktree code if needed)
+-- Judge writes JudgmentResult to {run_dir}/judgment.json
|
v
Phase 3: Select & Merge
+-- AskUserQuestion (present scoring matrix, get user approval)
+-- Merge winner into main branch
+-- Run tests
+-- Cleanup loser worktrees
+-- Write speculative-report.md
|
+--(if hybrid approved)---+
v
Phase 3.5: Hybrid
+-- Spawn synthesis agent
+-- Combine elements from multiple competitors
+-- Run tests
+-- Cleanup all worktrees
+-- Write speculative-report.md
You are the orchestrator. You define the spec, route competitor results to the judge, present the judgment to the user, and execute the merge. You never implement code yourself.
Create tasks upfront in Phase 0 with TaskCreate. Mark them in_progress as each phase begins
and completed when done. Blocked tasks (e.g., Phase 3.5 pending user decision) should remain
pending until triggered.
Track each competitor's status. When all competitors have reported, CronDelete the watchdog and proceed to Phase 2. If a competitor goes idle (no messages, no task updates), the watchdog alerts you — send one status check before assuming failure.
Phase 0 is the only mandatory user interaction before Phase 3. After gathering the spec and getting user confirmation on evaluation criteria and competitor count, competitors run without further user interaction until the judge has finished. The user resumes at Phase 3 to approve the selection.
Write all structured outputs to {run_dir}/:
implementations/competitor-{id}.json — each competitor's ImplementationResultjudgment.json — judge's JudgmentResultspeculative-report.md — final human-readable completion report| Phase | Skip When |
|---|---|
| Phase 3.5: Hybrid | Judge does not set hybrid_recommended: true, OR user declines hybrid |
| NEVER SKIP | Phase 0 (specification), Phase 1 (competitors), Phase 2 (judge), Phase 3 (selection) |
This skill runs competing implementations in parallel. Match tool to task:
| Scenario | Recommended Approach |
|---|---|
| One clearly correct approach | Implement directly (no speculative needed) |
| Multiple viable approaches, real trade-offs | /speculative |
| Architectural decision with broad impact | /speculative with 2-3 competitors |
| Algorithm selection (e.g., LRU vs TTL cache) | /speculative |
| "I want to see which is faster" | /speculative with performance as top criterion |
| Simple feature (1-3 files, obvious approach) | Single targeted subagent |
| Large feature needing full pipeline rigor | /swarm (optionally with Phase 2.7 speculative fork) |
| Role | Model | Rationale |
|---|---|---|
| Competitors | sonnet | Implementation work |
| Judge | opus | Judgment-heavy evaluation — fair comparison requires strong reasoning |
| Synthesis (Phase 3.5) | sonnet | Mechanical combination of known elements |
Never defer, skip, or reduce the scope of work to save tokens or reduce agent count. If the task requires an agent, spawn the agent. If a finding needs fixing, fix it. The only valid reasons to skip work are: (1) the user explicitly opted out, (2) the skip condition in the phase table applies, or (3) the work is genuinely out of scope for the current task.
"It would be expensive" is NEVER a valid reason to skip work.
| File | Content |
|---|---|
references/communication-schema.md | JSON schemas for SpeculativeSpec, ImplementationResult, JudgmentResult |
references/agent-prompts.md | Full prompt templates for competitor and judge agents |