Skip to content

Building an Automated Multi-Agent Coding Workflow with Codex, Claude Code, Cursor, and Grok

Version: 16 October 2026


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 Request
FAIL → Automatically return to Claude Code for fixes

You only need to write the requirement once. The orchestrator then automatically hands the work to the appropriate agents.


For the first version, avoid letting all four agents modify the same files at the same time. Use a sequential pipeline instead.

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.


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.


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.


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: PASS

or:

VERDICT: FAIL

If 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.


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 Review

For example, MarketLens:

MarketLens/
│
├── .ai/
│ ├── task.md
│ ├── plan.md
│ ├── implementation.md
│ ├── test-report.md
│ └── review.md
│
├── AGENTS.md
├── orchestrator.py
│
├── src/
├── tests/
└── ...

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.

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:
pytest
ruff check .
mypy .
All tests must pass.
## Git Rules
- Work on a feature branch.
- Never push directly to main.
- Do not rewrite unrelated history.

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 CLI
Claude CLI
Cursor CLI
Grok CLI

from pathlib import Path
import subprocess
ROOT = Path(__file__).parent
AI_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.md
AGENTS.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.md
AGENTS.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.md
AGENTS.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)

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 Review

You 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)

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 Review

Continue until:

VERDICT: PASS

or until the maximum retry count is reached.


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 Approval

Each task should have its own branch:

main
│
└── ai/123-single-ticker-scan

AI agents should only work within:

ai/*

A human should approve the merge at the end.


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
│
▼
Review

13. 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 time
Grok ───┘

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
↓
Grok

This is much more stable.


Later, you can use:

GitHub Issue

as 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 Request

At 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 scanning

The AI team can then start working automatically.


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 rerun

This creates a loop like:

Code
↓
CI
↓
FAIL
↓
AI Fix
↓
CI
↓
PASS

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
│
▼
Merge

Do not try to build the most complex version all at once.

Recommended sequence:

task.md
↓
Codex
↓
Claude
↓
Cursor
↓
Grok

Goal:

The four agents can hand work to one another automatically without any manual copy and paste.


Add:

Grok FAIL
↓
Claude Fix
↓
Cursor Test
↓
Grok Review

Add:

  • Structured JSON output
  • Retry limits
  • Error handling
  • Logs
  • Token / cost tracking
  • Run history

Add:

  • Git branches
  • Git worktrees
  • Parallel agents

Add:

GitHub Issue
↓
Agent Team
↓
Pull Request

Add:

CI FAIL
↓
AI Fix
↓
CI Retest

Only consider these at the final stage:

  • Auto merge
  • Auto deploy
  • Production changes

These capabilities should be enabled last.


There must be an objective Definition of Done, for example:

Build passes
Tests pass
Lint passes
Type checking passes
Security review passes
Independent reviewer passes

Tests 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 Tests

can often be more reliable than:

Best AI Model
+
No Tests

in practice.


Not every agent needs to use the strongest model.

For example:

Codex
→ Architecture / Planning
Claude Code
→ Implementation
Cursor
→ Integration / Testing
Grok
→ Independent Review

The 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.


Use one of your own projects, such as MarketLens, and choose a small feature.

For example:

Add:
python scan.py --ticker NVDA

Success criteria:

Codex writes plan
↓
Claude implements
↓
Cursor tests
↓
Grok reviews
↓
PASS

If 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.


The final goal is not:

Harry
→ ChatGPT
→ copy
→ Claude
→ copy
→ Cursor
→ copy
→ Grok

Instead, it is:

Harry
↓
Requirement
↓
AI Software Team
↓
Pull Request
↓
Harry Review

In other words, moving from:

Using AI to write code

to:

Managing a team of AI software agents.