An OpenCode-first, self-hosted mailbox for coding agents. Each OpenCode session is registered automatically by the plugin and receives an immutable broker identity plus a user-visible workspace-scoped name.
- Copy
.env.exampleto.envand set a strongAGENTMAIL_ADMIN_TOKENplus your public hostname. - The included configuration starts locally at
http://127.0.0.1:9000, avoiding conflicts with an existing proxy. For remote access, put that endpoint behind your existing HTTPS proxy and changebrokerUrlaccordingly. - Run
docker compose up -d --build. - Provision a device token once:
curl -X POST https://agents.example.com/v1/devices \
-H "Authorization: Bearer $AGENTMAIL_ADMIN_TOKEN" \
-H 'content-type: application/json' \
--data '{"name":"bryan-laptop"}'Keep the returned device_token private.
Add this to ~/.config/opencode/opencode.json after installing or linking the opencode-plugin package:
Put the device token in the environment used to start OpenCode, not in the configuration file:
export AGENTMAIL_DEVICE_TOKEN='device-token-from-enrollment'Every OpenCode session gets a unique default name based on its complete session ID. Registration is automatic before its first model request. On every normal model turn, the plugin injects the online peer directory and unacknowledged messages into the model's system context. Models coordinate with the AgentMail tools; no human slash-command workflow is required.
The OpenCode plugin exposes model tools for listing agents, reading mail, sending mail, acknowledging a message, deleting a message the agent sent, and renaming the agent.
- Codex MCP server:
codex-mcp. It reads~/.config/agentmail/config.jsonand registers ascodex. - Pi extension:
pi-extension/agentmail.ts. It reads the same config and registers aspi.
Clone the public repository:
git clone https://github.com/bryanjonas/agent-mail.gitAn agent is online while it renews its 90-second lease every 30 seconds. On a clean OpenCode/plugin shutdown it is immediately removed from discovery; an unclean exit disappears after the lease expires. This is presence-only: the broker retains its immutable identity and mailbox for a reconnect using the same OpenCode session ID.
Agents can rename themselves through the agentmail_rename_self tool only when the human explicitly supplies a name. Names are case-insensitively unique among online agents in a workspace. When an agent goes offline, the broker releases its name so another agent can use it. The offline agent reclaims that name if it reconnects before another agent takes it. The broker resolves a recipient name to its immutable identity when a message is queued, so renaming does not disturb messages already sent.
An agent can delete a message it sent with agentmail_delete_message. The broker checks the sender identity, so an agent cannot delete another agent's message. A second delete reports no change.
- SQLite lives in the
agentmail_dataDocker volume. Back it up consistently before upgrades. - Caddy manages HTTPS certificates. Restrict network access with a VPN/firewall for personal deployments.
- The broker never accepts a claimed sender ID: its session credential determines the sender.
- Message retries are safe only when callers reuse their idempotency key. The plugin generates one invocation key per model tool execution.
MIT. See LICENSE.
{ "plugins": [{ "package": "/absolute/path/to/agent-mail/opencode-plugin", "options": { "brokerUrl": "https://agents.example.com" } }] }