Loom planning — get implementation plans from Claude, Gemini, and GPT, then synthesize the best plan
From loomnpx claudepluginhub tony/ai-workflow-plugins --plugin loom<task description> [--passes=N] [--timeout=N|none] [--mode=fast|balanced|deep]/planRestates requirements, assesses risks and dependencies, generates phased step-by-step implementation plan with complexity estimates, and waits for user confirmation before coding.
/planStarts Manus-style file-based planning: creates task_plan.md, findings.md, progress.md if missing, invokes planning skill, and guides through workflow.
/planLaunches interactive 7-step wizard to build Scope, Metrics, Direction, and Verification from a goal description.
/planRestates requirements, assesses risks and dependencies, creates phased step-by-step implementation plan with complexity estimates, and waits for user confirmation before coding.
/planBreaks project into small verifiable tasks with acceptance criteria, dependencies, checkpoints. Reads spec/codebase, presents plan for review, saves to tasks/plan.md and tasks/todo.md.
/planCaptures user intent via 5 structured questions, creates strategic execution plan, saves to .claude/session-plan.md and session-intent.md for review.
Get implementation plans from multiple AI models (Claude, Gemini, GPT) in parallel, then synthesize the best plan. This is a project-read-only command — no files in your repository are written, edited, or deleted. Session artifacts (model outputs, prompts, synthesis results) are persisted to $AI_AIP_ROOT for post-session inspection; this directory is outside your repository. The output is a finalized Claude Code plan ready for execution.
The task description comes from $ARGUMENTS. If no arguments are provided, ask the user what they want planned.
Call EnterPlanMode immediately. The final output of this command is a Claude plan file — the main agent stays in plan mode throughout and does NOT exit plan mode.
The main agent in plan mode can use readonly tools (Read, Grep, Glob) and launch sub-agents. All non-readonly operations (Bash, Write to non-plan files, Edit) are delegated to sub-agents spawned with mode: "default".
If plan mode is unavailable (e.g., headless claude -p invocation), proceed normally — the phase structure still produces a plan, and the final synthesis is presented as markdown text instead of written to a plan file.
Do NOT call ExitPlanMode — the user reviews the plan file and approves execution via the UI.
Goal: Understand the project state and the planning request.
Read CLAUDE.md / AGENTS.md if present — the main agent does this directly (Read is available in plan mode). Project conventions constrain valid plans.
Capture the task: Use $ARGUMENTS as the task description. If $ARGUMENTS is empty, ask the user what they want planned.
Launch a context-gather Task agent to collect git state via Bash commands.
Launch a Task agent (subagent_type: "general-purpose", mode: "default") with this prompt:
Gather git context for the current repository. Run the following commands and return the results verbatim:
Determine the trunk branch:
git remote show origin | grep 'HEAD branch'Fall back to
main, thenmaster, if detection fails.Diff stats against trunk:
git diff origin/<trunk>...HEAD --statCommit log since trunk:
git log origin/<trunk>..HEAD --onelineCurrent branch and short SHA:
git branch --show-currentgit rev-parse --short HEADReturn the trunk branch name, diff stats, commit log, current branch, and short SHA as structured text.
Explore relevant code: The main agent reads the files most relevant to the task to understand the existing architecture, patterns, and constraints. Use Grep/Glob/Read to build context.
After Phase 1 context gathering (reading CLAUDE.md, exploring files, capturing the task), assemble a structured context bundle that will be included verbatim in ALL model prompts. This ensures every model works from the same information.
Write to $SESSION_DIR/context-packet.md (the actual file write happens after Session Directory Initialization in Phase 2 creates $SESSION_DIR):
Conventions summary — key rules from CLAUDE.md/AGENTS.md (max 50 lines). Focus on commit format, test patterns, code style, and quality gates relevant to the task.
Repo state — branch, HEAD ref, trunk branch, uncommitted changes summary (from context-gather agent results).
Changed files — branch changes relative to trunk (from context-gather agent results).
Relevant file list — files matching task keywords discovered during Phase 1 exploration. Include paths only, not content.
Key snippets — critical function signatures, types, test patterns, or API contracts relevant to the task (max 200 lines). Prioritize interfaces over implementations.
Known unknowns — aspects of the task that need discovery during execution. List what the model should investigate.
Size limit: 400 lines total. Prioritize by task relevance. If the packet exceeds 400 lines, truncate the least relevant sections (snippets first, then file list).
Usage in model prompts:
$SESSION_DIR/context-packet.md) — the agent reads it directlyFor plan, include changed files (branch diff stats), key snippets of code relevant to the task, and known unknowns that the plan should address.
Scan $ARGUMENTS for explicit flags anywhere in the text. Flags use --name=value syntax and are stripped from the prompt text before sending to models.
| Flag | Values | Default | Description |
|---|---|---|---|
--passes=N | 1–5 | 1 | Number of synthesis passes |
--timeout=N|none | seconds or none | command-specific | Timeout for external model commands |
--mode=fast|balanced|deep | mode preset | balanced | Execution mode preset |
Mode presets set default passes and timeout when not explicitly overridden:
| Mode | Passes | Timeout multiplier |
|---|---|---|
fast | 1 | 0.5× default |
balanced | 1 | 1× default |
deep | 2 | 1.5× default |
Backward compatibility: Legacy trigger words are silently recognized as aliases:
multipass (case-insensitive) → --passes=2x<N> (N = 2–5, regex \bx([2-5])\b) → --passes=Ntimeout:<seconds> → --timeout=<seconds>timeout:none → --timeout=noneLegacy triggers are scanned on the first and last line only (to avoid false positives in pasted content). Explicit -- flags take priority over legacy triggers.
Values above 5 for --passes are capped at 5 with a note to the user.
Config flags (used in Step 2):
pass_count = parsed pass count from --passes, mode preset, or legacy trigger. Null if not provided.timeout_value = parsed timeout from --timeout, mode preset, or legacy trigger. Null if not provided.When flags are provided, skip the corresponding question. When --passes is provided, skip the passes question. When --timeout is provided, skip the timeout question.
If AskUserQuestion is unavailable (headless mode via claude -p), use pass_count value if set, otherwise default to 1 pass. Timeout uses timeout_value if set, otherwise the command's default timeout.
Use AskUserQuestion to prompt the user for any unresolved settings:
Question 1 — Passes (skipped when --passes was provided):
pass_count exists (from mode preset or legacy trigger), move the matching option first with "(Recommended)" suffix. Other options follow in ascending order.pass_count is null, use default ordering:
Question 2 — Timeout (skipped when --timeout was provided):
After interactive configuration, launch a single setup Task agent (subagent_type: "general-purpose", mode: "default") to perform model detection, timeout detection, and session directory initialization. The main agent passes the resolved pass_count and timeout_value from Steps 1–2, plus the context packet content assembled from Phase 1.
Prompt for the setup agent:
Perform setup for a loom plan session. You have three tasks: detect available models, detect the timeout command, and initialize the session directory.
Input from parent:
- pass_count: <resolved pass count>
- timeout_value: <resolved timeout value>
- context_packet_content: <full context packet text from Phase 1b>
- task_summary: <first 120 chars of user prompt>
- current_branch: <branch name from Phase 1>
- short_sha: <short SHA from Phase 1>
- trunk_branch: <trunk branch from Phase 1>
Task 1: Detect Available Models
Run these checks:
command -v gemini >/dev/null 2>&1 && echo "gemini:available" || echo "gemini:missing"command -v codex >/dev/null 2>&1 && echo "codex:available" || echo "codex:missing"command -v agent >/dev/null 2>&1 && echo "agent:available" || echo "agent:missing"Apply model resolution (priority order):
Slot Priority 1 (native) Native model Priority 2 (agent fallback) Agent model Claude Always available (this agent) — — — Gemini geminibinarygemini-3.1-pro-previewagent --model gemini-3.1-progemini-3.1-proGPT codexbinary(default) agent --model gpt-5.4-highgpt-5.4-highResolution logic for each external slot:
- Native CLI found → use it
- Else
agentfound → useagentwith--modelflag- Else → slot unavailable, note in report
Task 2: Detect Timeout Command
command -v timeout >/dev/null 2>&1 && echo "timeout:available" || { command -v gtimeout >/dev/null 2>&1 && echo "gtimeout:available" || echo "timeout:none"; }On Linux,
timeoutis available by default. On macOS,gtimeoutis available via GNU coreutils. If neither is found, external commands run without a timeout prefix.Task 3: Initialize Session Directory
Step 1 — Resolve storage root:
if [ -n "$AI_AIP_ROOT" ]; then AIP_ROOT="$AI_AIP_ROOT" elif [ -n "$XDG_STATE_HOME" ]; then AIP_ROOT="$XDG_STATE_HOME/ai-aip" elif [ "$(uname -s)" = "Darwin" ]; then AIP_ROOT="$HOME/Library/Application Support/ai-aip" else AIP_ROOT="$HOME/.local/state/ai-aip" fiCreate a
/tmp/ai-aipsymlink to the resolved root for backward compatibility:ln -sfn "$AIP_ROOT" /tmp/ai-aip 2>/dev/null || trueStep 2 — Compute repo identity:
REPO_TOPLEVEL="$(git rev-parse --show-toplevel)"REPO_SLUG="$(basename "$REPO_TOPLEVEL" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9._-]/-/g')"REPO_ORIGIN="$(git remote get-url origin 2>/dev/null || true)"if [ -n "$REPO_ORIGIN" ]; then REPO_KEY="${REPO_ORIGIN}|${REPO_SLUG}" else REPO_KEY="$REPO_TOPLEVEL" fiif command -v sha256sum >/dev/null 2>&1; then REPO_ID="$(printf '%s' "$REPO_KEY" | sha256sum | cut -c1-12)" else REPO_ID="$(printf '%s' "$REPO_KEY" | shasum -a 256 | cut -c1-12)" fiREPO_DIR="${REPO_SLUG}--${REPO_ID}"Step 3 — Generate session ID:
SESSION_ID="$(date -u '+%Y%m%d-%H%M%SZ')-$$-$(head -c2 /dev/urandom | od -An -tx1 | tr -d ' ')"Step 4 — Create session directory:
SESSION_DIR="$AIP_ROOT/repos/$REPO_DIR/sessions/plan/$SESSION_ID"mkdir -p -m 700 "$SESSION_DIR/pass-0001/outputs" "$SESSION_DIR/pass-0001/stderr"Step 5 — Write
repo.json(if missing). If$AIP_ROOT/repos/$REPO_DIR/repo.jsondoes not exist, write it:{ "schema_version": 1, "slug": "<REPO_SLUG>", "id": "<REPO_ID>", "toplevel": "<REPO_TOPLEVEL>", "origin": "<REPO_ORIGIN or null>" }Step 6 — Write
session.json(atomic replace). Write to$SESSION_DIR/session.json.tmp, thenmv session.json.tmp session.json:{ "schema_version": 1, "session_id": "<SESSION_ID>", "command": "plan", "status": "in_progress", "branch": "<current branch>", "ref": "<short SHA>", "models": ["claude", "..."], "completed_passes": 0, "prompt_summary": "<first 120 chars of user prompt>", "created_at": "<ISO 8601 UTC>", "updated_at": "<ISO 8601 UTC>" }Step 7 — Append
events.jsonl. Append one event line to$SESSION_DIR/events.jsonl:{"event":"session_start","timestamp":"<ISO 8601 UTC>","command":"plan","models":["claude","..."]}Step 8 — Write
metadata.mdcontaining: command name, start time, configured pass count, models detected, timeout setting, git branch, commit ref.Step 9 — Write the context packet to
$SESSION_DIR/context-packet.mdusing the content provided above.Return: SESSION_DIR path, AIP_ROOT, REPO_DIR, SESSION_ID, available models with their backends (native or agent fallback), timeout command (timeout/gtimeout/empty).
Store $SESSION_DIR and the model/timeout resolution for use in all subsequent phases.
Goal: Ask each model to produce an implementation plan for the task.
Prepend each model's role preamble to its prompt. Each model receives a distinct evaluation lens to decorrelate outputs and reduce shared blind spots. The same context packet is included for all models, but a different role preamble is prepended to each prompt.
| Slot | Role | Bias | Preamble |
|---|---|---|---|
| Claude | Maintainer | Conservative, convention-enforcing, minimal-change | "You are the Maintainer. Prioritize correctness, convention adherence, and minimal scope. Challenge any change that isn't strictly necessary. Enforce all project conventions from CLAUDE.md/AGENTS.md." |
| Gemini | Skeptic | Challenge assumptions, find edge cases, question necessity | "You are the Skeptic. Challenge every assumption. Find edge cases, failure modes, and unstated requirements. Question whether the proposed approach is even the right one. Prioritize what could go wrong." |
| GPT | Builder | Pragmatic, shippable, favor simplicity over abstraction | "You are the Builder. Prioritize practical, shippable solutions. Favor simplicity over abstraction. Focus on what gets the job done with the least complexity. Call out over-engineering." |
Role preambles are prepended before the task-specific prompt and context packet. The role does not change the task — it changes the lens through which the model approaches it.
Include the context packet from Phase 1b. Write the prompt content to $SESSION_DIR/pass-0001/prompt.md via a sub-agent (main agent is in plan mode).
Launch a Task agent (subagent_type: "general-purpose", mode: "default") to create Claude's plan:
Prompt for the Claude planning agent:
Create a detailed implementation plan for the following task. Read the codebase to understand the existing architecture, patterns, and conventions. Read CLAUDE.md/AGENTS.md for project standards. Read the context packet at
$SESSION_DIR/context-packet.mdfor shared context.Role: You are the Maintainer. Prioritize correctness, convention adherence, and minimal scope. Challenge any change that isn't strictly necessary. Enforce all project conventions from CLAUDE.md/AGENTS.md.
Task: <task description>
Your plan must include:
- Files to create or modify — list every file with what changes are needed
- Implementation sequence — ordered steps with dependencies between them
- Architecture decisions — justify key choices with reference to existing patterns
- Test strategy — what tests to add/extend, using the project's existing test patterns
- Risks and edge cases — potential problems and mitigations
- Commit boundaries — each step should be one atomic commit; include a commit message and note which quality gates to verify before committing (lint, format, type-check, fast tests)
Be specific — reference actual files, functions, and patterns from the codebase. Do NOT modify any files — plan only.
Write your plan to
$SESSION_DIR/pass-0001/outputs/claude.md.
Launch a Task agent (subagent_type: "general-purpose", mode: "default") to run the Gemini CLI and capture its plan.
Prompt for the Gemini agent:
Run the Gemini CLI to generate an implementation plan. You have the following inputs:
- SESSION_DIR: <SESSION_DIR path>
- Task description: <task description>
- Role preamble: "You are the Skeptic. Challenge every assumption. Find edge cases, failure modes, and unstated requirements. Question whether the proposed approach is even the right one. Prioritize what could go wrong."
- Context packet content: <inline context packet text>
- Backend: <"gemini" or "agent --model gemini-3.1-pro">
- Timeout command: <timeout_cmd or empty>
- Timeout seconds: <timeout_seconds or empty>
Construct the planning prompt by prepending the role preamble to the task description and context packet, then appending: "Additional instructions: Read AGENTS.md/CLAUDE.md for project conventions. Reference actual files, functions, and patterns from the codebase. Do NOT modify any files — plan only. Include: files to modify, implementation steps in order (each step = one atomic commit with quality gate verification before committing), architecture decisions, test strategy, and risks."
The agent must run the appropriate command based on the backend:
Native (
geminiCLI):<timeout_cmd> <timeout_seconds> gemini -m gemini-3.1-pro-preview -y -p "<prompt>" >"$SESSION_DIR/pass-0001/outputs/gemini.md" 2>"$SESSION_DIR/pass-0001/stderr/gemini.txt"Fallback (
agentCLI):<timeout_cmd> <timeout_seconds> agent -p -f --model gemini-3.1-pro "<prompt>" >"$SESSION_DIR/pass-0001/outputs/gemini.md" 2>>"$SESSION_DIR/pass-0001/stderr/gemini.txt"Retry and fallback protocol:
- Record exit code, stderr, elapsed time
- Classify failure: timeout → retryable with 1.5× timeout; API/rate-limit error → retryable after 10s delay; credit-exhausted → skip retry, escalate to agent immediately; crash → not retryable; empty output → retryable once. Detect credit-exhaustion via:
RESOURCE_EXHAUSTED,quota exceeded,insufficient_quota,capacity exhausted,usage limit, or HTTP 429 with "daily limit".- Max 1 retry with the same backend (skipped for credit-exhausted)
- If retry fails (or credit-exhausted) AND native CLI was used AND
agentis available, re-run using the agent fallback command (1 attempt, same timeout). Append stderr to the same file. If agent is also credit-exhausted or unavailable, use lesser model (gemini-3-flash-preview for Gemini; gpt-5.4-mini via agent for GPT).- After all retries exhausted: mark model as unavailable for this pass
Return: success/failure status, output file path, any error details.
Launch a Task agent (subagent_type: "general-purpose", mode: "default") to run the GPT CLI and capture its plan.
Prompt for the GPT agent:
Run the GPT CLI to generate an implementation plan. You have the following inputs:
- SESSION_DIR: <SESSION_DIR path>
- Task description: <task description>
- Role preamble: "You are the Builder. Prioritize practical, shippable solutions. Favor simplicity over abstraction. Focus on what gets the job done with the least complexity. Call out over-engineering."
- Context packet content: <inline context packet text>
- Backend: <"codex" or "agent --model gpt-5.4-high">
- Timeout command: <timeout_cmd or empty>
- Timeout seconds: <timeout_seconds or empty>
Construct the planning prompt by prepending the role preamble to the task description and context packet, then appending: "Additional instructions: Read AGENTS.md/CLAUDE.md for project conventions. Reference actual files, functions, and patterns from the codebase. Do NOT modify any files — plan only. Include: files to modify, implementation steps in order (each step = one atomic commit with quality gate verification before committing), architecture decisions, test strategy, and risks."
The agent must run the appropriate command based on the backend:
Native (
codexCLI):<timeout_cmd> <timeout_seconds> codex exec \ -c model_reasoning_effort=medium \ "<prompt>" >"$SESSION_DIR/pass-0001/outputs/gpt.md" 2>"$SESSION_DIR/pass-0001/stderr/gpt.txt"Fallback (
agentCLI):<timeout_cmd> <timeout_seconds> agent -p -f --model gpt-5.4-high "<prompt>" >"$SESSION_DIR/pass-0001/outputs/gpt.md" 2>>"$SESSION_DIR/pass-0001/stderr/gpt.txt"Retry and fallback protocol:
- Record exit code, stderr, elapsed time
- Classify failure: timeout → retryable with 1.5× timeout; API/rate-limit error → retryable after 10s delay; credit-exhausted → skip retry, escalate to agent immediately; crash → not retryable; empty output → retryable once. Detect credit-exhaustion via:
RESOURCE_EXHAUSTED,quota exceeded,insufficient_quota,capacity exhausted,usage limit, or HTTP 429 with "daily limit".- Max 1 retry with the same backend (skipped for credit-exhausted)
- If retry fails (or credit-exhausted) AND native CLI was used AND
agentis available, re-run using the agent fallback command (1 attempt, same timeout). Append stderr to the same file. If agent is also credit-exhausted or unavailable, use lesser model (gemini-3-flash-preview for Gemini; gpt-5.4-mini via agent for GPT).- After all retries exhausted: mark model as unavailable for this pass
Return: success/failure status, output file path, any error details.
Each sub-agent writes its output directly to the session directory:
$SESSION_DIR/pass-0001/outputs/claude.md$SESSION_DIR/pass-0001/outputs/gemini.md (via CLI stdout redirect)$SESSION_DIR/pass-0001/outputs/gpt.md (via CLI stdout redirect)$SESSION_DIR/pass-0001/outputs/ to proceed with synthesis.Goal: Combine the strongest elements from all plans into a single, superior plan using evidence-backed adjudication.
The main agent reads the model outputs from $SESSION_DIR/pass-0001/outputs/ (Read is available in plan mode) and performs synthesis.
Before synthesis, strip model identity from responses to prevent brand bias during evaluation.
Step 1: Randomize Labels
Assign random labels (Response A, Response B, Response C) to the model outputs. Use a random permutation — do not always assign Claude to A. Record the mapping in $SESSION_DIR/pass-NNNN/label-map.json (via sub-agent):
{
"A": "<model>",
"B": "<model>",
"C": "<model>"
}
Step 2: Evaluate Blindly
During scoring and adjudication (see Synthesis Protocol), refer to responses only by their labels (A/B/C). Do not consider which model produced which output.
Step 3: Reveal After Scoring
After all scoring and adjudication is complete, reveal the model identities in the attribution section of the final report. Include the label mapping so the user can trace which model produced which response.
Limitation: Claude is both participant and judge. True blindness is impossible for Claude's own output — it may recognize its own writing style. The blind labeling primarily prevents bias when evaluating external model outputs against each other.
After collecting model outputs and applying blind labels, follow this evidence-backed synthesis protocol. The convergence mode for plan is Merge.
Step 1: Verify Claims
For each blinded response (A/B/C), check factual claims against the codebase:
Glob and Read to confirm referenced files existverified (confirmed by reading code), plausible-unverified (reasonable but not checked), or false (contradicted by code)Write the verification results to $SESSION_DIR/pass-NNNN/verification.md (via sub-agent).
Step 2: Score with Rubric
Rate each blinded response 0–10 per dimension. Use the General Rubric below. Compute a weighted total for each response.
Write scores to $SESSION_DIR/pass-NNNN/scores.md (via sub-agent) in a table showing per-dimension scores and weighted totals for each label (A/B/C).
| Dimension | Weight | Description |
|---|---|---|
| Correctness | 3× | Verified claims, no hallucinations |
| Completeness | 2× | Covers all task aspects |
| Convention adherence | 2× | Follows CLAUDE.md/AGENTS.md patterns |
| Risk awareness | 1× | Edge cases, failure modes identified |
| Scope discipline | 1× | Minimal unnecessary changes — higher is better |
Step 3: Adjudicate Conflicts
Compare responses to identify:
Step 4: Converge
Build the final result using the Merge convergence mode: Combine agreed points as foundation, apply adjudicated conflict resolutions, incorporate best unique contributions ordered by score, strip unverified claims.
Step 5: Critic
Launch an independent Task agent (subagent_type: "general-purpose") to challenge the synthesized result:
Review the following synthesis for errors. Your job is to BREAK it — find problems, not confirm it's good.
Find: (1) remaining factual errors — file/function references that don't exist, (2) logical inconsistencies — steps that contradict each other, (3) missing edge cases — failure modes not addressed, (4) convention violations — rules from CLAUDE.md/AGENTS.md not followed.
Emit ONLY deltas: each issue found and its specific fix. Do not rewrite the entire synthesis.
Write the critic's findings to $SESSION_DIR/pass-NNNN/critic.md (via sub-agent). Incorporate valid findings into the final output — verify each critic finding against the codebase before accepting it.
After synthesis and critic review, produce the final plan in this format:
# Implementation Plan
**Task**: <task description>
## Architecture Decision
<Chosen approach and why, referencing existing codebase patterns>
## Implementation Steps
Each step is one atomic commit. Run the project's quality gates (lint,
format, type-check, and fast tests as defined in CLAUDE.md/AGENTS.md)
before committing. All gates must pass.
### Step 1: <description>
- **Files**: `path/to/file`
- **Changes**: <specific changes>
- **Depends on**: (none / Step N)
- **Commit**: `<scope(type): concise description>`
- **Verify**: <which quality gates to run, or "all">
### Step 2: <description>
- **Files**: `path/to/file`
- **Changes**: <specific changes>
- **Depends on**: Step 1
- **Commit**: `<scope(type): concise description>`
- **Verify**: <which quality gates to run, or "all">
... (continue for all steps)
## Test Strategy
- **Extend**: existing test files using the project's test patterns
- **New test**: for new functionality following project conventions
## Risks and Mitigations
1. **Risk**: <description>
- **Mitigation**: <approach>
---
## Scores
| Dimension | A | B | C |
|-----------|---|---|---|
| Correctness (3×) | /10 | /10 | /10 |
| Completeness (2×) | /10 | /10 | /10 |
| Convention adherence (2×) | /10 | /10 | /10 |
| Risk awareness (1×) | /10 | /10 | /10 |
| Scope discipline (1×) | /10 | /10 | /10 |
| **Weighted total** | | | |
## Verification Summary
**Verified claims**: <count> | **Plausible-unverified**: <count> | **False**: <count>
## Adjudication
**Agreed**: <key points all plans concurred on>
**Conflicts resolved**: <disagreements and which was correct, with code references>
**Rejected approaches**: <approach — rejected because reason with code reference>
## Critic Findings
<Deltas from critic pass, or "No issues found">
## Attribution
**Label mapping**: A = <model>, B = <model>, C = <model>
**Models participated**: Claude, Gemini, GPT (or subset)
**Models unavailable/failed**: (if any)
**Session artifacts**: $SESSION_DIR
Step 6: Write to plan file and persist artifacts
Write the synthesized plan content to the Claude plan file directly. This is the plan file write, which IS allowed in plan mode — the plan file is the deliverable.
Launch a sub-agent (subagent_type: "general-purpose", mode: "default") to persist session artifacts:
Persist the loom plan session artifacts:
- Write the synthesis to
$SESSION_DIR/pass-0001/synthesis.mdwith the following content: <full synthesis text>- Update
session.jsonvia atomic replace: setcompleted_passesto1,updated_atto now (ISO 8601 UTC). Write tosession.json.tmpthenmv session.json.tmp session.json.- Append a
pass_completeevent toevents.jsonl:{"event":"pass_complete","timestamp":"<ISO 8601 UTC>","pass":1}
If pass_count is 1, skip this phase.
For pass N ≥ 2, do NOT re-run the entire task. Instead, target only:
The main agent reads prior pass artifacts (Read is available in plan mode) to identify refinement targets.
Construct refinement prompts that include ONLY these targeted items:
The following issues remain from the prior pass. Address ONLY these items:
Unresolved conflicts: [list from prior adjudication] Critic findings: [list from prior critic.md] Low-confidence areas: [dimensions/responses that scored < 5]
For each item: provide your resolution with evidence (file paths, line numbers, code references).
For each pass from 2 to pass_count:
Create the pass directory via sub-agent (subagent_type: "general-purpose", mode: "default"):
Create the pass directory and write the refinement prompt:
mkdir -p -m 700 "$SESSION_DIR/pass-$(printf '%04d' $N)/outputs" "$SESSION_DIR/pass-$(printf '%04d' $N)/stderr"Write the conflict-only prompt to
$SESSION_DIR/pass-{N}/prompt.mdwith the following content: <refinement prompt text>
Re-run all available models in parallel using the same sub-agent dispatch pattern as Phase 3. Launch Claude, Gemini, and GPT agents with the refinement prompt (same backends, same timeouts, same retry logic). For Claude, reference prior artifacts by path; for external models, inline them.
Capture outputs — each sub-agent writes to $SESSION_DIR/pass-{N}/outputs/<model>.md.
Re-synthesize following Phase 4 (re-score only affected dimensions, re-adjudicate only targeted disputes).
Early-stop check (main agent): Read this pass's synthesis and compare with the prior pass. If no material delta (no scores changed by more than 1, no new conflicts identified), stop refinement early and report convergence.
Persist pass artifacts via sub-agent (subagent_type: "general-purpose", mode: "default"):
Persist pass {N} artifacts:
- Write synthesis to
$SESSION_DIR/pass-{N}/synthesis.md- Update
session.jsonvia atomic replace: setcompleted_passesto N,updated_atto now- Append
pass_completeevent toevents.jsonl
Update plan file: Write the latest synthesis to the Claude plan file, adding a Plan Evolution section describing what was strengthened, corrected, or added across passes.
$AI_AIP_ROOT, which is outside the repository.mode: "default".<timeout_cmd> <timeout_seconds> for external CLI commands, resolved from Phase 2. If no timeout command is available, omit the prefix entirely. Adjust higher or lower based on observed completion times.$SESSION_DIR/pass-{N}/stderr/<model>.txt) to report failures clearlysession.json via atomic replace (through sub-agent): set status to "completed", updated_at to now. Append a session_complete event to events.jsonl. Update latest symlink: ln -sfn "$SESSION_ID" "$AIP_ROOT/repos/$REPO_DIR/sessions/plan/latest"**Session artifacts**: $SESSION_DIR in the final output