Eslam HelmyEslam Helmy
3 min readEslam

Two AI Agents, One Terminal: How I Compare Before I Commit

Claude Code, Codex CLI 5.3, Gemini CLI — each has its strengths, and if you're already subscribed, you have their CLI tools out of the box. When you're unsure which handles a task better, run both and compare.

Cursor supports this with parallel agents, but that's an extra subscription you don't need. Git worktrees, a shell function, and a terminal with splits do the same thing.

Here's how.


Git Worktrees: The Foundation

The key to running two agents in parallel without conflicts is Git worktrees. A worktree lets you check out multiple branches of the same repo simultaneously, each in its own directory, sharing the same .git history.

Instead of this:

~/projects/MyApp          ← stuck on one branch at a time

You get this:

~/projects/MyApp                    ← main branch (original)
~/projects/MyApp-auth-refactor      ← feature branch (worktree)
~/projects/MyApp-auth-refactor-v2   ← another feature branch (worktree)

No cloning. No stashing. Fully isolated directories. Each agent works in its own space — no file conflicts, no stepping on each other.


The Problem: Too Many Commands

Creating a worktree manually means running a chain of commands every time:

git fetch origin
git worktree add -b feature/auth-refactor ../MyApp-auth-refactor origin/main
cd ../MyApp-auth-refactor
claude

And cleanup is just as tedious:

cd ..
git worktree remove ../MyApp-auth-refactor --force
git branch -D feature/auth-refactor

That's a lot of friction for something you want to do quickly and often.


Automating It

I wrote two shell functions that reduce all of that to a single command. Add these to your shell config file:

  • macOS (Zsh): ~/.zshrc
  • Linux (Bash): ~/.bashrc
  • Windows (PowerShell): Microsoft.PowerShell_profile.ps1 (run echo $PROFILE to find it) — the syntax will need to be adapted to PowerShell functions
worktree() {
  local branch="feature/$1"
  local dir="../$(basename $(pwd))-$1"
  local tool="${2:-claude}"
  git fetch origin && git worktree add -b "$branch" "$dir" origin/main && cd "$dir" && "$tool"
}
 
worktree-clean() {
  local dir="../$(basename $(pwd))-$1"
  cd ..
  git worktree remove "$dir" --force
  git branch -D "feature/$1"
  echo "Cleaned up worktree and branch for $1"
}

Reload your config (source ~/.zshrc on macOS, source ~/.bashrc on Linux).


Putting It Together with Ghostty

Now comes the fun part. Open your repo in Ghostty and create a split. Ghostty supports horizontal and vertical splits, and all shortcuts are fully customizable through its config file — so use whatever keybindings work for you.

In the first pane, launch Claude Code:

worktree auth-refactor claude

Switch to the other pane and launch Codex on the same task:

worktree auth-refactor-v2 codex

The second argument is the tool to launch. It defaults to claude if you don't specify one.

Watch both agents work simultaneously. Jump between panes using your configured split navigation shortcuts.

That's it. Two AI agents solving the same problem in isolated Git worktrees, visible in one window.

When you're happy with one of the results, push the branch and open a pull request:

git push origin feature/auth-refactor

Then clean up the worktrees you no longer need:

worktree-clean auth-refactor
worktree-clean auth-refactor-v2

Worktrees removed. Branches deleted. Done.

Tip: This setup isn't just for comparing tools. I use the same workflow whenever I need to work on multiple features in parallel — each in its own worktree, each with its own agent. Same function, different use case.

Share this post