r/ClaudeCode • • 2d ago

Built with Claude Open source: a tmux-like multiplexer where Claude Code spawns visible sub-agents through MCP tools, and what I learned wiring it up

I built amux, a terminal multiplexer for coding agents (Linux, works over ssh, MIT): https://github.com/elyesghazel/amux

Inside amux, Claude Code gets six MCP tools: spawn_agent, wait_for_agents, list_agents, read_agent, send_to_agent and close_agent. In the video Claude splits a code review across three sub-agents, each a full interactive Claude Code in its own pane, waits for them and merges the results. You can switch into any of those panes and take over.

Claude Code wrote nearly all of it (Rust, in about a day). It also tested itself by running amux in a hidden tmux session with real Claude instances inside and reading the screen back. Things I learned that might help anyone building around Claude Code:

  1. Hooks beat parsing the terminal. Notification means "needs you", Stop means "done", UserPromptSubmit and PostToolUse mean "working". That gives exact state for the notification rings, no guessing from spinners.
  2. The Stop hook payload carries last_assistant_message. That's how the parent gets each sub-agent's final answer cleanly. The transcript_path JSONL works as a fallback.
  3. Pass everything per process. claude --settings <file> --mcp-config <file> puts the hooks, the MCP server and a permissions.allow list for the read-only tools on one pane, without touching ~/.claude.
  4. --mcp-config takes several values. A prompt placed after it gets read as another config file. Put the prompt (claude "task") before the flags.
  5. claude "task" stays interactive. Unlike -p, the sub-agent keeps running as a normal session you can talk to, so follow-ups go in with send_to_agent.
  6. Watch inherited env vars. If you start claude from inside another Claude Code session, a CLAUDE_CODE_CHILD_SESSION variable turns transcript saving off. Clear CLAUDE* vars when you launch from scripts.

Guardrails: at most 12 agents, 2 levels of nesting, an agent can only control panes it started, and spawn/send/close go through the normal permission prompt.

Limits: early, Linux only, no detach/reattach yet (next on the list).

2 Upvotes

4 comments sorted by

•

u/AutoModerator 2d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

1

u/hieuphung97 2d ago

Spot on with hooks over terminal scraping. We wasted so much time fighting dirty ANSI escape sequences and partial renders trying to detect when a worker actually settled. Grabbing last_assistant_message directly from the payload makes coordinator logic ten times cleaner.

1

u/amirfish 2d ago

The hooks point matches what I found building something similar. Stop, Notification and PostToolUse give you exact state, parsing terminal output or spinners is a losing game once you have more than a couple sessions running.

One thing I'd add: route the result back as a ticket, not just a wait_for call. In CCC, the open source queue I run my agents through, a worker takes the next ticket and works it to done, and only a real decision gets routed back to me, so I'm not the one polling for status. How are you routing it back when a sub-agent needs your input mid-task?

Free and open source: getccc.dev · GitHub

1

u/karol207 5m ago

Does the launcher preserve `CLAUDE_CONFIG_DIR` when cleaning the inherited environment? Clearing every `CLAUDE*` variable can also change where the child reads settings and writes session history, so getting transcripts back doesn't guarantee it kept the same configuration.