Built by Doug Cone. Available for consulting on multi-agent infrastructure, AI integration, and production agent platforms.
Janus runs Claude Code, Hermes, OpenCode, or Codex agents — each in its own tmux window, with the agents in a container sharing one set of MCP servers, one credential store, and one event bus. Inbound events come from Mattermost (or any source you wire in); outbound responses go back through the same channel. The cli/janus driver attaches to a specific agent's pane on demand.
The shipped example is a single claude-agents container running four agents. The same image scales to multiple containers side-by-side — one per agent group, or an isolated container for an agent that needs a different blast radius (broader host mounts, separate credentials). Spin one up as a one-line compose service that sets JANUS_AGENTS=<name> to restrict it to that agent; cli/janus auto-discovers every running janus container and addresses agents across all of them.
The interesting part is bridging runtimes that don't speak Claude Code's channel protocol. The pattern is documented in docs/tui-mcp-bridge.md; two halves, both runtime-agnostic at their boundary:
- Input — tmux-inject. When an inbound message arrives, the
mattermost-channelMCP server types the wrapped payload into the agent's tmux pane viatmux send-keys. The TUI sees it as if the user typed it. - Output — post-turn hook. Every TUI exposes a "this turn finished, run a script" hook (
Stopfor CC,post_llm_callfor Hermes). The hook reads the assistant response and, if the agent didn't already call a Mattermost tool, posts it to the channel as a backstop.
The trick on the input side is that Hermes's Ink-based
textInputcoalesces fast back-to-back stdin into a paste buffer with a 50ms debouncer, then strips the trailing newline on flush. Sending content + Enter as a singletmux send-keyscall types the message but never submits it. A >50ms gap between the two send-keys calls forces the paste to flush so Enter lands as its ownk.returnkeypress event — the path that actually triggerscbSubmit. Small detail; the difference between a working bridge and a broken one.
CC agents continue to use the native notifications/claude/channel event when MATTERMOST_INJECT_TARGET is unset, so adopting the bridge is opt-in per agent.
┌────────────────────────────────────────────────────────────────┐
│ claude-agents container (node:22-slim + bun + uv + chromium) │
│ │
│ Shared MCP servers (one process per agent that registers): │
│ mattermost-channel/ reply + post + react + tmux-inject │
│ heartbeat/ interval+jitter OR cron schedules │
│ scrapling user-level (host bind-mounted venv) │
│ qmd user-level (host bind-mounted package) │
│ │
│ ┌──────────────┐ ┌──────────────┐ ┌──────────────┐ ┌────────┐ │
│ │ tmux: health │ │ tmux: geordi │ │ tmux: mktg │ │ links │ │
│ │ Claude Code │ │ Claude Code │ │ Claude Code │ │ Hermes │ │
│ │ #health-log │ │ #project-mgmt│ │ #marketing │ │#link- │ │
│ │ wger API │ │ Planka,vault │ │ research │ │ dump │ │
│ └──────────────┘ └──────────────┘ └──────────────┘ └────────┘ │
└────────────────────────────────────────────────────────────────┘
Four example agents demonstrate the patterns:
| Agent | Runtime | What it does |
|---|---|---|
| health | Claude Code | Logs health entries (weight, BP, etc.) from a Mattermost channel via the wger API. |
| geordi | Claude Code | Project-management — Planka boards, vault notes, scheduled status checks. |
| marketing | Claude Code | Daily content generation from overnight research; cron-driven (5am M–F). |
| links | Hermes | Silent link archiver. Watches #link-dump, fetches each URL, writes a 3-line entry into an Obsidian vault, reacts :bookmark:. |
links is the worked example of the bridge pattern from the Hermes side — driven through tmux-inject for input and the post_llm_call hook for output. The other three are CC-native.
git clone https://github.com/nullvariable/janus.git
cd janus
# Configure host paths (defaults in docker-compose.yml; override via .env or shell env)
cp -n agents/health/.env.example agents/health/.env
# ...same for each agent you intend to run
# Build (HOST_USER controls the /home/<user> -> /home/node symlink for absolute
# paths in your ~/.claude.json)
docker compose build --build-arg HOST_USER=$(whoami)
docker compose up -d
# Attach to an agent
./cli/bin/janus attach linksDefaults assume your agent source projects live under ~/projects/ and your Obsidian vaults under ~/vaults/. Every host path is overridable — see docker-compose.yml for the full env-var-driven list.
The TypeScript mattermost-channel server can expose its existing MCP tools over
Tailscale HTTPS with WhoIs allowlisting, and independently verify the Mattermost
tailnet device before routing REST/WSS through an isolated child node. Stdio stays
available; leaving all TSNET variables unset preserves the default path. See
the locked contract and deployment guide for prerequisites,
identity grammar, loopback trust assumptions and limitations.
| Environment variable | Default | Purpose |
|---|---|---|
MATTERMOST_TSNET_AUTHKEY |
unset | Required enrollment key for either half; use deployment secrets. |
MATTERMOST_TSNET_LISTEN |
unset | Enable tailnet MCP HTTPS on :<port>, e.g. :8443. |
MATTERMOST_TSNET_ALLOW |
unset | Required inbound OR allowlist: user:, tag:, device:, or explicit *. |
MATTERMOST_TSNET_HOSTNAME |
mattermost-mcp-<channel ID first 8 chars> |
Child node hostname. |
MATTERMOST_TSNET_STATE_DIR |
<effective MATTERMOST_STATE_DIR>/tsnet |
Private persistent state; one process per directory. |
MATTERMOST_TSNET_EXPECT_MM_DEVICE |
unset | Enable outbound verification of WhoIs device hostname; requires HTTPS Mattermost. |
MATTERMOST_TSNET_CONTROL_URL |
unset | Optional HTTP(S) control-plane override. |
- Create
agents/<name>/.mcp.jsondeclaring the MCP servers it needs (useagents/health/.mcp.jsonas the smallest reference,agents/geordi/.mcp.jsonfor one withheartbeat). - Add
agents/<name>/.env.examplelisting the env vars the.mcp.jsonreferences via${VAR}. - Add the agent to
entrypoint.sh:AGENTS[<name>]=/agents/<name>in the workdir mapCHANNELS[<name>]="server:mattermost ..."listing each MCP channel to loadAGENT_ORDERarray
- Bind-mount the source project at
/agents/<name>indocker-compose.yml.
- Create
agents/<name>/config.yaml(Hermes config). Useagents/links/config.yamlas the reference; the key bits are themcp_servers.mattermost.env.MATTERMOST_INJECT_TARGETline (set toclaude-agents:<name>somattermost-channelknows which tmux pane to inject into) and thehooks.post_llm_callentry pointing at/app/hooks/hermes-mattermost-autopost.sh. - Add
agents/<name>/.env.examplelisting the secretsconfig.yamlreferences via${VAR}(Mattermost creds, model API keys). - In
entrypoint.shaddKIND[<name>]=hermesalongside theAGENTS/AGENT_ORDERentries. The runtime dispatcher will route tobuild_hermes_cmd. - Bind-mount the source project as in step 4 above.
The architecture details are in docs/tui-mcp-bridge.md.
| Host path (default) | Container path | Purpose |
|---|---|---|
~/.claude |
/home/node/.claude |
OAuth tokens, plugin marketplace, settings |
~/.claude.json |
/home/node/.claude.json |
User-level MCP server config |
~/.config/gh |
/host-gh:ro |
gh CLI auth (staged on entrypoint, not migrated in place) |
~/projects/health-agent |
/agents/health |
health agent source project |
~/projects/geordi-agent |
/agents/geordi |
geordi agent source project |
~/projects/marketing-agent |
/agents/marketing |
marketing agent source project |
~/projects/links-agent |
/agents/links |
links agent source project |
~/vaults/geordi |
/agents/geordi/vault |
Obsidian-style vault for geordi |
~/vaults/links |
/agents/links/vault |
Obsidian links/ folder |
~/projects/plnk/target/release/plnk |
/usr/local/bin/plnk:ro |
plnk Rust binary (replaces planka-cli) |
~/.local/venvs/scrapling (+ uv-managed Python) |
same paths | scrapling venv + interpreter |
~/.bun/install/global |
/opt/bun-global |
host bun globals (qmd + hoisted node_modules) |
~/.cache/ms-playwright |
/home/node/.cache/ms-playwright |
Chromium binaries for scrapling |
All defaults are env-var-driven; see docker-compose.yml.
entrypoint.sh maintains a KIND map; agents not listed default to claude:
declare -A KIND=(
[links]=hermes
)build_agent_cmd dispatches to build_claude_cmd or build_hermes_cmd accordingly. CC agents get auto-acceptance for first-run prompts (workspace trust, dev channels); Hermes agents skip that since it has no equivalent.
declare -A CHANNELS=(
[health]="server:mattermost"
[geordi]="server:mattermost server:heartbeat"
[marketing]="server:mattermost server:heartbeat server:heartbeat-keywords"
)Each entry produces one --dangerously-load-development-channels flag. Channels listed here MUST also be registered in the agent's .mcp.json. Ignored for Hermes agents (Hermes loads MCP servers directly from config.yaml).
declare -A MODELS=(
)Empty by default; add [<agent>]="<model-id>" to pin a non-default Claude model. Hermes agents pin their model in config.yaml instead.
heartbeat/ injects file contents into a CC agent's session on a schedule. One MCP process per agent runs N schedules, declared in a JSON file pointed at by HEARTBEAT_CONFIGS_FILE.
"heartbeat": {
"command": "/home/node/.bun/bin/bun",
"args": ["/app/heartbeat/server.ts"],
"env": {
"HEARTBEAT_CONFIGS_FILE": "/app/agents/<name>/heartbeats.json"
}
}Schedules file (agents/<name>/heartbeats.json):
[
{
"label": "create-content",
"file": "/agents/marketing/workspace/tasks/create-content.md",
"cron": "0 5 * * 1-5",
"autopost": true,
"marker": true
},
{
"label": "geordi",
"file": "/agents/geordi/HEARTBEAT.md",
"interval_minutes": 30,
"jitter_minutes": 2
}
]Each entry is one schedule. Set either cron (wall-clock aligned) or interval_minutes + jitter_minutes (drift across restarts). 5-field cron with *, ranges, lists, and */n steps. No L/W/#/? extensions. dom + dow are OR'd vixie-style when both are restricted.
Each tick emits <channel source="heartbeat" label="..." file="..." ts="..."> containing the file's content; the file content IS the prompt. label identifies which schedule fired.
The optional autopost / marker flags are read by hooks/mattermost-autopost.sh: autopost lets a heartbeat-triggered turn forward its assistant response to Mattermost (otherwise heartbeat turns stay silent); marker appends _(auto-forwarded)_ when the hook does. Per-schedule, not per-agent.
| Tool | When to use |
|---|---|
reply(channel_id, text) |
Respond to an inbound Mattermost message. |
post(text) |
Proactively post to the server's configured default channel. |
react(post_id, emoji) |
Add an emoji reaction without replying. Used by links. |
history(limit?) |
Read recent channel messages (oldest→newest) to recall earlier conversation after a context reset. |
search(query) |
Keyword-search this channel's history. |
reply and post reject empty/whitespace text — if you have nothing to say, stay silent. Set MATTERMOST_INJECT_TARGET=<session>:<window> on the MCP env to drive a non-CC TUI through tmux instead of CC channel notifications.
The host's ~/.claude.json is bind-mounted, so any user-scoped MCP servers (e.g. scrapling, qmd) defined there try to launch in every agent. To suppress a user-level server for one agent, add to that agent's .claude/settings.local.json:
{
"deniedMcpServers": [
{ "serverName": "qmd" },
{ "serverName": "scrapling" }
]
}The key is deniedMcpServers (not disabledMcpServers — that's not in CC's schema). Denylist takes precedence over allowlists.
Per-project plugin enablement lives in each agent's .claude/settings.local.json:
{
"enabledPlugins": {
"hindsight-memory@hindsight": true
}
}Plugin code comes from ~/.claude/plugins/ (already mounted via ~/.claude). Two extra steps to make plugins actually work in-container:
- Per-project install registration. Enabling in
settings.local.jsonisn't enough — the plugin must also be installed for the agent's project path. Attach to the agent's tmux window and run/plugins→ Install. This writes aprojectPathentry to~/.claude/plugins/installed_plugins.json. - Local services the plugin talks to. Plugin host configs often use
127.0.0.1which doesn't reach the container. Workaround: attach Janus to the service's Docker network (external: trueindocker-compose.yml) and bind-mount a janus-specific config file over the plugin's expected path. Seeagents/geordi/hindsight-claude-code.jsonfor a worked example.
These agents run unattended around the clock on a Windows/WSL2 Docker Desktop host. Most of the code outside the bridge exists because something broke in production. Each entry below lists what failed, how it showed up, and the change that handles it.
| Failure | Symptom | Fix |
|---|---|---|
| Half-dead Mattermost websocket. When Mattermost restarts, the client's socket can be left open with no TCP reset ever delivered. | The agent stops receiving messages indefinitely while every process still looks healthy. | mattermost.ts sends an application-level ping every 30s (MATTERMOST_PING_INTERVAL_MS). If a full interval passes with no frame back, the socket is torn down. A real close and a keepalive timeout share one loss handler that runs at most once per socket, so they can't both schedule a reconnect. Reconnects back off exponentially from 1s to 30s and reset after a successful open. |
| Messages sent during an outage. The websocket only carries live events. | Anything posted while the connection was down never reached the agent. | The last delivered post's position is saved to last-seen-<channel>.json. On every (re)connect the client fetches recent posts and delivers the ones it missed, oldest first. Live posts that arrive during the backfill are held back so ordering is kept. |
| Duplicate delivery. Hermes runs a separate MCP server process per tier, and each one subscribes to the same channel. Backfill and live events can also overlap. | Each process would inject the same message into the agent's pane, so it ran twice. | Every post goes through one deliver() function with a per-process id set. On the tmux-inject path, an O_EXCL marker file per post_id decides which process handles it: the first to create the file wins, and the rest skip. |
Agent dies mid-task on a Planka card. The card's in_flight lock is released only by events.complete, and the throttle gate reopens only on a Stop hook from the same agent. |
After a crash or OOM, that card got no further events, and once the gate closed no bundle for any card was dispatched until the server restarted. | The dispatcher sweeps on every tick. Locks older than PLANKA_CHANNEL_INFLIGHT_TIMEOUT_MS (15 min) are abandoned with an audit row, and orphaned locks with no bundle are cleared immediately. A synthetic Stop then reopens the gate. |
Early timer wakeups. WSL/Hyper-V clock instability can wake a setTimeout minutes before its deadline. |
A 5:00 cron heartbeat fired at 4:49, 4:59 and 5:00. Each early fire re-armed for the same minute, so the daily content job ran three times. | firedEarly() in heartbeat/cron.ts: a wake more than 5s early re-arms for the remaining time instead of firing. It's covered by a regression test built from the real timestamps. |
Stale bind mounts after a host crash. After a hard Windows/WSL crash, Docker Desktop loses the source of single-file bind mounts such as ~/.claude.json. |
Every agent container fails init with OCI runtime create failed … no such file or directory (exit 127). restart: unless-stopped retries the same broken mount indefinitely. |
scripts/boot-recovery.sh runs at @reboot. It waits for the Docker daemon, removes leftover containers (including compose's half-created <hash>_<service> ones), and runs up -d --force-recreate so the mount sources are resolved again. |
OAuth token rotation. Claude Code refreshes ~/.claude/.credentials.json by writing a new file and renaming it over the old one. A single-file bind mount keeps pointing at the old inode. |
Consumers that mount just that file keep an expired token, and their LLM calls fail without any clear error. | scripts/refresh-claude-creds.sh runs every minute from cron. It copies the file atomically into a dedicated directory, which consumers mount instead, and can optionally rsync it to another host. |
Everything in the failure-modes table above lives in about 1,100 lines of TypeScript. I wanted to know if those behaviors were actually written down, or just accreted in one codebase... so I had the bridge rebuilt from scratch in Go and in Roc, from the same written brief, and benchmarked all three.
They were. Both ports implement the same list: ping keepalive, one loss handler per socket, capped backoff, a cursor that never moves backwards, ordered backfill that holds live posts until it finishes, and the O_EXCL claim that stops two processes from delivering the same post. Each behavior has a test in both ports. Go's claim test races eight child processes against the same claim file. Roc's suite was mutation-checked. Switch off the half-dead branch and two tests against its simulated Mattermost fail. Make AlreadyExists count as a claim and the two-process end-to-end test delivers every post twice. The one real hole was somewhere else, and it was in the original.
The hole was in the Tailscale identity auth described above. That feature went into all three implementations at once, against a locked MATTERMOST_TSNET_* contract. It's optional and env-gated. With every TSNET variable unset, none of it loads and the server behaves exactly as before. When it's on, it does two things. Client auth: tailnet identity, not a bearer token, decides who may connect to the MCP endpoint. Service auth: the server checks that Mattermost really is the tailnet device you expect before it sends the bot token anywhere.
Roc's port was tested against a real tailscale 1.104.5 binary. On a node that has never joined a tailnet, serve reset fails with netMap is nil. The TypeScript reference ran that reset before up and treated any failure as fatal, so it could never start on a fresh node. Roc tolerates the failure only when the child tailscaled's LocalAPI reports no saved Serve config, and fails closed otherwise. The reference now tolerates it only when no prior state file exists, and fails closed otherwise (#7). The port found a bug in the original.
The resilience code ported cleanly. Where the three languages differ is what each one could do with Tailscale.
TypeScript (reference, mattermost-channel/)
npm has no Tailscale library worth using. tsnode doesn't exist on npm (404). tsnet is a single 1.0.0 release from 2018 with no repository. @nostr-agx/tailscale is current, but it only does outbound relay through a bundled sidecar, with no listener and no WhoIs (Tailscale's lookup for which user and device is behind a peer address). So the bridge runs a child tailscaled in userspace mode and talks to its LocalAPI over Bun's unix-socket fetch. Inbound MCP reaches a loopback backend through Tailscale Serve. Serve overwrites X-Forwarded-For with the real peer address, and the backend trusts that header. Outbound REST and websocket traffic goes through a loopback CONNECT proxy over LocalAPI's ts-dial. It works, but it adds two trust boundaries the code has to defend: the forwarded header, and anything else sharing the loopback interface.
Go (mattermost-mcp-go)
Go is the only one of the three with the real thing: tsnet embedded in the binary. Server.Listen hands the bridge the peer address directly, so there's no Serve route, no loopback backend, and no forwarded header to trust. Outbound, Server.Dial connects through the embedded node, and the bridge checks the remote address against the Mattermost device it verified and pinned at startup. No CONNECT proxy either. Both trust boundaries from the TypeScript version are gone.
The cost is size. Tailscale is compiled in even when every TSNET variable is unset, and the binary went from about 12 MB before auth to 36 MB after.
One more gap: the official MCP Go SDK had no way to send Claude Code's channel notifications (a non-standard MCP method), so a small decorator wraps its stdio transport and writes those frames through the same connection under a shared mutex.
Roc (mattermost-mcp-roc)
Roc 0.1.0 on basic-cli 0.28.1 gave the port HTTP with TLS, raw TCP with read timeouts, and an O_EXCL file open, which covers the claim. It had no websocket client, no regex engine, and no concurrency at all: no threads, no async, no select. roc-mcp-sdk exists, but its stdio server owns the main loop, and this bridge has to watch stdin, the socket and its timers from one place. So the port hand-rolls an RFC 6455 codec (about 250 lines) and the MCP layer (about 260), and turns each regex into a small tested function.
The resilience stack from the TypeScript mattermost.ts became a pure state machine: events in, commands out. One poll loop drives it. It waits up to 25 ms on stdin, then up to 25 ms on the socket, then ticks the timers. Even stdin needed a workaround. The platform can't read it with a timeout, so the loop reads through a spawned cat child. That poll loop is the design, and it's where Roc's 26 ms latency comes from.
The porting brief assumed basic-cli couldn't listen on a socket. It can: Tcp.listen! and UnixSocket.listen! both exist, so client auth landed in full. Like TypeScript, it runs a child tailscaled and talks to LocalAPI over a unix socket. The Streamable HTTP server is hand-rolled too. roc-mcp-sdk's version is a stub that crashes with "not implemented in this release."
Service auth is refused on purpose. The contract requires an HTTPS Mattermost. basic-cli has TLS only inside Http, never on a raw socket, so Roc can't open wss://. The brief's fallback was to verify the device through WhoIs, then connect normally, which for Roc means plain ws://. That's exactly the gap the contract exists to close. WhoIs checks the address DNS gave you at that moment. The socket opens later, to whatever DNS gives you then, and the bot token goes with it. A check that doesn't bind the connection is theater, so the port validates the setting and then refuses to start, with an error that says why.
Two platform changes would close both gaps. TLS over a raw byte stream (basic-cli already links rustls for Http) would unlock service auth. Real concurrency would retire the 25 ms poll.
The native binaries start 30–50× faster than Bun and sit 5–10× lighter in memory. Bun wins the moment something happens: a new post reaches the agent in 0.19 ms, against 1.4 ms for Go and 26 ms for Roc, which is that 25 ms poll loop. All three recover from a half-dead socket in 1.7–2.0 s. Go consistently reconnects about 300 ms later than the other two and is the slowest to backfill. Neither gap is explained yet.
| TypeScript (Bun) | Go | Roc | |
|---|---|---|---|
| Startup: spawn → initialize | 207 ms | 6.48 ms | 4.17 ms |
| Settled RSS (whole process tree) | 132.4 MiB | 24.6 MiB | 13.2 MiB |
| Connect + backfill of 50 posts | 103 ms | 158 ms | 58.5 ms |
| Post → notification (median of 100) | 0.19 ms | 1.40 ms | 26.3 ms |
| Half-dead recovery (500 ms ping) | 1714 ms | 2003 ms | 1706 ms |
| Delivery size | 175.7 MB* | 36.3 MB | 6.7 MB |
*Bun runtime + node_modules + source, not comparable to a single static binary. Roc's 6.7 MB carries no Tailscale. That runs in the child tailscaled. Go's 36.3 MB has it compiled in.
Medians of 7 interleaved runs on a single WSL2 host with no CPU pinning (indicative, not controlled), with Tailscale auth off: only the default stdio path was measured. Every subject passed every scenario in all 7 runs, and every outage post arrived in order. Methodology, raw samples and the full caveats are in mattermost-mcp-bench.
A small zero-dep Node CLI in cli/ wraps the common docker+tmux operations.
cd ./cli && npm link # adds `janus` to $PATH
# or run directly: ./cli/bin/janus <command>| Command | What it does |
|---|---|
janus list |
List agent windows across every running janus container (auto-discovered by image prefix). |
janus attach [agent] |
Attach to the tmux session, optionally jumping to <agent>. |
janus send <agent> <msg> |
Send a single-line message into <agent>'s prompt without attaching. |
janus help |
Show help. |
Planned: janus restart, janus update, janus status.
Inside an attached session: Ctrl-b d detaches (agents keep running); Ctrl-b n/p cycle windows; Ctrl-b 0..3 jump to window by index.
- OpenCode + Codex bridges —
opencode.mdhas the integration notes; only the post-turn hook is left to write (the input side is already runtime-agnostic). - Container ops — nightly auto-update, CLI stubs (
restart/update/status).
MIT — see LICENSE.
