NAME
App::teai::Cookbook - recipes for teai
A hub and the first session
Start a hub and exchange mail between two inboxes in one shell. Use NATS with JetStream as described in "CONFIGURATION" in App::teai.
Copy the hub config. Replace the paths and passwords in the copy. Set listen to "127.0.0.1:4222" for local use. Put the TLS certificate and key at cert_file and key_file. The certificate must cover the address in the client URL, here 127.0.0.1.
install -d -m 700 "$HOME/.config/teai"
install -m 600 eg/nats.conf "$HOME/.config/teai/nats.conf"
Start the hub in another terminal.
nats-server -c "$HOME/.config/teai/nats.conf"
For a systemd user service, copy the unit and set ExecStart's executable to the absolute path from command -v nats-server.
install -Dm 644 eg/teai-hub.service \
"$HOME/.config/systemd/user/teai-hub.service"
systemctl --user daemon-reload
systemctl --user enable --now teai-hub.service
To keep the service up without a login, run loginctl enable-linger "$USER".
Copy the sample client config with mode 0600. A nonempty TEAI_CONFIG gives the file to edit. Otherwise use $XDG_CONFIG_HOME/teai/config if XDG_CONFIG_HOME is absolute, or the home default shown here.
install -m 600 eg/teai.config "$HOME/.config/teai/config"
Edit the copy. Use the hub user's password and the CA that signed the server certificate. For a self-signed certificate, use the certificate itself as the CA file.
url = tls://127.0.0.1:4222
user = hub
password = replace-with-the-hub-password
tls_ca = /home/me/.config/teai/hub-ca.pem
Run teai init as a hub operator. Look for stream TEAI ready and the bucket readiness lines. Then send, read and reply.
teai init
eval "$(teai join --agent shell)"
peer=$(teai session new --agent shell)
seq=$(teai send "session:$peer" --thread hello 'Say hello')
TEAI_SESSION="$peer" teai inbox
TEAI_SESSION="$peer" teai reply "$seq" 'Hello'
teai inbox --re "$seq"
The first inbox call prints Say hello. The second prints Hello. If the hub refuses the connection, check the URL, CA and password. If a bucket is missing, run teai init on that hub. See "Connection and setup" in App::teai for connection errors.
A second host
Bind the hub to an address reachable from the second host and allow TCP port 4222 from that host. Use a certificate that covers the name or IP in the remote URL. Give each host its own NATS user. Anyone with hub credentials can act as any session. See "SECURITY" in App::teai.
On the second host, copy the CA file and set its client config as in "A hub and the first session". Use that host's login.
url = tls://hub.example:4222
user = laptop
password = replace-with-the-laptop-password
tls_ca = /home/me/.config/teai/hub-ca.pem
For a hub that uses NATS credentials, omit user and password and use a private credentials file instead.
export TEAI_CREDS="$HOME/.config/teai/laptop.creds"
Join from the second host, print the session ID and start a watcher.
eval "$(teai join)"
printf '%s\n' "$TEAI_SESSION"
teai wait --timeout 60
In a joined shell on the first host, check that teai session list shows the inbox and teai who shows wait and the second host's label. Send a test message with the printed ID in place of ID.
teai send session:ID 'Hello from the first host'
Expect teai: 1 new message - call teai_inbox or run teai inbox on the second host, then run teai inbox there to read the body. teai wait exits 1 if 60 seconds pass without a notice.
If the name lookup stalls, use a name in /etc/hosts or a numeric address covered by the certificate. If TLS fails, check that the CA and URL match the hub certificate.
Connecting an agent CLI
Put eg/teai-agent on PATH and register teai mcp as below. Start each interactive session with teai-agent CLI [ARGS...]. It joins a fresh inbox and prints teai session ID on stderr. An unknown CLI exits 2 with the usage below. A missing executable exits 127 with teai-agent: NAME not found on PATH.
usage: teai-agent CLI [ARGS...] CLI: claude codex agy muse kimi grok
Ask the agent to call teai_whoami. Its session should match the launcher's ID. Replace ID with that ID and send from another shell joined to the same hub.
teai send session:ID 'Hello from the shell'
Have the agent call teai_inbox and check for Hello from the shell in the message body. If a tool says no teai session: start the CLI with teai-agent, check TEAI_SESSION forwarding. Keep the ID out of the MCP registration. teai exec strips TEAI_* for batch members so their default MCP server offers no tools. Codex and Muse filter the server's environment. The other CLIs pass it through.
The headless check is xt/mcp-clients.t. Observed output cutoffs are about 10000 characters in agy, 19.5 KB in Grok and 50000 characters in Claude. See "COMMANDS" in App::teai under mcp for tool limits and paging.
Copy eg/teai-skill.md to the path for your CLI below, or add the short eg/AGENTS.md snippet to its instructions.
claude
Register in ~/.claude.json and launch.
claude mcp add -s user teai -- teai mcp
teai-agent claude
For per-run registration, the checked setup uses --strict-mcp-config, which limits Claude to the specified server.
teai-agent claude --strict-mcp-config --mcp-config \
'{"mcpServers":{"teai":{"type":"stdio","command":"teai","args":["mcp"]}}}'
Skill path ~/.claude/skills/teai/SKILL.md.
codex
Set this in ~/.codex/config.toml, or set individual keys with -c mcp_servers.teai.KEY=VALUE. approve runs the tools without asking. Forward TEAI_SESSION, XDG_RUNTIME_DIR for the reader lock, and any hub overrides such as TEAI_URL or TEAI_CONFIG.
[mcp_servers.teai]
command = "teai"
args = ["mcp"]
env_vars = ["TEAI_SESSION", "XDG_RUNTIME_DIR"]
default_tools_approval_mode = "approve"
teai-agent codex replaces env_vars with TEAI_SESSION, XDG_RUNTIME_DIR and all other set TEAI_* variables via -c. Any -c gives this TUI its own embedded server. With no -c, TUIs share the first TUI's app-server. teai_whoami can show that other session's ID, and the server survives /quit.
Skill path ~/.codex/skills/teai/SKILL.md. Add to ~/.codex/AGENTS.md.
When TEAI_SESSION is set or teai tools are available, use the teai skill.
agy
Register in ~/.gemini/config/mcp_config.json and launch.
agy mcp add teai -- teai mcp
teai-agent agy
Headless runs need --settings '{"permissions":{"allow":["mcp(*)"]}}'. Use MCP tools for mail. The shell sandbox blocks hub access, and VAR=val breaks shell auto-approval. Subagents share the parent's server and inbox.
Skill path ~/.gemini/config/skills/teai/SKILL.md.
grok
Set this in ~/.grok/config.toml. This entry takes precedence over teai imported from ~/.claude.json.
[mcp_servers.teai]
command = "teai"
args = ["mcp"]
The read-only sandbox blocks the hub and reader lock. Create the runtime directory before launch and add a profile in ~/.grok/sandbox.toml. restrict_network = false also opens the network for Grok's tools.
runtime=${XDG_RUNTIME_DIR:+$XDG_RUNTIME_DIR/teai}
runtime=${runtime:-/tmp/teai-$(id -u)}
mkdir -m 700 -p "$runtime"
grep -q '^\[profiles.teai\]' ~/.grok/sandbox.toml 2>/dev/null || \
cat >> ~/.grok/sandbox.toml <<EOT
[profiles.teai]
extends = "read-only"
restrict_network = false
read_write = ["$runtime"]
EOT
teai-agent grok --sandbox teai
Headless runs need --allow 'MCPTool(teai__TOOL)' per tool. Grok imports the skill at ~/.claude/skills/teai/SKILL.md. Subagents share the parent's server and inbox.
muse
Register in ~/.config/muse/settings.json, then add the env field below to mcpServers.teai. --env-var does not forward variables. Add any other required TEAI_* variables the same way. An unset ${VAR} without :- disables every MCP server. The check covers the case where both variables are set.
muse mcp add teai --user -- teai mcp
"env": {
"TEAI_SESSION": "${TEAI_SESSION:-}",
"XDG_RUNTIME_DIR": "${XDG_RUNTIME_DIR:-}"
}
In a trusted workspace, accept the prompt or run teai-agent muse --trust-workspace to enable the tools. Muse imports the skill at ~/.claude/skills/teai/SKILL.md.
kimi
Registration is per run. teai-agent kimi adds the arguments below and uses --preset teai if ~/.config/kimi/presets/teai.txt exists. Copy the skill there without its front matter.
kimi --mcp 'teai=teai mcp' --mcp-tools \
teai:teai_whoami,teai_send,teai_ask,teai_reply,teai_inbox,teai_message
Only named tools are callable. teai_whoami lists all tools on the server, including omitted ones. Global ~/.config/kimi/mcp.json registration is unverified.
Waking idle sessions
Start the CLI with "Connecting an agent CLI", let it go idle and send a message to its session ID from another shell. The wake should prompt the agent to read its inbox. Ask it to print the mail body when testing (Grok and Codex can interpret "reply" as teai_reply). teai wait only announces mail and shares a cursor with the Claude hook. See "COMMANDS" in App::teai under wait and hook for exits and limits.
Idle wakes checked 2026-11-26. The agy, grok and codex checks on 2026-11-27 sent two messages each (xt/wake-clis.t).
Claude hook
The Claude hook runs on Linux only. Merge hooks from eg/claude-settings.json into ~/.claude/settings.json. Remove teai-claude-hook entries. Keep the synchronous teai hook reset first in SessionStart so unread mail from an earlier context can be announced again. Mail is announced at the next prompt or wakes an idle session. The async waiter's lifetime is its timeout (86400 seconds in the sample). If every turn wakes, check that teai hook is accepted. Claude treats an exit 2 as a wake.
agy background wait
Allow MCP and the wait command. --settings replaces the allow list, so omit it if mcp(*) and the commands are already allowed.
teai-agent agy --settings \
'{"permissions":{"allow":["mcp(teai/*)","command(teai *)"]}}'
Have the agent run teai wait --timeout 300 in the background with BypassSandbox, then end the turn. One run wakes it once. On wake, have it call teai_inbox and start the waiter again. In the agy 1.5.18 check, the command started about 20 seconds after it was shown, and the inbox read followed about 7 seconds after mail.
Grok monitor
teai-agent grok --allow 'Bash(teai *)'
Have the agent run a persistent monitor on teai wait --follow and end the turn. Each output line prompts teai__teai_inbox. One monitor handles repeated wakes for up to 10 hours. In the grok 1.0.92 checks it handled the second mail both times, with an inbox read about 7.3 seconds after sending.
Codex wake helper
Put eg/teai-codex-wake on PATH. Get the session ID from teai_whoami and the thread UUID from $CODEX_THREAD_ID. Run the launcher alongside the idle TUI, replacing ID and UUID.
TEAI_SESSION=ID teai-codex-wake --thread UUID
The wrapper watches teai wait --follow and runs this per wake. A notice during a run queues one more run.
codex queue --thread UUID --message 'teai: new mail - call teai_inbox' --resume
In embedded mode, /quit ends the MCP server. The wrapper polls teai session list --json every 10 seconds and exits 0 after it sees mcp and then two consecutive misses. Presence expires 120 seconds after its last refresh, so a hub outage can hide it. teai-codex-wake: cannot read presence (teai session list); keeps running means the poll failed. The wrapper reports it once and keeps watching.
With the shared daemon, add --pid PID to stop when the TUI exits. Keep TEAI_SESSION=ID on the helper command so its waiter has a session. Find the TUI PID outside Codex with pgrep -a codex. Check that it belongs to the TUI, as a launcher may also appear and exit early. The sandbox has its own PIDs. Match the printed UUID in ~/.codex/sessions/**/rollout-*-<uuid>.jsonl to find the rollout for this TUI. The shell runs bash -lc, so it may miss PATH set in .bashrc. MCP tools still work. If the wrapper outlives the TUI, it can advance the cursor. To read the queued mail, run codex resume UUID and call teai_inbox.
teai-codex-wake: no process PID exits 2. A failed teai wait keeps its stderr and returns its status after any queued wake. teai-codex-wake: codex queue timed out means the queue run hit 30 seconds. The wrapper sends TERM, then KILL after 2 seconds. Other queue failures print teai-codex-wake: codex queue exited N. INT, TERM and HUP stop the wrapper with exit 0 (an inherited ignored HUP stays ignored). Cleanup sends TERM, then KILL after 2 seconds, to its children and the queue process group. KILL or PIPE can leave children running. In the codex 0.172.0 check, embedded --resume warned and ran the turn (9 seconds). The daemon resumed directly (14 seconds).
muse and kimi
These CLIs have no idle wake. Read the inbox at the start and end of a task. Use teai wait --timeout S in the foreground to wait for a reply.
A consilium
Send one brief to several batch members and collect their replies. Run from a configured project, or pass --project P to each round command. The round lead needs a session. A project lead lease is optional.
Join as the round lead and make an inbox for each member.
eval "$(teai join)" claude_id=$(teai session new --agent claude) kimi_id=$(teai session new --agent kimi)Use a fresh thread and a self-contained brief. Each output line gives the member name, session ID and brief sequence (SEQ). Continue when the final check prints
Both briefs have a SEQ.round=C-r1 sent=$(printf '%s\n' 'List two ways to make a CLI manual easier to scan.' | teai round start --thread "$round" "claude=$claude_id" "kimi=$kimi_id") printf '%s\n' "$sent" claude_seq=$(printf '%s\n' "$sent" | awk '$1 == "claude" {print $3}') kimi_seq=$(printf '%s\n' "$sent" | awk '$1 == "kimi" {print $3}') test -n "$claude_seq" && test -n "$kimi_seq" && printf '%s\n' 'Both briefs have a SEQ'Run one
execper member to pass its brief on stdin and collect stdout. Use the member's latestbriefsentry inteai round status "$round" --jsonafter a resend. For agy, set--timeout 1560onteai execbefore--.teai exec --session "$claude_id" --seq "$claude_seq" --timeout 1800 -- \ claude -p --restricted --strict-mcp-config --tools Read,Grep,Glob & claude_run=$! teai exec --session "$kimi_id" --seq "$kimi_seq" --timeout 1800 -- \ env KIMI_LAST_SESSION=0 kimi -e max --final --tools read_file \ 'Answer the brief given on stdin.' & kimi_run=$!Collect one reply per member. Use
--ackas the lead to clear those replies from its inbox. If a member has no reply yet, collect later or runteai round resend "$round" kimiand serve the new SEQ. See "COMMANDS" in App::teai underroundandexecfor exits.teai round collect "$round" --wait 1800 --ack teai log --thread "$round" --jsonWait for the runners to exit, then remove their inboxes.
wait "$claude_run" "$kimi_run" teai session rm "$claude_id" "$kimi_id"
Other member commands
Use one of these in place of the command after -- in step 3. In the standalone examples, set id and seq to the member's session ID and brief SEQ. See "SECURITY" in App::teai for isolation.
- codex
-
Omit
-c mcp_servers.teai.enabled=falseif ~/.codex/config.toml has no[mcp_servers.teai]entry, or Codex reportsinvalid transport in mcp_servers.teai.codex exec -s read-only --skip-git-repo-check --ephemeral \ --disable apps --disable browser_use --disable computer_use \ -c web_search='"disabled"' -c mcp_servers.teai.enabled=false - - agy
-
Headless agy auto-approves tools. eg/agy-member.sh uses
bwrapwith a read-only root, private /tmp and scratch home. It hides ~/.config/teai and, if present, $XDG_RUNTIME_DIR/teai. It shares the host network and can read credentials stored outside the masked paths. Its--print-timeoutis 25m (1500 seconds).eg/agy-member.sh - grok
-
env GROK_CLAUDE_AGENTS_ENABLED=false GROK_CLAUDE_RULES_ENABLED=false \ GROK_CLAUDE_SKILLS_ENABLED=false GROK_CLAUDE_MCPS_ENABLED=false \ GROK_CLAUDE_HOOKS_ENABLED=false \ grok -m grok-4.7 --reasoning-effort xhigh --sandbox read-only \ --disable-web-search --tools read_file,grep,list_dir \ --no-subagents --no-memory --prompt-file /dev/stdin - muse
-
Muse takes a prompt argument or a regular file, so spool the brief.
sh -c ' f=$(mktemp) || exit 1 cat > "$f" env MUSE_NO_AUTO_UPDATE=1 muse exec --model muse-spark-1.3 \ --reasoning-effort xhigh --no-foreign-personal-context \ --disable-shell --disable-write --disable-web-tools \ --approval-mode never --prompt-file "$f" rc=$? rm -f "$f" exit $rc '
A member on another host
Run teai exec on the lead's host. Use SSH to run the CLI on the other host, which needs no teai config or binary. SSH joins command arguments into one string. Put the member command in an executable script, member.sh in the remote login directory.
#!/bin/sh
exec codex exec -s read-only --skip-git-repo-check \
--disable apps --disable browser_use --disable computer_use \
-c web_search='"disabled"' -
Set up the SSH key and known host first. BatchMode=yes fails promptly if SSH needs a password, passphrase or host key confirmation. An interactive prompt from the background command can stop it with SIGTTIN.
teai exec --session "$id" --seq "$seq" -- ssh -o BatchMode=yes host ./member.sh
Use teai round collect to see the remote reply, just like a local one.
Member checks
On 2026-11-25, all six members returned ok and exited 0 via teai exec at lowest effort on Reply with exactly: ok. The check omitted --ephemeral, -c mcp_servers.teai.enabled=false and the agy runtime-directory mask.
codex codex-cli 0.172.0
muse Muse Code 1.4.25
agy agy 1.5.16
grok grok 1.0.92
kimi kimi harness 97bd649
claude Claude Code 2.1.332
In the write probe, Claude had no shell or write tool. With eg/agy-member.sh, touch ran in private /tmp and writing in the working directory failed with read-only file system. A scratch home and read-only tool allow list alone let agy do both.
A project with a lead and roles
Give project P a lead and a reviewer. In the lead's terminal, join and keep the session live with a watcher.
eval "$(teai join --project P --lead)"
teai wait --follow &
lead_watcher=$!
In the reviewer's terminal, join with a role and start a watcher.
eval "$(teai join --project P --role R)"
teai wait --follow &
watcher=$!
From the lead's terminal, check for lead=P and the reviewer's role=R and live=wait. Send to all live peers, then to role R.
teai who --project P
teai send live:P 'Can anyone review this?'
teai send role:P/R 'Please check the tests.'
If a send reports teai: no live session for ADDRESS, check teai who --project P and start the recipient's watcher or MCP server. Have the reviewer read the inbox and send to the project mailbox, where mail can wait for a lead.
teai inbox
kill "$watcher"
teai send project:P 'The tests passed.'
As lead, use the #SEQ in the message header from teai inbox --project P. Pass its digits to teai reply. A plain teai inbox shows the notice with its own header number.
teai inbox --project P
teai reply SEQ 'Thanks for the review.'
To take over as the reviewer, run teai session lead P in that terminal. Add --take to replace a live lead.
teai session lead P --take
teai who --project P
Check for lead=P on the new session. Stop the old lead's watcher from its terminal with kill "$lead_watcher". See "Project mail" in App::teai for mailbox recovery and "COMMANDS" in App::teai under join and session lead for takeover rules and exits.
The dashboard
Run this from a configured project or name the project explicitly.
teai dash --project P
Open the printed URL on the same machine. The dashboard listens only on loopback. Keep the URL private because it grants operator access. Sessions shows inboxes, presence and leads. Use Compose and Inbox for operator mail, Threads for conversations and open asks, and Rounds for member replies. Use New round to send a brief. Stop with Ctrl-C. If startup reports missing Feersum or a bad listen address, see "COMMANDS" in App::teai under dash and "SECURITY" in App::teai.
Test runs
Run tests from the checkout under the repository's shared lock.
perl -Ilib bin/teai lock --wait 900 -- prove -l t/00-load.t
eg/test-lock.sh uses the same lock and needs util-linux flock.
WAIT=900 eg/test-lock.sh prove -l t/00-load.t
Look for the test's result line. On teai: test lock busy, or exit 4 from the shell helper before tests start, retry or allow more time. See "TESTING" in App::teai for test settings and "COMMANDS" in App::teai under lock for lock options.
AUTHOR
vividsnow
LICENSE
This is free software; you can redistribute it and/or modify it under the same terms as Perl itself.