Why I Built a Mailbox Instead of Injecting Messages Into a Running AI Agent
This is the third article in my product-engineering series. The previous article covered isolated Codex Desktop applications for custom model providers. This one focuses on communication between a human and a running coding agent.
The obvious way to send new guidance to a running agent is to inject another message into its active conversation.
I deliberately chose not to do that.
When an agent is implementing, testing, or reasoning through a task, a late instruction can interrupt a coherent plan, arrive during a tool operation, or blur the boundary between the task the agent accepted and the new context being introduced.
I wanted a different interaction model:
Leave guidance now. Let the agent read it at the next safe checkpoint.
That idea became CodexPigeon, an open-source desktop app and CLI that gives each Codex worktree a repository-local mailbox.
The human writes to an inbox. The agent reads it when control returns to a reasonable checkpoint, acknowledges it, and can write a reply or receipt. The application can observe Codex state, but it never starts, interrupts, steers, or injects into an active turn.
Why useful context often arrives late
Long-running software tasks rarely remain perfectly static.
While an agent is working, a human may notice that:
- one module must not be changed;
- a test environment has become unavailable;
- a release gate should be checked before publishing;
- another developer changed a related file;
- a destructive operation needs explicit approval;
- the final response should include a particular validation result.
The information is relevant, but the timing is awkward. Interrupting immediately may be unnecessary, while waiting for the whole turn to finish may be too late.
The product question became:
Can a human update the working context without treating the active chat stream as the only communication channel?
Why I rejected active-turn injection
Codex exposes methods that could conceptually be used to start, steer, interrupt, or inject items into conversations.
CodexPigeon explicitly refuses to use them.
Its App Server allowlist contains only read and discovery operations:
initialize
thread/list
thread/read
thread/loaded/list
hooks/list
Methods such as these are rejected by design:
turn/steer
turn/start
turn/interrupt
thread/inject_items
This does not mean active steering is universally wrong. It means CodexPigeon has a narrower contract.
It is a mailbox companion, not a second chat client.
That narrow contract creates useful properties:
- the app cannot silently alter an active conversation;
- the user can inspect the exact guidance written to disk;
- the agent consumes messages at explicit checkpoints;
- guidance remains attached to a repository and worktree;
- communication state stays visible outside the chat UI;
- the security review can focus on a small set of file and read-only process boundaries.
One thread, one worktree, one mailbox
Each selected worktree receives a .codex-mailbox directory:
.codex-mailbox/
INBOX.md
OUTBOX.md
RECEIPTS.md
STATE.json
HOOK_STATE.json
README.md
.gitignore
The core routing rule is:
1 thread = 1 worktree = 1 .codex-mailbox/
This prevents guidance for one task from leaking into another task in the same repository.
Git worktrees are already a strong task boundary. They represent separate working copies, branches, and contexts. The mailbox follows that existing boundary instead of creating a global message bus with complicated routing rules.
File ownership is the protocol boundary
The files are separated by writer:
| File | Writer | Purpose |
|---|---|---|
INBOX.md |
CodexPigeon app or CLI | Human guidance for the agent |
OUTBOX.md |
Codex agent | Human-readable replies |
RECEIPTS.md |
Codex agent | Acknowledgement and action status |
STATE.json |
App or CLI | Technical state and repeat scheduling |
HOOK_STATE.json |
Hook runtime | Reminder throttling and runtime state |
The app must never write to OUTBOX.md or RECEIPTS.md.
The agent must never write to INBOX.md.
This avoids two processes editing the same logical record and makes provenance easy to understand. When something appears in the inbox, it came from the human-side tool. When a receipt appears, it came from the agent-side workflow.
A boundary simple enough to explain in one table is much easier to audit than a hidden shared database with implicit writers.
Messages stay human-readable
I chose Markdown because the protocol should remain inspectable with normal repository tools.
An inbox message looks like this:
## msg_20260520T153000_01HY4YF9F0Q2A3N4B5C6D7E8F9
from: human
created_at: 2026-05-20T15:30:00.000Z
priority: normal
status: unread
scope: current_task
Message:
Do not touch the auth module during the billing refactor.
If auth changes are needed, ask in OUTBOX.md first.
The message ID combines a readable timestamp with a ULID suffix. That keeps IDs sortable while avoiding collisions during rapid writes.
The app treats inbox entries as append-only. It does not rewrite an old message to mark it read.
Instead, the agent writes a receipt.
## receipt_20260520T153245_01HY4YJ4Q8E2GHK2Z6MBWR6A1R
message_id: msg_20260520T153000_01HY4YF9F0Q2A3N4B5C6D7E8F9
seen_at: 2026-05-20T15:32:45.000Z
decision: accepted
action_status: applied
summary: Updated the plan to avoid auth module changes.
The UI derives status from receipts rather than mutating the human-authored message.
Possible states include:
- unseen;
- accepted;
- rejected;
- deferred;
- needs confirmation;
- applied;
- blocked;
- not applicable.
This produces an audit trail instead of hiding state transitions inside a mutable record.
Safe checkpoints, not constant polling by the agent
Installed project instructions ask the agent to check the mailbox:
- before a major architectural decision;
- after a meaningful implementation step;
- after tests or a long shell command;
- before the final response.
Hooks provide reminders at session start, after tool use, and before stopping, but hooks are not the only boundary. The design depends on:
- project instructions;
- file ownership;
- append-only human messages;
- agent-authored receipts;
- explicit safe checkpoints.
A long-running blocking shell command still cannot consume a new message until control returns. The mailbox does not pretend to create real-time interruption where none exists.
Installation preserves the existing workspace
CodexPigeon installs a managed block into AGENTS.md, merges its hook groups into .codex/hooks.json, copies a small hook runtime, and creates the mailbox files.
It does not replace unrelated project instructions or hooks.
Only content between managed markers is inserted or updated:
<!-- CODEXPIGEON_MAILBOX_START -->
<!-- CODEXPIGEON_MAILBOX_END -->
This makes repeated installation idempotent and avoids taking ownership of files that belong to the repository.
Repeated guidance still uses normal inbox messages
The app can optionally schedule repeated reminders.
A repeat is stored in STATE.json. When it becomes due, the desktop process or explicit CLI runner appends a new, ordinary inbox message through the same validation and locking path as a manual message.
It does not call an active chat API.
This keeps the protocol consistent: automated guidance is still guidance, and the agent processes it at a checkpoint.
What I learned
1. More immediate is not always more controllable
Active injection can be powerful, but asynchronous delivery can be easier to inspect, audit, and reason about.
2. Existing repository boundaries are valuable
Worktrees already separate task context. Reusing them simplified routing and reduced the risk of cross-task leakage.
3. File ownership can be a strong protocol primitive
Clear writers, append-only behavior, and visible provenance can provide a useful security boundary without a complex service.
4. Human-readable protocols improve debugging
A user can open the mailbox with any editor, inspect what happened, and understand the state without a proprietary viewer.
5. Honest limitations build trust
The mailbox cannot interrupt a blocking command or force an agent to read at an arbitrary moment. It offers checkpoint-based coordination, not real-time control.
Project links
- GitHub: https://github.com/ademisler/codexpigeon
- License: MIT
- Current status: working local MVP for macOS and Linux development
The next article covers CodexControl: a local-first quota monitor and account switcher, and why changing accounts on Windows turned out to require much more than copying auth.json.
Comments
Join the discussionNo comments yet. Be the first to comment.
