Session Messaging
Session Messaging lets Command Code sessions running on the same machine find each other and exchange short messages, agent to agent.
When you run more than one session, say one on the API and one on the web app, each agent only knows its own corner. The API agent renames an endpoint and has no idea the web agent still calls it. So you become the relay: you copy a question out of one terminal, paste it into the other, wait, and carry the answer back.
In Command Code, your sessions can talk to each other.
You ask your agent in plain words. It finds the other session, sends it a short message, and tells you it's sent. The other agent reads it, answers, and the answer arrives back in your conversation. Neither of you switches terminals.
A message from another session is never your input. It arrives labelled as coming from another session, it can't approve permissions, and whether it needs your OK first follows that session's permission mode.
There's nothing to set up. Session Messaging is on by default and works between sessions on the same machine, under the same user. Everything travels through local files, never over the network.
Each example is something you type in one session. Your agent takes it from there, and the other agent answers in its own words. Messages are short text, so for anything long, both agents point at a file. They share your machine, so either one can open it.
Another session's agent treats a message as information, not as orders: it answers questions and tells its user about requests. Work starts in the session where you ask for it, and messages carry questions, findings and results between sessions.
You're about to rename an endpoint in the API, and the web app lives in another repo with its own session. Ask before you break it, not after:
The web agent searches its own repo and replies with the call sites. Your API agent now knows exactly what to update or keep backward-compatible, and you never opened the other terminal.
An agent missing one fact tends to make it up. If another session already has that fact, your agent can just ask:
The answer comes from the session that made the change, not from a guess built on old code.
You spent an hour in one session tracking down a flaky test, and another session owns the fix. Don't re-explain it from scratch:
The message stays short. The context lives in the file, where the other agent can read all of it.
Run one session per piece of work, each in its own worktree so their edits never collide:
Give each one its task in its own terminal, and tell it where to report. In auth:
In ui:
Each session works on its own branch, asks the other directly when it's blocked, and reports to lead when it finishes. You read the summaries in one place instead of checking three terminals.
A long backfill is running in another session, and you just need to know where it is:
A busy session sees the question at its next step and answers without dropping its work. In default mode, its terminal first asks its user to approve the message once (see Approval). For news that needs no answer, send an FYI, which waits until that session would stop anyway:
Before touching shared code, find out who else is in it:
list_sessions shows each session's folder, branch, last tool and current todo. That's a hint, not a list of the files it's editing, so the follow-up question is what settles it before it becomes a merge conflict.
Another session already holds the context you need for a review. In the pricing session:
The pricing agent reads the branch with git, since it's on the same machine, and the cart session gets the review as a message, ready to act on.
Both split work up, but they suit different jobs.
| Session Messaging | Sub-agents | |
|---|---|---|
| Who starts it | You, in separate terminals | Your agent, from inside one session |
| Context | Each session keeps its own long-running context | Each sub-agent starts fresh and returns a summary |
| Lives for | As long as you keep the session open | One task, then it's gone |
| Talks to | Any session on the machine, both ways | Only its parent |
| You can step in | Yes, each session is a full conversation you can type into | No, you see its result |
| Best for | Work that runs in parallel for hours across repos or worktrees, and needs the odd question or handoff | A focused job inside one task: search, review, a quick investigation |
If two pieces of work edit the same files all the time, keep them in one session. Messaging helps sessions coordinate; it doesn't merge their edits.
Your agent gets two tools. Both are always loaded:
| Tool | What it does |
|---|---|
list_sessions | Lists the other live sessions: name, branch, folder, and what each is doing (working, idle, waiting on its user). It shows sessions in this repo by default; scope: "all" shows every session on the machine. |
send_message | Sends a short message to one session by name. It returns right away, and any reply comes back later as a new message. |
The agent picks them up from plain requests like "tell the api session…", "ask the other terminal…", or "what are my other sessions doing?".
- Busy session: sees the message at its next step, without stopping its work.
- Idle session: starts a turn to read the message and answer it.
- FYI (sent with
expectReply: false): waits until the other session would stop anyway, so it never interrupts.
A message is only counted as delivered once the other agent actually has it in its context. If that session was cleared (/clear) first, you're told it wasn't delivered. If it was closed, the message stays in its inbox and is read when that session is resumed, unless it expires first (1 hour). No failure notice is sent in that case.
The receiving agent gets the message as a clearly marked block, never as something you typed:
- The header names the sender, its folder and its branch.
- The trust line tells the model this isn't you. A message can't approve a permission prompt or change a setting.
- The body is fenced. A line inside it that tries to open a fake header is relabelled
(quoted), so one session can't forge another message. - The reply call is spelled out, so even a small model answers the right message, once.
Messages show as quiet, dim rows, so you can follow the exchange without it taking over the conversation:
The receiving session shows Message received from @api, and its agent sums up what was asked in one line.
Sessions are addressed by name. Name them so they're easy to ask for:
Or rename one mid-session with /rename web. Without a name, a session uses its title, or else its folder name with a short id.
A message from another session is never treated as your input. It arrives under a header that says it's from another session and not from you. It can't approve permissions or change settings, and the receiving agent still asks you before any action its permission mode would ask about.
Whether a message waits for your approval follows the receiving session's permission mode:
| Receiving session's mode | Incoming messages |
|---|---|
| Default, Plan | Held until you approve |
| Auto-accept, Don't ask | Delivered right away |
| Bypass | Delivered right away only from another bypass session; otherwise held |
The bypass rule stops a stricter session from using a bypass session to run actions it isn't allowed to run itself.
When a message is held, you get a prompt with three choices:
- Yes: deliver this message.
- Yes, allow messages from @name this session: deliver it, and don't ask again for messages from that sender in this session.
- No: turn it away. The sender is told your user didn't allow it.
A prompt you don't answer within 5 minutes expires, and the sender is told the message wasn't delivered. A reply to a message your session sent never needs a second approval.
To override the permission-mode default, set sessionMessages.inbound in settings.json (user, project, or project-local):
| Value | Behavior |
|---|---|
"auto" (default) | Follow the permission mode, as in the table above |
"accept" | Deliver every message without asking |
"hold" | Ask before delivering, whatever the permission mode. Replies to your own messages, and senders you allowed for this session, still come straight in |
"refuse" | Turn every message away. Your session is still listed, but nobody can message it |
- Name your sessions.
cmd -n apiis easier to ask for than an auto-generated title. - Keep messages to a few lines and point at files. A path to a note, a diff or a log carries more than a long message, and it doesn't fill the other session's context.
- Use FYIs for news, questions for answers. An FYI never interrupts. A question gets answered at the other session's next step.
- Pick the right approval level. In default mode you approve each incoming message. For a pair of sessions you trust, choose "Yes, allow messages from @name this session" once.
- Know when to stay in one session. If two pieces of work edit the same files all the time, one session (or sub-agents) coordinates better than two sessions messaging each other.
| Guardrail | Limit |
|---|---|
| Message size | 8 KB. Keep messages to 2–3 lines and point to a file for anything longer |
| Back-and-forth | 4 hops per exchange, so two agents can't loop forever |
| Rate | 10 messages per minute from one sender |
| Repeats | Within one exchange, the same message to the same session within 5 minutes is turned away. Across new exchanges, the rate limit above is the backstop |
| Expiry | A message nobody reads within 1 hour expires |
| Queue | 20 waiting messages per session |
| Sub-agents | Only the main session can list or message sessions. Sub-agents report to their parent |
Your agent is instructed to write each message itself instead of forwarding your words, and not to ask another session to do anything its own permissions wouldn't allow. This is guidance to the model, not something Command Code enforces. The receiving session's own permission mode is what actually guards its actions.
Session Messaging is a built-in mod. To turn it off, add it to mods.disabled in ~/.commandcode/settings.json:
With it off, your agent loses both tools, your session stops publishing its record, and other sessions can't see or message it. To stay visible but never take messages, use "inbound": "refuse" instead.
Which sessions can receive messages?
Which sessions can receive messages?
Terminal sessions (cmd) can send and receive. Headless runs (cmd -p), the Desktop app and IDE extensions show up in list_sessions as "not messageable": they can't start a turn to read a message yet, so message a terminal session instead.
Will another session do work because my agent asked it to?
Will another session do work because my agent asked it to?
Not on its own. The other agent reads a message as information from another session, not as an instruction from its user. It answers questions and tells its user about requests. To have a session do the work, ask in that session, and tell it to message the other session when it's done. See Split a bigger task across sessions.
Why does it say "No running session matches …"?
Why does it say "No running session matches …"?
The name doesn't match a live session. Ask your agent to list sessions (scope: "all" includes other repos), or send by the id shown in the list. A session renamed with /rename is found by its new name. If two sessions share a name, rename one or send by id.
Why wasn't my message delivered?
Why wasn't my message delivered?
The row in your feed says why:
- "…'s user didn't allow the message": someone answered No, or that session uses
"inbound": "refuse". - "…'s user didn't respond": the approval prompt sat 5 minutes with no answer. Resend when someone is at that terminal.
- "…that session was cleared": it ran
/clear, so it's a new conversation. List sessions again and resend. - "…stopped the message to keep the conversation from looping": the exchange hit 4 hops, or one sender went over 10 messages a minute. Step in and tell one agent what to do next.
Nothing arrived and there was no error. Where did it go?
Nothing arrived and there was no error. Where did it go?
If the other session was closed, the message waits in its inbox and is read when that session is resumed, for up to an hour. If it's waiting for approval, your feed shows "(waiting for their approval)". Check the session is still listed by list_sessions.
What does "…has 20 messages waiting" mean?
What does "…has 20 messages waiting" mean?
The other session's inbox is full, usually because nobody there has approved its messages. Ask someone at that terminal to work through them.
Can a sub-agent send messages?
Can a sub-agent send messages?
No. Only the main session can list or message other sessions. A sub-agent reports to its parent, and the parent sends.
- Git Worktrees: give each session its own branch and directory, so parallel sessions never edit the same files.
- Permissions: the permission modes that decide whether incoming messages wait for approval.
- Agents: sub-agents, for focused work inside one session.
- Mods: Session Messaging is a built-in mod, turned on and off like any other.