Building an Automated Multi-Agent Coding Workflow with Codex, Claude Code, Cursor, and Grok
Version: 16 October 2026
Table of Contents
Section titled “Table of Contents”- Goal
- 1. Agent Role Allocation
- 2. Overall Architecture
- 3. Recommended Project Structure
- 4.
task.md - 5.
AGENTS.md - 6. Orchestrator
- 7. First Version of
orchestrator.py - 8. Feedback Loop
- 9. Claude Fix Prompt
- 10. Initial Safety Rules
- 11. Git Branch
- 12. Phase Two: Git Worktree
- 13. Do Not Let Agents Edit the Same Folder in Parallel at the Start
- 14. Phase Three: GitHub Issue → AI
- 15. Phase Four: CI Feedback
- 16. Target Architecture
- 17. Recommended Development Sequence
- 18. Most Important Principles
- 19. Suggested First Experiment
- 20. Final Goal
Multi-Agent Automated Coding Workflow
Section titled “Multi-Agent Automated Coding Workflow”Build a development workflow in which multiple AI coding agents automatically divide the work and collaborate, reducing the need for manual copy and paste.
The basic idea is:
Requirement ↓Orchestrator ↓Codex → Claude Code → Cursor Agent → Grok ↓Tests / Review ↓PASS → Git Diff / Pull RequestFAIL → Automatically return to Claude Code for fixesYou only need to write the requirement once. The orchestrator then automatically hands the work to the appropriate agents.
1. Agent Role Allocation
Section titled “1. Agent Role Allocation”For the first version, avoid letting all four agents modify the same files at the same time. Use a sequential pipeline instead.
Codex — Architect / Planner
Section titled “Codex — Architect / Planner”Main responsibilities:
- Read the requirement
- Analyse the repository
- Understand the existing architecture
- Identify affected files
- Break the work into implementation steps
- Define the required tests
- Identify edge cases and risks
- Produce
plan.md
At this stage, Codex mainly focuses on reasoning and planning rather than modifying code.
Claude Code — Main Developer
Section titled “Claude Code — Main Developer”Main responsibilities:
- Read
task.md - Read
plan.md - Read
AGENTS.md - Implement feature / bug fix
- Modify the source code
- Add automated tests
- Run build / tests
- Fix implementation errors
Claude Code acts as the primary implementation agent in the first version of the workflow.
Cursor Agent — Integration / Tester
Section titled “Cursor Agent — Integration / Tester”Main responsibilities:
- Read the requirement
- Review Claude Code’s Git diff
- Run build
- Run unit tests
- Run integration tests
- Run lint
- Run type checking
- Identify integration issues
- Fix implementation issues when necessary
Cursor Agent is mainly responsible for confirming that:
After Claude finishes the implementation, the project still works correctly as a whole.
Grok — Independent Reviewer
Section titled “Grok — Independent Reviewer”Ideally, Grok should not participate in the original implementation.
Main responsibilities:
- Review current Git diff
- Look for logic bugs
- Look for security issues
- Look for regressions
- Look for race conditions
- Look for missing edge cases
- Look for missing tests
- Look for architecture problems
- Look for unnecessary complexity
At the end, it only needs to return a clear verdict:
VERDICT: PASSor:
VERDICT: FAILIf the result is FAIL, list the blocking issues clearly.
The advantage of using Grok as an independent reviewer is that:
The model that wrote the code is not reviewing its own work.
2. Overall Architecture
Section titled “2. Overall Architecture” YOU │ │ .ai/task.md │ ▼ ┌──────────────┐ │ Orchestrator │ │ Python │ └──────┬───────┘ │ ▼ ┌──────────────┐ │ Codex │ │ Architect │ └──────┬───────┘ │ .ai/plan.md │ ▼ ┌──────────────┐ │ Claude Code │ │ Developer │ └──────┬───────┘ │ Git Diff │ ▼ ┌──────────────┐ │ Cursor Agent │ │ Test / Int. │ └──────┬───────┘ │ Test Report │ ▼ ┌──────────────┐ │ Grok │ │ Reviewer │ └──────┬───────┘ │ ┌───────┴────────┐ │ │ PASS FAIL │ │ ▼ ▼ Stop / PR Claude Fix │ ▼ Cursor Retest │ ▼ Grok Review3. Recommended Project Structure
Section titled “3. Recommended Project Structure”For example, MarketLens:
MarketLens/│├── .ai/│ ├── task.md│ ├── plan.md│ ├── implementation.md│ ├── test-report.md│ └── review.md│├── AGENTS.md├── orchestrator.py│├── src/├── tests/└── ...4. task.md
Section titled “4. task.md”This is the main file you would normally write for each task.
For example:
# Task
Add support for scanning a single ticker.
Example:
python scan.py --ticker NVDA
## Requirements
- Existing watchlist scan must continue working.- Validate invalid ticker input.- Support lowercase input.- Add automated tests.- Do not change unrelated functionality.
## Definition of Done
- Existing tests pass.- New tests pass.- Lint passes.- Type checking passes.- Independent review returns PASS.5. AGENTS.md
Section titled “5. AGENTS.md”AGENTS.md can act as the project rules that every AI developer must follow.
For example:
# Project Instructions
## Architecture
Python application for stock screening and analysis.
## Coding Rules
- Do not change public APIs without approval.- Keep functions small.- Avoid unnecessary dependencies.- Do not modify unrelated files.- Never commit secrets.- Add tests for new behaviour.
## Validation
Before completing a task run:
pytestruff check .mypy .
All tests must pass.
## Git Rules
- Work on a feature branch.- Never push directly to main.- Do not rewrite unrelated history.6. Orchestrator
Section titled “6. Orchestrator”The first version does not need CrewAI, LangGraph, or another large agent framework.
A simple Python script is enough to coordinate the four CLI agents.
Concept:
Python ↓subprocess ↓Codex CLIClaude CLICursor CLIGrok CLI7. First Version of orchestrator.py
Section titled “7. First Version of orchestrator.py”from pathlib import Pathimport subprocess
ROOT = Path(__file__).parentAI_DIR = ROOT / ".ai"
AI_DIR.mkdir(exist_ok=True)
def run(command: list[str], prompt: str) -> str:
result = subprocess.run( command + [prompt], cwd=ROOT, text=True, capture_output=True, encoding="utf-8", )
if result.returncode != 0: raise RuntimeError(result.stderr)
return result.stdout
# =========================================================# 1. CODEX — ARCHITECT# =========================================================
plan = run( ["codex", "exec"], '''Read:
.ai/task.mdAGENTS.md
Inspect this repository.
Act as the software architect.
Do NOT modify any files.
Produce an implementation plan covering:
- affected files- architecture- implementation steps- tests required- edge cases- risks''')
(AI_DIR / "plan.md").write_text( plan, encoding="utf-8")
# =========================================================# 2. CLAUDE CODE — IMPLEMENTATION# =========================================================
implementation = run( [ "claude", "-p", "--output-format", "text" ], '''Read:
.ai/task.md.ai/plan.mdAGENTS.md
Implement the task.
You may modify source code and tests.
Run the relevant build and tests before finishing.
Rules:
- Do not modify unrelated files.- Do not remove existing tests.- Follow the architecture plan.- Add tests for new behaviour.
At the end summarize what you changed.''')
(AI_DIR / "implementation.md").write_text( implementation, encoding="utf-8")
# =========================================================# 3. CURSOR — INTEGRATION / TESTING# =========================================================
test_report = run( [ "agent", "-p", "--output-format", "text" ], '''Read:
.ai/task.md.ai/plan.mdAGENTS.md
Inspect the current git diff.
Act as an integration engineer.
Run all relevant:
- tests- lint- type checking- build
Fix problems caused by this implementation.
Do not perform unrelated refactoring.
Report:
- commands executed- tests run- failures found- fixes made- final result''')
(AI_DIR / "test-report.md").write_text( test_report, encoding="utf-8")
# =========================================================# 4. GROK — INDEPENDENT REVIEW# =========================================================
review = run( [ "grok", "-p", "--output-format", "plain" ], '''Read:
.ai/task.md.ai/plan.md.ai/test-report.md
Inspect the current git diff.
Act as an independent senior code reviewer.
Do NOT modify the implementation.
Review for:
- logic bugs- security issues- regressions- race conditions- missing edge cases- missing tests- architecture problems- unnecessary complexity
Finish with EXACTLY one of:
VERDICT: PASS
or
VERDICT: FAIL
If FAIL, list the blocking issues clearly.''')
(AI_DIR / "review.md").write_text( review, encoding="utf-8")
print(review)8. Feedback Loop
Section titled “8. Feedback Loop”The key step that turns this into a real agent team is:
If the reviewer returns FAIL, automatically send the work back to the developer.
For example:
Claude ↓Cursor ↓Grok ↓ FAIL ↓Claude Fix ↓Cursor Retest ↓Grok ReviewYou can add:
MAX_REVIEW_ATTEMPTS = 2
for attempt in range(MAX_REVIEW_ATTEMPTS):
test_report = run_cursor_tests()
review = run_grok_review()
if "VERDICT: PASS" in review: print("Review passed.") break
run_claude_fix(review)9. Claude Fix Prompt
Section titled “9. Claude Fix Prompt”When Grok returns FAIL:
Read:
.ai/task.md.ai/plan.md.ai/review.md
The independent reviewer found blocking issues.
Fix ONLY the blocking issues listed in the review.
Do not perform unrelated refactoring.
Run relevant tests after fixing.Then run the cycle again:
Claude Fix ↓Cursor Test ↓Grok ReviewContinue until:
VERDICT: PASSor until the maximum retry count is reached.
10. Initial Safety Rules
Section titled “10. Initial Safety Rules”At the beginning, AI agents should not have:
- Production DB write access
- Azure production credentials
- AWS production credentials
- Production deployment permission
- Direct push permission to
main - Auto merge permission
- Secret management permission
The first version should preferably stop at:
AI Development ↓Tests PASS ↓Review PASS ↓Git Diff / Pull Request ↓STOP ↓Human Approval11. Git Branch
Section titled “11. Git Branch”Each task should have its own branch:
main │ └── ai/123-single-ticker-scanAI agents should only work within:
ai/*A human should approve the merge at the end.
12. Phase Two: Git Worktree
Section titled “12. Phase Two: Git Worktree”Once the sequential pipeline is stable, you can begin introducing parallel agents.
Git Worktree allows each agent to have its own working copy.
For example:
MarketLens/│├── main/│├── worktrees/│ ├── backend/│ ├── frontend/│ ├── tests/│ └── review/The workflow can then evolve into:
Requirement │ ▼ Architect │ ┌─────────┼─────────┐ │ │ │ ▼ ▼ ▼ Backend Frontend Tests Agent Agent Agent │ │ │ └─────────┼─────────┘ │ ▼ Integrator │ ▼ Review13. Do Not Let Agents Edit the Same Folder in Parallel at the Start
Section titled “13. Do Not Let Agents Edit the Same Folder in Parallel at the Start”For the first version, avoid:
Claude ─┐Cursor ─┼── modifying src/ at the same timeGrok ───┘Because this can easily cause:
- overwrite changes
- merge conflicts
- tests interfering with one another
- agents not knowing what other agents have already changed
- more difficult debugging
So for the first version, use:
Codex ↓Claude ↓Cursor ↓GrokThis is much more stable.
14. Phase Three: GitHub Issue → AI
Section titled “14. Phase Three: GitHub Issue → AI”Later, you can use:
GitHub Issueas the system input.
For example:
GitHub Issue Created ↓Webhook / GitHub Action ↓Create branch ↓Generate .ai/task.md ↓Run orchestrator.py ↓Codex ↓Claude ↓Cursor ↓Grok ↓PASS ↓Create Pull RequestAt that point, you may not even need to create task.md yourself.
You only need to create a GitHub Issue:
Add support for single-ticker scanningThe AI team can then start working automatically.
15. Phase Four: CI Feedback
Section titled “15. Phase Four: CI Feedback”The next step is to automatically feed CI errors back to the agent.
For example:
Pull Request ↓GitHub Actions ↓pytest FAIL ↓CI log ↓Claude Code ↓Fix ↓Push ↓CI rerunThis creates a loop like:
Code ↓CI ↓FAIL ↓AI Fix ↓CI ↓PASS16. Target Architecture
Section titled “16. Target Architecture”In the longer term, the system can evolve into:
GitHub Issue │ ▼ AI Orchestrator │ ▼ Architect │ ┌────────────┼────────────┐ │ │ │ ▼ ▼ ▼ Backend Frontend Tests Agent Agent Agent │ │ │ └────────────┼────────────┘ │ ▼ Integrator │ ▼ CI │ ┌───────┴───────┐ │ │ PASS FAIL │ │ ▼ ▼ Reviewer Developer │ │ ┌──────┴──────┐ │ │ │ │ PASS FAIL ◄────┘ │ ▼ Pull Request │ ▼ Human Approval │ ▼ Merge17. Recommended Development Sequence
Section titled “17. Recommended Development Sequence”Do not try to build the most complex version all at once.
Recommended sequence:
Phase 1
Section titled “Phase 1”task.md ↓Codex ↓Claude ↓Cursor ↓GrokGoal:
The four agents can hand work to one another automatically without any manual copy and paste.
Phase 2
Section titled “Phase 2”Add:
Grok FAIL ↓Claude Fix ↓Cursor Test ↓Grok ReviewPhase 3
Section titled “Phase 3”Add:
- Structured JSON output
- Retry limits
- Error handling
- Logs
- Token / cost tracking
- Run history
Phase 4
Section titled “Phase 4”Add:
- Git branches
- Git worktrees
- Parallel agents
Phase 5
Section titled “Phase 5”Add:
GitHub Issue ↓Agent Team ↓Pull RequestPhase 6
Section titled “Phase 6”Add:
CI FAIL ↓AI Fix ↓CI RetestPhase 7
Section titled “Phase 7”Only consider these at the final stage:
- Auto merge
- Auto deploy
- Production changes
These capabilities should be enabled last.
18. Most Important Principles
Section titled “18. Most Important Principles”AI Should Not Define “Done” by Itself
Section titled “AI Should Not Define “Done” by Itself”There must be an objective Definition of Done, for example:
Build passesTests passLint passesType checking passesSecurity review passesIndependent reviewer passesTests Are One of the Most Important Guardrails in Agentic Coding
Section titled “Tests Are One of the Most Important Guardrails in Agentic Coding”The more automated the workflow becomes, the more important the tests become.
A repository with strong automated tests:
Average AI Model+Strong Testscan often be more reliable than:
Best AI Model+No Testsin practice.
Use Different Models for Different Roles
Section titled “Use Different Models for Different Roles”Not every agent needs to use the strongest model.
For example:
Codex→ Architecture / Planning
Claude Code→ Implementation
Cursor→ Integration / Testing
Grok→ Independent ReviewThe biggest value is not simply having four AIs writing code together.
Instead, it is:
Each AI has a clear role, clear inputs, clear outputs, and an objective verification process.
19. Suggested First Experiment
Section titled “19. Suggested First Experiment”Use one of your own projects, such as MarketLens, and choose a small feature.
For example:
Add:
python scan.py --ticker NVDASuccess criteria:
Codex writes plan ↓Claude implements ↓Cursor tests ↓Grok reviews ↓PASSIf this pipeline can run from start to finish without manual copy and paste, the first version of the Multi-Agent Development Pipeline is working successfully.
20. Final Goal
Section titled “20. Final Goal”The final goal is not:
Harry→ ChatGPT→ copy→ Claude→ copy→ Cursor→ copy→ GrokInstead, it is:
Harry ↓Requirement ↓AI Software Team ↓Pull Request ↓Harry ReviewIn other words, moving from:
Using AI to write code
to:
Managing a team of AI software agents.