ClosedLoop.ai
Mechanisms

Orchestrator and Subagents

The system prompt and agents that drive every loop iteration.

The orchestrator is the system prompt loaded at the start of each loop iteration. It is not a long-lived process; every iteration is a fresh claude -p invocation with a clean 200K-token context. All state between iterations lives on disk.

The orchestrator's job

The orchestrator coordinates. It does not read files directly. Its rules:

  • First action on every iteration is a TodoWrite that enumerates all 18 phases.
  • Its only allowed tools are Bash (for shell scripts and ls/mkdir/echo), Task (to launch subagents), TodoWrite, AskUserQuestion, and SendMessage (to continue a running subagent without re-launching it).
  • It may not use Read, Grep, Glob, Edit, or Write. All I/O goes through subagents.
  • It must write $CLOSEDLOOP_WORKDIR/state.json at every phase transition so external UIs can observe progress.
  • It must emit <promise>COMPLETE</promise> only after plan.json has zero pendingTasks and final validation has passed.

Subagents

Subagents are specialized Claude instances launched via Task. Each has a tightly scoped system prompt, a declared tool allowlist, a promise they must emit, and (for loop agents) a validation script.

Planning subagents

AgentModelRole
plan-draft-writerOpusDraft a new plan.json and plan.md from the PRD and pre-exploration. Loop agent; max 10 iterations; emits PLAN_VALIDATED.
plan-writerSonnetMerge critic feedback and finalize task descriptions. Modes: MERGE, FINALIZE, GAP. Loop agent; max 5 iterations; emits PLAN_WRITER_COMPLETE.
plan-validatorSonnetSemantic-only validation of the current plan. Loop agent; emits PLAN_VALIDATION_COMPLETE.
plan-evaluatorSonnetSimple-mode 6-signal gate that short-circuits expensive validation for trivial plans.
plan-importerSonnetConvert a staged imported-plan.md into a canonical plan.json.
answered-questions-subagentHaikuIncorporate answeredQuestions from the plan.
plan-agentOpusUsed by plan-with-codex for the Claude side of a Codex debate.

Implementation subagents

AgentModelRole
pre-explorerHaikuProduce requirements-extract.json, code-map.json, and investigation-log.md.
verification-subagentSonnetFor each task, return VERIFIED if already implemented or NOT_IMPLEMENTED otherwise.
implementation-subagentSonnetApply the task with a 4-gate self-verification loop (max 4 iterations). Appends visual QA steps to visual-requirements.md on UI changes.
build-validatorHaikuAuto-discover test/lint/typecheck/build commands across Node, Python, Rust, Go, Android, and Make; loop until VALIDATION_PASSED.
code-reviewerSonnetPost-implementation review. Loop agent; max 5 iterations; exits when no Critical or High findings remain.

Cross-repo subagents

AgentModelRole
cross-repo-coordinatorHaikuDecide which peer repositories are needed and emit a CAPABILITIES_LIST.
generic-discoveryHaikuDiscover per-peer capabilities; cache to .discovery-cache/.
repo-coordinatorHaikuReconcile task ownership across repos.
cross-repo-prd-writerSonnetProduce cross-repo-prd-{peer-name}.md; tag plan tasks with [CROSS-REPO: {peer}].
api-spec-writerSonnetProduce api-requirements.md for inter-repo contracts.

Support subagents

AgentRole
visual-qa-subagentPlaywright-driven visual QA. Returns SUCCESS, FAILURE, AUTH_REQUIRED, BLOCKED, or INCOMPLETE_DOCS.
dev-environmentProduce .dev-environment.json describing how to boot the app locally.
learning-captureExtract learnings from the iteration.
amend-extractorClassify a freeform amendment request into a directive, question, or confirmation.
code-review-workerWorker spawned by /code-review:start for each file partition.
code-review-guidelinesStyle and severity rules for reviewer workers.

Loop agents and their promises

A loop agent is a subagent that runs a validation loop until it emits a completion promise or hits its max-iteration cap. Registered in scripts/loop-agents.json:

AgentPromiseMax iterationsValidator
plan-draft-writerPLAN_VALIDATED10validate-plan.sh
plan-writerPLAN_WRITER_COMPLETE5validate-plan.sh
code-reviewerCODE_REVIEW_PASSED5
plan-validatorPLAN_VALIDATION_COMPLETE5
implementation-subagentIMPLEMENTATION_VERIFIED4

The loop-stop-hook.sh reads the subagent's state, checks for the promise, runs the validator, and either allows exit on PASS or increments the iteration and blocks with feedback.

Subagent continuation with SendMessage

For long-running subagents that need to continue with additional context (for example, visual QA after INCOMPLETE_DOCS), the orchestrator stores the agent's agent_id from its initial Task spawn and continues via SendMessage(to=<agent_id>). This preserves full agent context instead of re-launching a new Task. SendMessage returns immediately with a queued acknowledgment; the orchestrator waits for a <task-notification> before proceeding.

On this page