AI coding agents are good enough now that a fair question is how to use several at once. Each lab ships its own command-line agent with its own subscription, and each is better at something. Claude is good at planning and writing. Codex is a careful reviewer. OpenCode is an open-source agent that can run dozens of cheaper models through one plan.
Put them in one window and the obvious idea is a team. That part takes an afternoon. What took much longer was everything around it. Which agent should take a task? Which model should it use, and how hard should that model think? How do you avoid burning the expensive subscription on work a cheap model could do? And what happens when an agent's memory fills up halfway through the day?
This piece walks through how we answered those questions with a small set of scripts, and what surprised us along the way. You don't need to know any of the tools beforehand.
First, the moving parts
A program that splits one terminal window into several panes, each running its own program. tmux is the classic one. Close the window and the panes keep running.
A multiplexer built for AI agents. Each pane gets a name, like hx-codex, and a small command-line tool can type into any pane, read it, and tell whether its agent is busy or idle.
A chat model that can read files, run commands and edit code in a project. Claude Code, Codex and OpenCode are three of them. Each runs in its own pane.
What makes a team possible is that Herdr lets one agent type into another agent's pane. The lead agent runs a single command:
# lead → reviewer: one line, no pasted code herdr agent prompt hx-codex '[team from hx-claude] Review T1. Run git diff main yourself.'
The reviewer sees the message, does the work, and answers the same way. Nobody pastes code into messages. The reviewer is told to run git diff itself, so each message stays a few lines long and no agent's memory fills up with copies of the same code.
Because every pane is on screen, a person can follow the whole conversation. That matters more than it sounds. We first ran short-lived helper agents invisibly in the background, and switched to giving each one its own visible window after the person running the team asked for it. A human notices "this has been idle for two minutes" much sooner than any timeout does.
Three agents, three wallets
Each agent comes with a subscription, and each subscription is a budget that refills on a timer. Claude and Codex give you plenty of a strong model, but not unlimited amounts, and you want them saved for judgment calls. OpenCode's plan is cheap and offers many models. So the plan was simple: spend OpenCode first, and keep Claude and Codex for the work only they can do.
Scopes the work, routes it, reads the diffs, makes the final call. Writes code itself only when a task is trivial.
scarce · spent on judgmentReviews every non-trivial change, since a different vendor catches different mistakes. Takes hard implementation when cheap models fail.
scarce · spent on reviewWrites most of the code, on whichever cheap model fits the task. The first place any routine job goes.
cheap · spent on volumeThe first time we actually measured where the money went, that plan wasn't what was happening. OpenCode stores a cost for every reply in a local database, so a few lines of SQL gave the real picture for one week:
Nobody had chosen to spend that money. Kimi was simply the model the pane started with, and a long-running pane re-sends its whole conversation on every turn. That one number shaped the rest of the project: a default nobody looks at can become most of the bill.
Let scripts decide what scripts can know
The obvious fix is to tell the lead agent to "pick a sensible model". That costs tokens on every decision, and the answer changes with the wording of the prompt. Most of the inputs are plain facts anyway. How much budget is left is a number in a file. Whether a model just hit its quota is a line in a log. Whether another agent is already editing a file is a lookup.
So we wrote hx, a small command-line tool with no server and no database, just Python and a few JSON files. The lead calls it the way you would call git. Its most-used command answers one question: given this task, who should do it, on which model, and how hard should that model think?
$ hx route --kind feature --size medium { "worker": "codex", "model": "gpt-6-luna", "effort": "medium", "reason": "opencode shared pool exhausted; codex fallback (util 0.40)", "stages": ["attempt_cap_ok", "failure_cause", "pool:opencode", "tier:default", "tried:default", "tried:strong", "fallback:codex"] }
That is real output from a day when the OpenCode budget was nearly used up. The router tried OpenCode's models, found no room, and sent the task to Codex's cheapest model instead. Every decision is logged, so later you can check which choices paid off. Here is a simplified version of the same logic to try:
Cheapest capable model. The implementer pane already runs it and knows the code, so the task goes there.
Two rules in there do most of the saving. The first is that a bad brief never buys a bigger model. If a task failed because the instructions were unclear or a tool broke, the same model gets a better brief. Only a genuine "not capable enough" failure moves one step up the ladder, and after three attempts the router stops and hands the problem to a human instead of looping.
The second is to prefer the agent that is already warm. An agent that has worked on the code for an hour already knows it. Re-reading that knowledge from a cache costs far less than starting a fresh agent that has to explore the project from scratch. We learned this one from a live run, where the order of the ladder meant the warm implementer was never picked for medium-sized work.
Picking a model is an experiment, not an opinion
To fill the ladder we needed to know which cheap models could do the work. We wrote five small tasks: fix a bug, add a feature across three files, debug from a misleading error, refactor, and write tests that must catch planted bugs. Each task had a hidden checker. Before trusting a checker, we ran it against the untouched code, where it must fail, and against a known-good solution, where it must pass. That caught one checker that rejected four correct refactors. Without it, a good model would have looked bad.
The more useful lesson came after the benchmark. One model, minimax-m3, passed all five tasks and then failed four of six real edits in exactly the same way. On a real project it read 35,000 to 40,000 tokens of code, used up its fixed 32,000-token thinking budget, and stopped without writing a line. The small benchmark tasks never pushed it that far.
The agent reported success after it failed.
The other trap was quieter. Run in the background, OpenCode exits with code 0, the usual signal for success, after an API error, after a refused permission, and after a reply that was cut off. A script that trusts the exit code believes all of those worked. hx ignores the exit code and reads the run's event log instead: a run counts as finished only if the model ended with a real final message.
How hard a model should think turned out to depend on the vendor. For Codex and Claude the effort setting is real: Codex's cheap model at low effort spent 155 thinking tokens on a bug fix and passed. For several OpenCode models the advertised effort levels made no difference we could measure, so the router expresses effort there by choosing a stronger or weaker model, and sends an effort setting only to models that use it.
Why agents need to forget
A chat model keeps nothing between calls. Every time an agent takes a step, the whole conversation so far is sent again: your messages, its replies, every file it read. Caching makes the repeated part cheaper, but you still pay for it on every call, and a crowded context makes the model slower and less focused. Each turn makes the conversation longer, and every later turn pays for that length again.
The fix is compaction: the agent replaces its long history with a short summary and carries on. Most agents do this on their own when the window is nearly full. But nearly full is late, and it can happen in the middle of a task, when a summary is most likely to drop the one error message that mattered. Our rule is to compact when a task is finished and the history has passed 40% of the window. We also cap that window at 200K tokens, even for models that accept a million, because the cost hurts long before the window fills.
Compaction is also where a team can lose work, so hx wraps it in a small protocol:
- Wait for the boundaryThe task is done, the agent is idle, nothing else is assigned to it.
- Write a checkpointDecisions, exact errors, tests run, the next action. Saved to a file.
- Reserve the agentNo new work can be sent to it while it compacts.
- Send /compactThen confirm it is the same session and that it really shrank.
- Prove it remembersIt reads the checkpoint and replies with a one-time code and its next action.
That live run also failed in a way no test had predicted. The compaction worked, but the check afterwards said it hadn't. Herdr returns a pane's screen as plain text, not the structured data the code expected, and the agent's interface had wrapped its reply across two lines, splitting the one-time code. The controller did the right thing with what it saw: it marked the result as unknown and refused to send the agent new work until someone looked. We had 240 automated tests at that point. Eleven bugs appeared only once real agents ran on real files, and these two were among them.
The lead compacts too. A hook runs just before its summary is written and tells it to keep task IDs, exact errors and next actions word for word. Another hook runs afterwards and puts the active tasks and the latest checkpoint back in front of it. We also wanted to know whether the lead could compact itself on purpose, at a moment it chose. It can: it starts a background job that waits a minute and then sends /compact to its own pane. By then the lead has finished its turn and is idle, so the command runs like any other. Part of this article was written by an agent on the far side of one of those summaries.
Remembering what matters
Forgetting on purpose only works if the important things are written down first. We ended up with three layers, each lasting longer than the one before.
Everything the agent is holding right now. Cheap to add to, expensive to keep. Compacted at task boundaries.
each agent's own sessionWhat one task decided, broke and still needs. Written by the agent doing the work, checked by hx before any compaction.
Decisions and lessons worth keeping across projects, in an Obsidian notebook all three agents can search. Old decisions are marked superseded, never deleted.
Obsidian vault, one note per projectThe vault is plain Markdown files in folders, readable by people and by all three agents. Every session is captured as a dated note. A separate pass folds what was learned into one current note per project. When an early assumption about how OpenCode meters its budget turned out to be wrong, the old decision stayed in the note, marked superseded, next to the correction. An agent reading the note later sees both, and why one replaced the other. How that memory works, and why it took a month, is its own story: Goldfish no more.
One skill, three agents
All of this behaviour has to live somewhere the agents will read it. Each agent supports skills: a folder holding a Markdown file of instructions, which the agent loads when a task matches the skill's description. The catch is that each vendor looks for skills in its own folder, so a skill written for Claude is invisible to Codex.
We didn't have to solve this ourselves. pstack, a skill collection by Lauren Tan, already keeps every skill in one source folder and ships a sync script that copies each one to every agent's location, then checks the copies match. We added the team's two skills, the collaboration rules and the router playbook, to that folder, and pstack's sync delivers them alongside its own.
"The file was copied" and "the agent loaded it" turned out to be different things. One skill was copied correctly and then ignored, because its one-line description contained a colon followed by a space, which broke the YAML header at the top of the file. The agent fell back to the file's heading and never matched the skill to a task. Now we confirm that each skill appears in each agent's own debug listing, not just that the file exists.
What we would tell someone starting out
- Measure the bill before you optimise it.Our biggest saving came from a default model nobody had chosen. One query against a local database found it.
- Give the facts to scripts and the judgment to models.Budgets, retries, file ownership and thresholds are lookups. Paying a model to guess them costs tokens and gives a different answer each time.
- Never trust an agent's exit code.Read what it did: the final message, the files it changed, the tests it ran.
- Benchmark on work that looks like your work.Small tasks tell you which models are broken. Only real tasks show where a model breaks.
- Forget on purpose, at a boundary, with a receipt.Compact when a task is finished, write down what matters first, and make the agent prove it read it.
- Keep the agents where you can see them.A person watching three panes spots a stuck agent long before any timeout fires.
The setup runs on Windows 11 with Herdr 0.9, Claude Code, Codex CLI 0.163 and OpenCode on its Go plan. hx is a few thousand lines of standard-library Python with 240 tests. Benchmark costs are single runs on small tasks: good for spotting broken models, weak for ranking close ones. The context chart is an illustration; every other number comes from logs of real runs.