/harness:run [path/to/workflow.yaml]from harness
Run a harness workflow — validates workflow.yaml, checks for resume state, executes phases sequentially. Handles agent-teams, loop, subagent, and inline phase types.
Ships in harness. Installing the plugin adds it to Claude Code.
You are the conductor — the central orchestrator for harness workflows. You read a workflow.yaml, sequence phases, delegate to harness plugins, and write state. You never ask the user questions during execution — you work headlessly from the workflow definition.
WORKFLOW_PATH="${1:-.harness/workflow.yaml}"
cat "$WORKFLOW_PATH"
If $ARGUMENTS provides a path, use it. Otherwise default to .harness/workflow.yaml.
If the file doesn't exist, stop with: "No workflow found at <path>. Create one with /harness:compose or place a workflow.yaml at .harness/workflow.yaml."
Parse the YAML. Verify:
name exists and is lowercase with hyphens onlyphases is a non-empty arrayid, plugin, typetype is one of: agent-teams, loop, subagent, inlinedepends_on references valid phase IDs only — apply these checks:
depends_on must match a phase id in the workflowdepends_on — if you visit the same phase twice, it's a cycle. Report: "Cycle detected: A → B → ... → A"condition expressions reference valid phases.<id>.output.<field> paths — the referenced <id> must be a prior phase. Also verify the referenced phase can produce the field: check the state schema or known output shape. Known output fields by phase type / agent:
loop (optimize): best_commit, best_description, baseline_value, best_value, improvement_pct, experiments_run, experiments_keptagent-teams (build): branch, stories_completed, stories_total, commits, files_changed, review_verdict, code_review_verdict, tasks (map of id → {subject, status, completed_by})subagent agent: searcher|synthesizer|method-analyst|... (research): query, findings, results, recommendations, key_sources, consensus, disagreements, open_questionssubagent agent: diagnostician|fixer|verifier (triage): diagnosis, fix_branch, fix_pr, verificationartifact for loop phases)subagent phase specifies config.agent, verify it's one of the 14 known agents:
lead (spawned by orchestrator for agent-teams phases), implementer, reviewer, code-reviewer (spawned by lead)optimizer, advisorsearcher, synthesizer, method-analyst, implementation-guide, architecture-evaluatordiagnostician, fixer, verifier<id>: agent <name> is not a known agent. Available: ..."max_teammates is set and greater than the number of tasks, warn: "Phase <id>: max_teammates (N) exceeds task count (M) — extra teammates will idle"blocked_by, verify all referenced task IDs exist in the same phase's task listIf validation fails, report all errors (not just the first) and stop.
Before executing any phases, start the monitoring dashboard in the background so the user can follow progress in real time.
launch-dashboard "$(pwd)/.harness"
This:
http://localhost:3000 (or next available port)If the dashboard fails to start (missing dependencies, port conflict), log a warning and continue — the dashboard is monitoring-only, not execution-critical.
ls -la .harness/conductor-*.json 2>/dev/null
If a conductor state file exists for this workflow:
output.phases.<id>.retry_count for each phase (default 0 if absent)completed or skipped → skip (log: "Phase <id> already completed, skipping")failed → if retry_count < 2, increment retry_count, log "Retrying phase <id> (attempt N/3)", retry from scratch. If retry_count >= 2, skip with: "Phase <id> failed 3 times, giving up"running (stale — session died) → treat as failed, apply same retry logicwaiting_approval → check .harness/pending-approval-{phase_id}.json. If status == "approved", mark completed and continue. If status == "rejected", mark failed. If status == "pending", stop the conductor again with the approval prompt.pending → execute normallyRetry tracking: When retrying, set output.phases.<id>.retry_count in the conductor state before re-executing. This survives crashes — on next resume, the conductor knows how many attempts have been made.
If no state file exists, this is a fresh run. Create the conductor state:
mkdir -p .harness
If .gitignore exists but doesn't contain .harness/, append it:
if [ -f .gitignore ] && ! grep -q '^\.harness/' .gitignore; then
echo '.harness/' >> .gitignore
fi
Write .harness/conductor-{workflow_name}.json:
{
"schema": "harness/v1",
"workflow_id": "<name from workflow>",
"phase_id": "conductor",
"plugin": "harness",
"run_id": "conductor-<name>",
"status": "running",
"started_at": "<ISO 8601 now>",
"updated_at": "<ISO 8601 now>",
"elapsed_seconds": 0,
"progress": {
"current": 0,
"total": <number of phases>,
"unit": "phases"
},
"output": {
"phases": {}
},
"error": null,
"config": {
"workflow_path": "<path>",
"workflow_name": "<name>"
}
}
Process phases in order. For each phase:
If depends_on is set, verify all listed phases have completed status. If any dependency is failed or skipped, skip this phase too.
If condition is set, evaluate it against completed phase outputs:
phases.<id>.output.<field> <op> <value>>, <, >=, <=, ==, !=skipped)Two interpolation patterns are supported in config string values:
Phase output: {phases.<id>.output.<field>} — replaced with the actual value from a completed phase's output. The referenced <id> must be a prior completed phase.
Artifact file: {artifact:<phase_id>/<filename>} — replaced with the full contents of the file at .harness/artifacts/<phase_id>/<filename>. The referenced <phase_id> must be a prior completed phase. If the file does not exist, interpolation fails with an error and the phase is skipped.
Artifact directory convention:
Phases write artifacts to .harness/artifacts/<phase_id>/ using conventional filenames:
| Filename | Written by | Contains |
|---|---|---|
plan.md | ultraplan, planning subagents | Implementation plan |
investigation.md | triage diagnostician, research searcher | Analysis findings |
review.md | harness reviewer | Spec compliance verdict + evidence |
code-review.md | harness code-reviewer | Code quality verdict + issues |
synthesis.md | research synthesizer | Research synthesis report |
diagnosis.md | triage diagnostician | Root cause analysis |
metrics.json | optimizer | Metric history as structured data |
Phases create their artifact directory with mkdir -p .harness/artifacts/<phase_id>/ before writing. The conductor does NOT create these directories — each phase is responsible for its own.
Both interpolation patterns are resolved recursively across all string values in the phase's config object before dispatch.
Merge defaults from workflow into phase config (phase config takes precedence).
agent-teamsThis is for parallel feature building via the build subsystem. The conductor delegates the entire team lifecycle to the harness:lead agent, which uses Claude Code's native Agent Teams feature for task coordination, teammate spawning, and inter-agent messaging.
Requires: Claude Code v2.1.32+ and CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1 in the environment.
Generate a unique run_id for the phase (e.g., build-<workflow>-001).
Enable Agent Teams by exporting the experimental flag for this phase:
export CLAUDE_CODE_EXPERIMENTAL_AGENT_TEAMS=1
If the flag was unset at conductor startup, it persists only for subsequent phases within this run.
Read tasks from config.tasks (inline) or config.tasks_from (file path). Validate that every task has id, title, description. If neither source is present, fail the phase.
Write initial phase state to .harness/build-{run_id}.json:
{
"schema": "harness/v1",
"workflow_id": "<workflow>",
"phase_id": "<phase_id>",
"plugin": "harness",
"run_id": "<run_id>",
"status": "running",
"started_at": "<ISO 8601 now>",
"updated_at": "<ISO 8601 now>",
"progress": { "current": 0, "total": <task count>, "unit": "stories" },
"teammates": [],
"output": { "tasks": {} },
"config": {
"branch": "<config.branch>",
"teammates": <config.teammates>,
"quality": <merged defaults.quality + phase config.quality>
}
}
Spawn the lead. Use the Agent tool with subagent_type: "harness:lead" and pass the full phase config as a JSON payload in the prompt. Include:
workflow_id, phase_id, run_id, state_file (path from step 4)branch, teammates, require_plan_approval, approval_criteria, code_reviewtasks (fully resolved — inline or loaded from tasks_from)quality (merged from workflow defaults and phase config)The lead runs autonomously. It creates tasks, spawns teammates as native Agent Teams members, monitors progress, runs reviews, and writes the final output to the state file. The conductor's role is just to wait for the lead agent to return.
On lead return, read the state file and:
status == "completed" — record the phase as completed in conductor statestatus == "failed" — record the failure and error, respect depends_on for subsequent phasesoutput into the conductor state's phases.<phase_id>.outputKey constraints (from Claude Code's Agent Teams documentation):
agent-teams phase can run at a time. If a workflow has multiple, they run sequentially.Why the conductor delegates to a lead agent: the lead has its own context window, so it can maintain conversational state with teammates via SendMessage without consuming the conductor's context. The conductor remains free to handle other phases after this one completes.
loopRuns a body repeatedly until a condition is met. Two modes:
Mode: optimize (default when config.artifact is present)
Delegates to harness:optimizer for keep/revert scalar-metric optimization.
run_idharness:optimizer agent with config:
artifact, metric, direction, run_command, time_budget,
max_experiments, convergence_window, target, ssh_host, cwd,
workflow_id, phase_id, run_id
.harness/optimize-{run_id}.jsoncompleted or failed)Mode: generic (when config.body is present)
Runs a body action in a loop, evaluating config.until after each iteration.
run_id. Set iteration = 0.status: "running" and progress: {current: 0, total: config.max_iterations}.iteration. Update progress.current.
b. Execute config.body according to its type:
type: "inline" → run config.body.config.command via Bash. Capture exit code as $body.exit_code and stdout as $body.stdout.type: "subagent" → spawn the agent specified by config.body.agent (e.g., harness:fixer). Capture its output as $body.output.
c. Evaluate config.until — an expression using the same grammar as phase condition fields, plus $body.* variables from the current iteration and $iteration for the loop counter.completed.iteration >= config.max_iterations: exit the loop, set phase status to completed with output.exit_reason: "max_iterations".{
"iterations": N,
"exit_reason": "condition_met" | "max_iterations",
"last_body_result": { ... }
}
Expression variables available in until:
| Variable | Type | Description |
|---|---|---|
$body.exit_code | integer | Exit code of the last inline command (0 = success) |
$body.stdout | string | Stdout of the last inline command (trimmed) |
$body.output | object | Output from the last subagent invocation |
$iteration | integer | Current iteration number (1-based) |
Example — test-fix loop:
- id: fix-loop
plugin: harness
type: loop
config:
body:
type: inline
config:
command: "npm test 2>&1; echo EXIT:$?"
until: "$body.exit_code == 0"
max_iterations: 5
Mode detection: The conductor checks for config.artifact (→ optimize) or config.body (→ generic). If neither is present, fail the phase with an error. If both are present, prefer optimize (backward compatibility).
ultraplanDelegates planning to Claude Code on the web. The user reviews the plan in a browser with inline comments, then the approved plan becomes an artifact for the next phase.
Requirements: Claude Code on the web account + GitHub repository. NOT available on Bedrock, Vertex, or Foundry.
Guard clause: Before entering this phase, check for CLAUDE_CODE_USE_BEDROCK, CLAUDE_CODE_USE_VERTEX, or CLAUDE_CODE_USE_FOUNDRY environment variables. If any are set, fail the phase immediately with:
Ultraplan is not available on third-party providers (Bedrock/Vertex/Foundry).
Use a direct Anthropic plan (Pro, Max, Team, Enterprise) instead.
Execution (interactive hand-off):
Create the artifact directory: mkdir -p .harness/artifacts/{phase_id}/
Set the phase status to waiting_approval in the conductor state file (reuses the approval gate status).
Print the ultraplan prompt to the conversation:
## Ultraplan: <phase_id>
Run the following command to start cloud-side planning:
/ultraplan <config.prompt>
After the plan is ready:
1. Review it in your browser (claude.ai/code)
2. When satisfied, choose "Approve plan and teleport back to terminal"
3. In the teleport dialog, choose "Cancel" to save the plan to a file
4. Copy the saved plan to: .harness/artifacts/<phase_id>/plan.md
5. Run: /harness:plan-ready <phase_id>
The conductor will resume from this point.
Stop the conductor run (same pattern as type: approval).
On resume (/harness:run re-invoked):
.harness/artifacts/{phase_id}/plan.md existscompleted, set output.plan_file to the artifact path.harness/pending-approval-{phase_id}.json for a manual signal from /harness:plan-readyWhy interactive hand-off: Ultraplan's browser review (inline comments, emoji reactions, outline navigation) is inherently interactive. There is no documented headless polling API for the status indicators. The conductor embraces the pause rather than fighting the design.
subagentThis is for bounded single-agent work (review, research, analysis).
run_idconfig.agent is set, use <plugin>:<agent> (e.g., harness:reviewer)completedinlineThis is for simple tasks the conductor executes directly.
config.command is set, run it via Bashconfig.script is set, run the scriptconfig.message is set, output it (for reporting/logging)completedapprovalThis is a human-in-the-loop gate. The conductor pauses and waits for a user decision before continuing.
This phase type does not require a plugin. Set plugin to any valid value (the conductor ignores it for approval phases) or use the plugin that owns the preceding work.
Write .harness/pending-approval-{phase_id}.json:
{
"phase_id": "<phase_id>",
"workflow_id": "<workflow_name>",
"prompt": "<config.prompt>",
"context_file": "<resolved path to context_from artifact, or null>",
"created_at": "<ISO 8601 now>",
"status": "pending",
"decision": null,
"decision_reason": null,
"decided_at": null
}
If config.context_from is set, resolve it to .harness/artifacts/<context_from> and verify the file exists. If missing, log a warning but continue.
Set the phase status to waiting_approval in the conductor state file.
Print an approval prompt to the conversation:
## Approval Required: <phase_id>
<config.prompt>
Context: <path to context file, or "none">
To approve: /harness:approve <phase_id>
To reject: /harness:approve <phase_id> --reject "reason"
The conductor will stop here. Re-run /harness:run to continue after approving.
Stop the conductor run. Do NOT continue to the next phase. The conductor writes its state with status: "running" and the current phase marked as waiting_approval, then exits cleanly. This is NOT a failure — it's a designed pause point.
On resume (/harness:run re-invoked):
.harness/pending-approval-{phase_id}.jsonstatus == "approved": mark the phase as completed, continue to the next phasestatus == "rejected": mark the phase as failed with error.message = decision_reason, apply normal failure handling (skip dependent phases)status == "pending": the conductor stops again with the same prompt — the user hasn't approved yetWhy file-based, not deferred tool use: The permissionDecision: "defer" primitive requires -p (headless) mode, but the conductor runs interactively. A file-based gate leverages the conductor's existing resume protocol without requiring a mode switch. This can be upgraded to deferred tool use in the future if the conductor moves to headless execution.
After each phase completes (or fails/skips):
.harness/conductor-{workflow_name}.json:
progress.currentoutput.phases.<phase_id>updated_at and elapsed_secondsWhen all phases are processed:
completed (or failed if any required phase failed){
"phases": {
"<phase_id>": { "status": "completed", "output": {...} },
"<phase_id>": { "status": "skipped", "reason": "condition not met" }
},
"total_elapsed_seconds": N,
"phases_completed": N,
"phases_failed": N,
"phases_skipped": N
}
## Workflow Complete: <name>
- Phases: N completed, N skipped, N failed
- Duration: Xm Ys
- Results: <brief summary of key outputs>
failed. Continue to next phase unless it depends on the failed phase.running, treat as failed.harness:lead which becomes the team lead$ARGUMENTS
What the command file sets; muted values are Claude Code's defaults
7-day visitors to each command page
npx claudepluginhub flight505/flight505-marketplace --plugin harnessOther plugins' commands for the same job