2026-01-02 01:19:22 +01:00
---
summary: "iMessage support via imsg (JSON-RPC over stdio), setup, and chat_id routing"
read_when:
- Setting up iMessage support
- Debugging iMessage send/receive
---
# iMessage (imsg)
2026-01-07 00:25:16 +01:00
Status: external CLI integration. Gateway spawns `imsg rpc` (JSON-RPC over stdio).
2026-01-02 01:19:22 +01:00
2026-01-11 02:40:28 +01:00
## Quick setup (beginner)
1) Ensure Messages is signed in on this Mac.
2) Install `imsg` :
- `brew install steipete/tap/imsg`
3) Configure Clawdbot with `imessage.cliPath` and `imessage.dbPath` .
4) Start the gateway and approve any macOS prompts (Automation + Full Disk Access).
Minimal config:
```json5
{
imessage: {
enabled: true,
cliPath: "/usr/local/bin/imsg",
dbPath: "/Users/< you > /Library/Messages/chat.db"
}
}
```
2026-01-07 00:25:16 +01:00
## What it is
- iMessage provider backed by `imsg` on macOS.
- Deterministic routing: replies always go back to iMessage.
2026-01-11 02:52:50 +00:00
- DMs share the agent's main session; groups are isolated (`agent:<agentId>:imessage:group:<chat_id>` ).
2026-01-08 16:24:28 -06:00
- If a multi-participant thread arrives with `is_group=false` , you can still isolate it by `chat_id` using `imessage.groups` (see “Group-ish threads” below).
2026-01-06 18:25:52 +00:00
2026-01-02 01:19:22 +01:00
## Requirements
- macOS with Messages signed in.
2026-01-07 00:25:16 +01:00
- Full Disk Access for Clawdbot + `imsg` (Messages DB access).
- Automation permission when sending.
2026-01-08 06:25:01 +01:00
- `imessage.cliPath` can point to any command that proxies stdin/stdout (for example, a wrapper script that SSHes to another Mac and runs `imsg rpc` ).
2026-01-02 01:19:22 +01:00
2026-01-07 00:25:16 +01:00
## Setup (fast path)
1) Ensure Messages is signed in on this Mac.
2) Configure iMessage and start the gateway.
2026-01-02 01:19:22 +01:00
2026-01-08 16:24:28 -06:00
### Dedicated bot macOS user (for isolated identity)
If you want the bot to send from a **separate iMessage identity** (and keep your personal Messages clean), use a dedicated Apple ID + a dedicated macOS user.
1) Create a dedicated Apple ID (example: `my-cool-bot@icloud.com` ).
- Apple may require a phone number for verification / 2FA.
2) Create a macOS user (example: `clawdshome` ) and sign into it.
3) Open Messages in that macOS user and sign into iMessage using the bot Apple ID.
4) Enable Remote Login (System Settings → General → Sharing → Remote Login).
5) Install `imsg` :
- `brew install steipete/tap/imsg`
6) Set up SSH so `ssh <bot-macos-user>@localhost true` works without a password.
7) Point `imessage.accounts.bot.cliPath` at an SSH wrapper that runs `imsg` as the bot user.
2026-01-08 01:18:37 +01:00
2026-01-08 16:24:28 -06:00
First-run note: sending/receiving may require GUI approvals (Automation + Full Disk Access) in the *bot macOS user* . If `imsg rpc` looks stuck or exits, log into that user (Screen Sharing helps), run a one-time `imsg chats --limit 1` / `imsg send ...` , approve prompts, then retry.
Example wrapper (`chmod +x` ). Replace `<bot-macos-user>` with your actual macOS username:
2026-01-08 01:18:37 +01:00
```bash
#!/usr/bin/env bash
2026-01-08 16:24:28 -06:00
set -euo pipefail
2026-01-08 01:18:37 +01:00
2026-01-08 16:24:28 -06:00
# Run an interactive SSH once first to accept host keys:
# ssh <bot-macos-user>@localhost true
exec /usr/bin/ssh -o BatchMode=yes -o ConnectTimeout=5 -T < bot-macos-user > @localhost \
"/usr/local/bin/imsg" "$@"
```
2026-01-08 01:18:37 +01:00
2026-01-08 16:24:28 -06:00
Example config:
2026-01-02 01:19:22 +01:00
```json5
{
imessage: {
enabled: true,
2026-01-08 16:24:28 -06:00
accounts: {
bot: {
name: "Bot",
enabled: true,
cliPath: "/path/to/imsg-bot",
dbPath: "/Users/< bot-macos-user > /Library/Messages/chat.db"
}
}
2026-01-02 01:19:22 +01:00
}
}
```
2026-01-08 16:24:28 -06:00
For single-account setups, use flat options (`imessage.cliPath` , `imessage.dbPath` ) instead of the `accounts` map.
### Remote/SSH variant (optional)
If you want iMessage on another Mac, set `imessage.cliPath` to a wrapper that runs `imsg` on the remote macOS host over SSH. Clawdbot only needs stdio.
Example wrapper:
```bash
#!/usr/bin/env bash
exec ssh -T mac-mini imsg "$@"
```
Multi-account support: use `imessage.accounts` with per-account config and optional `name` . See [`gateway/configuration` ](/gateway/configuration#telegramaccounts--discordaccounts--slackaccounts--signalaccounts--imessageaccounts ) for the shared pattern. Don’ t commit `~/.clawdbot/clawdbot.json` (it often contains tokens).
2026-01-08 01:18:37 +01:00
2026-01-07 00:25:16 +01:00
## Access control (DMs + groups)
DMs:
- Default: `imessage.dmPolicy = "pairing"` .
2026-01-07 05:06:04 +01:00
- Unknown senders receive a pairing code; messages are ignored until approved (codes expire after 1 hour).
2026-01-07 00:25:16 +01:00
- Approve via:
2026-01-10 16:36:43 +01:00
- `clawdbot pairing list imessage`
- `clawdbot pairing approve imessage <CODE>`
2026-01-07 02:04:02 +01:00
- Pairing is the default token exchange for iMessage DMs. Details: [Pairing ](/start/pairing )
2026-01-07 00:25:16 +01:00
Groups:
- `imessage.groupPolicy = open | allowlist | disabled` .
- `imessage.groupAllowFrom` controls who can trigger in groups when `allowlist` is set.
2026-01-09 12:44:23 +00:00
- Mention gating uses `agents.list[].groupChat.mentionPatterns` (or `messages.groupChat.mentionPatterns` ) because iMessage has no native mention metadata.
- Multi-agent override: set per-agent patterns on `agents.list[].groupChat.mentionPatterns` .
2026-01-07 00:25:16 +01:00
## How it works (behavior)
- `imsg` streams message events; the gateway normalizes them into the shared provider envelope.
- Replies always route back to the same chat id or handle.
2026-01-08 16:24:28 -06:00
## Group-ish threads (`is_group=false`)
Some iMessage threads can have multiple participants but still arrive with `is_group=false` depending on how Messages stores the chat identifier.
If you explicitly configure a `chat_id` under `imessage.groups` , Clawdbot treats that thread as a “group” for:
2026-01-11 02:31:45 +00:00
- session isolation (separate `agent:<agentId>:imessage:group:<chat_id>` session key)
2026-01-08 16:24:28 -06:00
- group allowlisting / mention gating behavior
Example:
```json5
{
imessage: {
groupPolicy: "allowlist",
groupAllowFrom: ["+15555550123"],
groups: {
"42": { "requireMention": false }
}
}
}
```
This is useful when you want an isolated personality/model for a specific thread (see [Multi-agent routing ](/concepts/multi-agent )). For filesystem isolation, see [Sandboxing ](/gateway/sandboxing ).
2026-01-07 00:25:16 +01:00
## Media + limits
- Optional attachment ingestion via `imessage.includeAttachments` .
- Media cap via `imessage.mediaMaxMb` .
2026-01-08 04:02:04 +01:00
## Limits
- Outbound text is chunked to `imessage.textChunkLimit` (default 4000).
- Media uploads are capped by `imessage.mediaMaxMb` (default 16).
2026-01-07 00:25:16 +01:00
## Addressing / delivery targets
2026-01-02 01:19:22 +01:00
Prefer `chat_id` for stable routing:
- `chat_id:123` (preferred)
2026-01-07 00:25:16 +01:00
- `chat_guid:...`
- `chat_identifier:...`
2026-01-02 01:19:22 +01:00
- direct handles: `imessage:+1555` / `sms:+1555` / `user@example.com`
List chats:
```
imsg chats --limit 20
```
2026-01-07 00:25:16 +01:00
## Configuration reference (iMessage)
2026-01-07 02:04:02 +01:00
Full configuration: [Configuration ](/gateway/configuration )
2026-01-07 00:25:16 +01:00
Provider options:
- `imessage.enabled` : enable/disable provider startup.
- `imessage.cliPath` : path to `imsg` .
- `imessage.dbPath` : Messages DB path.
- `imessage.service` : `imessage | sms | auto` .
- `imessage.region` : SMS region.
- `imessage.dmPolicy` : `pairing | allowlist | open | disabled` (default: pairing).
- `imessage.allowFrom` : DM allowlist (handles or `chat_id:*` ). `open` requires `"*"` .
2026-01-12 08:21:50 +00:00
- `imessage.groupPolicy` : `open | allowlist | disabled` (default: allowlist).
2026-01-07 00:25:16 +01:00
- `imessage.groupAllowFrom` : group sender allowlist.
2026-01-10 18:53:38 +01:00
- `imessage.historyLimit` / `imessage.accounts.*.historyLimit` : max group messages to include as context (0 disables).
2026-01-07 00:25:16 +01:00
- `imessage.groups` : per-group defaults + allowlist (use `"*"` for global defaults).
- `imessage.includeAttachments` : ingest attachments into context.
- `imessage.mediaMaxMb` : inbound/outbound media cap (MB).
- `imessage.textChunkLimit` : outbound chunk size (chars).
Related global options:
2026-01-09 12:44:23 +00:00
- `agents.list[].groupChat.mentionPatterns` (or `messages.groupChat.mentionPatterns` ).
2026-01-07 00:25:16 +01:00
- `messages.responsePrefix` .