How we run five coding agents side by side in one window
I build NestMux, a desktop app that runs Claude Code, Codex, Gemini CLI, Copilot and OpenCode in a grid of real terminals, each with its own account and its own git worktree. This is how it works inside, including the parts that are heuristics wearing a confident UI and the parts that do not survive a restart. If you are building something similar, most of this transfers. If you are deciding…
NestMux is a desktop application that enables users to run multiple coding agents, such as Claude Code, Codex, Gemini CLI, Copilot, and OpenCode, simultaneously within a single window. Each agent operates in its own terminal, complete with its own account, Git worktree, and configuration.
The application simplifies the structure of each "pane" through an interface called PaneNode, which contains essential properties such as an ID, the type of AI agent (claude, codex, gemini, copilot, opencode, terminal, or custom), the account name, and the directory path. There is no specific AI-related code underlying this setup; instead, each pane spawns a shell using node-pty, sets the HOME directory to the pane's account directory, adjusts the current working directory to the specified repository path, and executes the provided command.
Support for new agent CLIs is straightforward, involving the addition of a row in a list, making custom CLIs a user-friendly feature rather than a complex release. The app focuses on environmental management rather than parsing agent outputs or interacting with their APIs — it treats each agent as a program running in a terminal window. Key differences between panes include isolated Home directories for account-specific logins and git worktrees to prevent conflicts when multiple agents edit the same repository.
Broadcasting prompts to all panes is surprisingly simple, requiring only four lines of code. Instead of using a custom protocol, the terminal emulator provides every keystroke, allowing the app to distribute inputs across all active panes. Although this approach captures all inputs, including special keys like Ctrl+C and arrow keys, it also means that panes must handle unexpected commands without additional parsing or readiness checks.
Monitoring system resources for each pane is particularly challenging. Since each pane's processes inherit from the shell, standard methods for obtaining resource metrics are ineffective. The solution involves recursively scanning the process tree, which can be resource-intensive and prone to errors, especially on Windows where process links can quickly become stale. This heuristic method, while effective for most cases, lacks precision and fails to account for elevated processes or those from other users.
The application's built-in diff viewer is a simple yet efficient solution for displaying changes from each agent. It executes a git diff command specifically for the worktree associated with each pane and parses the output to present differences in an organized format. To optimize performance, the viewer skips rendering for files over 10,000 lines, focusing on more manageable chunks.
Additionally, the default behavior of using the HEAD base for diffs assumes that agents commit changes at the end of their execution, although some agents now commit continuously.
The application ensures a seamless experience by maintaining session data in session.json, which stores pane configurations and other relevant information. However, the app acknowledges that certain aspects, such as handling system restarts or ensuring consistent agent behavior, present ongoing challenges that require careful consideration and ongoing refinement.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.