Parallel Coding Agent Stack: Git Worktrees, Memory Layers and Guardrails
When running 2–4 coding agents (Claude Code, Codex CLI, OpenCode) at once, the biggest failure mode is sessions overwriting the same workspace or colliding on ports and databases. Combine isolated Git worktrees, a session board, permission deny-lists and scoped memory to keep parallel work safe.
- Advancing independent tracks simultaneously—such as UI polish, API fixes and test coverage—without waiting serially on one agent loop.
- Reviewing clean per-task Git diffs and test logs side by side before anything lands on
main.
- Tightly coupled refactors touching the same shared files, where parallel branches mostly create merge conflicts.
- Tiny one-off scripts without version control or automated tests.
Architecture & flow
Stack layers & catalog tools
Layer 1 · Primary coding host
Source: Codex approvals & security docs ↗Reads the codebase, edits files and runs tests while enforcing command approvals and OS/container sandboxing.
Wiring & protocols: Configured via AGENTS.md / CLAUDE.md, lifecycle hooks (PreToolUse), and CLI permission flags.
Claude Code
Use natural-language commands to work on code and Git workflows from your terminal, IDE, or GitHub.
Codex CLI
OpenAI's official coding agent for your terminal
opencode
The open source coding agent for your terminal
Pick one primary host or pair a read-only Codex review session with OpenCode/Claude Code implementation.
Layer 2 · Worktree & session board
Source: Parallel coding-agent managers rankingGives each task its own Git worktree and highlights which background agent session is waiting on your approval.
Wiring & protocols: Spawns isolated Git worktrees and manages terminal/container sessions per task.
Orca
A desktop ADE for running and reviewing parallel CLI coding agents in isolated Git worktrees.
cmux
A Ghostty-based macOS terminal with vertical tabs and notifications for AI coding agents.
Vibe Kanban
A kanban workspace for planning, running, reviewing, and shipping coding-agent work.
Container Use
Run multiple coding agents safely in parallel inside isolated containerized environments.
For zero extra dependencies, plain git worktree add ../feat-a -b feat-a covers basic isolation.
Layer 3 · Cross-session memory
Source: Agent memory layers rankingPrevents re-explaining architecture conventions in every fresh worktree without bloating the prompt window.
Wiring & protocols: Captures observations via hooks and retrieves snippets on demand via MCP tools.
Claude-Mem
Persistent, searchable project memory for coding agents across sessions.
Magic Context
Persistent context management and cross-session project memory for OpenCode and Pi coding agents.
Keeping concise build/test instructions in AGENTS.md already covers most single-repo needs.
Find companion SKILL.md packs on FollowSkills.com → Discover compatible MCP servers on FollowMCP.com →
Wiring & hardening steps
1. Isolate every session in its own Git worktree before launching agents
Never point two active coding sessions at the same working tree. Give each task a clean branch and directory.
git worktree add ../repo-auth -b feat/auth
git worktree add ../repo-tests -b test/coverage
2. Lock down secret reads and destructive commands in host config
Deny .env reads and destructive shell commands in .claude/settings.json, or switch OpenCode from default allow to ask via opencode.json.
{
"permissions": {
"deny": ["Read(./.env)", "Read(./.env.*)", "Bash(rm -rf *)"]
}
}
3. Isolate test ports and temporary databases across worktrees
Parallel test runs fail flakily when they share a fixed port or SQLite file. Document per-worktree env overrides in AGENTS.md.
Common traps & fixes
container-use).--dangerously-skip-permissions across all concurrent tabs to save clicks.Pre-flight safety checklist
- Clean
mainbranch; every agent runs inside its own worktree and feature branch. - Secret files (
.env*) and destructive shell commands explicitly denied in host settings. - Test commands use isolated ports and temporary databases per worktree.
- Verification commands (
pytest,npm test, linters) documented inAGENTS.md/CLAUDE.md. - Every merged branch passes a human
git diffreview first.
FAQ
How many parallel sessions are practical at once?
Most developers find 2–3 independent tasks optimal. Beyond 4 concurrent sessions, human code-review bandwidth and merge conflicts usually become the bottleneck.
Does a Git worktree provide OS-level sandboxing?
No. A worktree only separates Git working directories; processes still share your user account, home folder and network unless wrapped in an OS sandbox or Docker container.
Can Claude Code and Codex share one project rules file?
Yes—keep canonical build and safety rules in AGENTS.md and reference it from CLAUDE.md so instructions stay in sync.
Related hubs, guides & concepts
Agent Workflow Stacks
Thanks — we use this to improve the page.