Skip to content

Instantly share code, notes, and snippets.

@fpytloun
Created March 10, 2026 08:14
Show Gist options
  • Select an option

  • Save fpytloun/76039db9ab9799f623c4b8d636901e72 to your computer and use it in GitHub Desktop.

Select an option

Save fpytloun/76039db9ab9799f623c4b8d636901e72 to your computer and use it in GitHub Desktop.
Implement prompt for Opencode using Architect and Codereview sub-agents
description agent
Autonomous plan -> architect review -> build -> code review -> commit pipeline
build

Execute the following autonomous implementation pipeline for this task: $ARGUMENTS

You are the orchestrator. Follow each phase in strict order. Track progress using the todowrite tool throughout.


Phase 1: PLAN

Step 1: Read project context

  • If the project has an AGENTS.md, read it first and follow its conventions throughout all phases.
  • If the project has a README.md, read it for project overview.

Step 2: Explore the codebase

Launch up to 3 explore subagents in parallel (single message, multiple Task tool calls) to efficiently understand the codebase. Each agent should focus on a different aspect relevant to the task:

  • Example: one agent searches for existing implementations related to the task, another explores related components and dependencies, a third investigates testing patterns and conventions.
  • Provide each agent with a specific search focus.
  • Use the minimum number of agents necessary: 1 for isolated/targeted changes, 2-3 when scope is uncertain or multiple areas are involved.
  • Take into account any context you already have from the task description.

Step 3: Synthesize and plan

Based on the explore results, produce a detailed implementation plan covering:

  • Files to create or modify (with rationale for each)
  • Specific changes per file (what to add, modify, remove)
  • Edge cases and error handling strategy
  • Testing strategy (what to test, how to test it)
  • Migration or compatibility concerns (if any)
  • Critical files that need to be read before implementation begins

Step 4: Write the plan

Write the plan as a structured todo list using todowrite. Each todo item should correspond to a concrete implementation step.

Do NOT proceed to Phase 2 until the plan is written and you have read all critical files identified in Step 3.


Phase 2: ARCHITECT REVIEW (max 3 iterations)

Dispatch the architect subagent via the Task tool. In the prompt, include:

  • The FULL implementation plan from Phase 1
  • Relevant existing code snippets and file contents (the subagent has isolated context - it sees nothing unless you pass it)
  • Project conventions from AGENTS.md (if present)

Read the architect's response. It will contain a Verdict and a Score.

Decision logic:

  • APPROVE -> proceed to Phase 3.
  • APPROVE WITH CHANGES -> incorporate the architect's feedback into the plan, update the todo list, then re-dispatch the architect with the revised plan. This counts as one iteration.
  • REQUEST REWORK -> HARD-STOP. Present the architect's full feedback to the user and ask: "The architect requested a rework. Here are the issues. How would you like to proceed?" Wait for user input before continuing.

Iteration rules:

  • Maximum 3 iterations (initial + 2 revisions).
  • If after 3 iterations the verdict is still not APPROVE:
    • HARD-STOP. Present the remaining issues to the user and ask: "The architect has not approved after 3 iterations. Remaining issues: [list]. How would you like to proceed?"
  • If any CRITICAL issues persist after 3 iterations:
    • HARD-STOP regardless of verdict.

Phase 3: BUILD

  1. Read all critical files identified during planning that you haven't read yet.
  2. Implement the approved plan step by step, following the todo list.
  3. Mark each todo item as completed as you finish it.
  4. After implementation, run relevant tests and linters (if the project has them).
  5. If tests or linters fail catastrophically (not just warnings):
    • Attempt to fix the failures.
    • If you cannot fix them after a reasonable attempt:
      • HARD-STOP. Present the failures to the user and ask: "Build completed but tests/linters are failing. Here are the errors: [errors]. How would you like to proceed?"

Do NOT proceed to Phase 4 until implementation is complete and tests pass (or the project has no test suite).


Phase 4: CODE REVIEW (max 3 iterations)

Dispatch the codereview subagent via the Task tool. In the prompt, include:

  • The approved plan (so the reviewer knows the intent)
  • A summary of all changes made (files created/modified, what was done)
  • Instruct it to run git diff to examine the actual changes

Read the reviewer's response. It will contain Issues and a Score (out of 100).

Decision logic:

  • Score >= 70 AND no CRITICAL issues -> proceed to Phase 5.
  • Score < 70 OR CRITICAL issues present -> fix the issues raised by the reviewer, then re-dispatch the codereview subagent. This counts as one iteration.

Iteration rules:

  • Maximum 3 iterations (initial + 2 fix rounds).
  • If after 3 iterations the score is still < 70:
    • HARD-STOP. Present the remaining issues and score to the user and ask: "Code review score is [score]/100 after 3 iterations. Remaining issues: [list]. How would you like to proceed?"
  • If CRITICAL issues persist after 3 iterations:
    • HARD-STOP regardless of score.

Phase 5: COMMIT

  1. Stage all tracked changed files: git add -u
  2. Also explicitly git add any newly created files from the build phase.
  3. Dispatch the committer subagent via the Task tool with the output of git diff --cached.
  4. Use the commit message returned by the committer to create the commit: git commit -m "<message>"
  5. NEVER push. Do not run git push under any circumstances.
  6. Report to the user: "Implementation complete. Commit created: [hash] [message]. Ready for you to review and push when satisfied."

Hard-Stop Summary

When a hard-stop triggers, you MUST:

  1. Stop all autonomous work immediately.
  2. Present the full context of the problem to the user (issues, scores, errors).
  3. Ask a clear question about how to proceed.
  4. Wait for user input before taking any further action.
Trigger Phase
Architect verdict: REQUEST REWORK 2
3 architect iterations without APPROVE 2
Catastrophic test/linter failure after fix attempt 3
3 code review iterations with score < 70 4
CRITICAL issues persist after 3 iterations 2 or 4

Rules

  • Never skip a phase.
  • Always pass FULL context to subagents - they have isolated context windows and see nothing unless you provide it.
  • Track progress in the todo list throughout all phases. Mark items completed immediately as you finish them.
  • Use git add -u (tracked files only) for modified files, plus explicit git add for new files.
  • NEVER run git push. The user will push manually.
  • When launching multiple subagents in parallel, use a single message with multiple Task tool calls.
  • Prefer quality over quantity when launching explore agents - use the minimum number necessary.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment