iMessage: how it works
iMessage is Apple's messaging service, and Messages is the Mac app that carries it. Taji uses your one-to-one iMessage chat with yourself both ways. Alerts, agent answers and permission cards go out as texts into that chat, and what you text yourself from your phone comes back in. The plugin is one channel crate, taji-imessage, built from plugins/imessage/src/lib.rs. It implements taji_plugin::channel::Channel and calls no network host. It reads the Messages database on this Mac and runs osascript to make Messages send. It needs no account of its own, no key and no token, and it serves no market data, places no orders and feeds no hub product.
The vendor
Apple documents the user-facing settings and the scripting interface; the Messages database has no public documentation. Each fact below names its source, all fetched or read on 2026-12-02. This Mac ran macOS 27.0.1.
The service. iMessage runs between Apple devices over Wi-Fi or cellular data and is end-to-end encrypted. SMS, MMS and RCS are carrier services that reach non-Apple phones, and SMS/MMS is not end-to-end encrypted (What is the difference between iMessage, RCS, and SMS/MMS?). A Mac shows SMS, MMS and RCS only through Text Message Forwarding from an iPhone on the same Apple Account (Forward text messages).
Accounts. You sign in to Messages on the Mac with your Apple Account. You choose the addresses (phone numbers and emails) where "You can be reached for messages at", and which one to "Start new conversations from". Messages in iCloud is an optional setting (Set up Messages on Mac). There is no environment beyond the live one, no sandbox and no entitlement tier. Your chat with yourself is a conversation with one of your own addresses.
Two macOS permissions stand in for an auth model. Neither has a token or a lifetime; each lasts until you turn it off in System Settings.
| Permission | What Apple says it grants | How it is given | Source |
|---|---|---|---|
| Full Disk Access | "access all files on your computer, including data from other apps" | You add the app under Privacy & Security, Full Disk Access. From macOS 27.3 an app's request can also offer "Choose Folder", "Choose Apps" or "Bypass System Protections" | Change Privacy & Security settings, If an app asks for Full Disk Access, Controlling app access to files |
| Automation | "access and control other apps on your Mac" | A dialog with Allow and Don't Allow the first time an app sends Apple events to another app; later, a per-app switch under Privacy & Security, Automation | Allow apps to automate and control other apps, Allow apps to control other apps |
For a signed app, Apple's developer docs add two requirements. The Info.plist key NSAppleEventsUsageDescription "is required if your app uses APIs that send Apple events" (NSAppleEventsUsageDescription). A hardened-runtime app needs the com.apple.security.automation.apple-events entitlement to prompt for that permission (Apple Events Entitlement). The SDK header AE.framework/Headers/AppleEvents.h says the prompt comes "the first time an application attempts to send an AppleEvent to another application", and that after a refusal every later send fails with errAEEventNotPermitted (-1743). CarbonCore.framework/Headers/MacErrors.h defines errAETimeout (-1712) as "the AppleEvent timed out" (errAETimeout).
Interfaces Taji calls.
| Interface | What Taji uses | Apple's documentation |
|---|---|---|
osascript | The script on standard input (-), its arguments after it. "Any arguments following the script will be passed as a list of strings to the direct parameter of the run handler", and script errors print to standard error | man osascript (osascript(1), dated April 24, 2014), read locally; Apple's online copy of the page answers 404 |
| Messages' scripting dictionary | send with a text or a file to a chat; a chat's id is "A guid identifier for this chat". send returns no result | sdef /System/Applications/Messages.app, read locally. Apple publishes no web page for it |
~/Library/Messages/chat.db | SQLite tables message, chat, handle, chat_message_join, chat_handle_join, read-only | None. Apple documents neither the file nor its schema |
message.date | Nanoseconds since 00:00:00 UTC on 1 January 2001, the reference date of NSDate | NSDate documents the reference date; nothing documents the column's unit |
message.attributedBody | An archived NSAttributedString in the typedstream format of NSArchiver, deprecated since macOS 10.13 | NSArchiver documents the class, not the byte layout. Two maintained decoders agree on it: crabstep 0.7.0, imessage-exporter's, and pytypedstream 0.1.0 |
The database facts this crate relies on are read from the database and from Anthropic's iMessage channel plugin (claude-plugins-official, external_plugins/imessage/server.ts), whose poll query, watermark, own-address rule, attributedBody decoder and argv scripts the crate ports, as its //! header says. They are:
chat.style45 is a one-to-one chat; 43 is a group;message.serviceisiMessageorSMS, andhandle.serviceis the service of its handle, so one address has a handle per service;message.accountisE:<email>orp:<number>on rows this Mac sent;- in the self-chat, the text lands on the
is_from_me = 0copy of a row; - a null
textmeans the text is inattributedBody; - U+FFFC stands in for an attachment.
Apple can change any of these in a macOS update without notice.
Stated limits. Apple states none for iMessage length, send rate or chat.db reads on the pages above, and a search of support.apple.com on 2026-12-02 found no length limit. The 20,000-character text_limit in caps is Taji's own bound, set where users on Apple's community forums report sends failing (thread 8426396). Anthropic's plugin cuts at 10,000 (MAX_CHUNK_LIMIT in server.ts), also unsourced.
Capabilities Taji does not use.
- SMS, MMS and RCS. A carrier sender can be spoofed; an iMessage sender is authenticated by Apple Account.
heardrops every row whoseserviceis notiMessage. - Other conversations and group chats. Taji hears only your self-chat, because a reply there can answer a card that runs a shell (ruling, 2026-11-17: follow Anthropic's plugin, self-chat alone, no allowlist).
- Sending to a
participant. Taji sends to the chat'sid, whichlinkalready read from the database. The manifest'schatstep usesparticipantonce, from your shell, to create the chat. - Attachments sent from your phone. A row holding only an attachment is dropped. Not yet built.
- Typing indicators and read receipts. The scripting dictionary has no command for either, so
typingkeeps the trait's no-op default. - An event for a received message. The dictionary has none, which is why inbound reads
chat.db. loginandlogout. The dictionary offers both; Taji never signs Messages in or out.- Apple Messages for Business. It is for companies, through an Apple-approved Messaging Service Provider and an Experience Review (Messaging documentation). It cannot reach your own number as you.
Code map
The crate is one source file, its manifest and its mark.
| File | Owns | Read first |
|---|---|---|
plugins/imessage/src/lib.rs | The IMessage arm: link, send, run. Also the chat.db queries (own_addresses, self_chat, poll), the owner rule's database half (hear), the typedstream decoder (attributed_text), the osascript runner and its error words (osascript, classify_osascript), and every test | impl Channel for IMessage, then hear |
plugins/imessage/taji-plugin.toml | The imessage link form: brief, three steps, risk line and the four refusal words with their sentences | steps |
plugins/imessage/Cargo.toml | Dependencies: taji-plugin, rusqlite (bundled SQLite), tokio, async-trait | — |
plugins/imessage/ui/mark.svg | The Connections row's mark, a generic speech bubble (LICENSING.md), picked up by ui/src/marks.ts | — |
How it plugs into Taji
Composition. engine/crates/taji-open/src/lib.rs adds taji_imessage::IMessage::default under #[cfg(target_os = "macos")], and engine/crates/taji-open/Cargo.toml takes the crate only as a macOS dependency. On Windows and Linux the kernel has no imessage channel. Plugin::build registers the arm with Build::channel.
The trait. IMessage implements taji_plugin::channel::Channel (engine/crates/taji-plugin/src/channel.rs):
| Method | iMessage's answer |
|---|---|
id, name | imessage, iMessage |
fields | none. The kernel seals nothing, the vault never locks it, and the slot holds an empty Secret from boot |
caps | inbound: true, images: true, text_limit: 20_000 |
markup | Markup::Plain: the kernel strips Markdown markers before send (engine/crates/taji/src/wire/markup.rs) |
link | Opens chat.db, finds the self-chat, sends the hello. Returns owner: Some(<chat guid>), so the kernel links at once with no pairing code |
send | One osascript run for the text, one more for a picture. Returns "", because send in Messages names nothing it sent |
run | Polls chat.db every second and hands each heard row to inbox until a read fails |
send_framed, typing | The trait's defaults: a card goes as its text form, ending in the replies to type; no typing signal |
The crate has no FACTS, VenueFacts or OFFER statics: those describe data sources and venues.
The link form. plugins/imessage/taji-plugin.toml declares one [[link]], form = "imessage", kind = "start", in the Channels group. Its three steps are access, chat and send, in that order. access and send are yours: true: only you can flip a macOS permission. chat is not, so your agent may send the first self-text from your shell. Each open is one of the closed targets in engine/crates/taji/src/opener.rs: settings:full-disk-access, app:messages and settings:automation become /usr/bin/open with the Privacy_AllFiles pane, the com.apple.MobileSMS bundle and the Privacy_Automation pane. link calls report.at(step) before each step, so GET /read/flows stands on the step that failed, and a Failed::Word is shown with the manifest's sentence.
What it feeds. Every surface is a channels row of the //! header of engine/crates/taji/src/wire/mod.rs, served by engine/crates/taji/src/wire/channels.rs:
| Taji surface | What happens on the Mac | File |
|---|---|---|
POST /verb/channels/link {"channel":"imessage"} | chat.db opened read-only; own addresses and the self-chat read; SEND_TEXT with Taji: Linked to Taji. | lib.rs link |
GET /read/channels, row imessage | Nothing: state, error and last_sent_utc are kernel state. <state dir>/channels.json holds {"imessage":{"owner":"<chat guid>"}} | channels.rs read |
GET /read/flows?flow=imessage, POST /verb/flow/open | /usr/bin/open with a fixed target | opener.rs |
| An alert's desk note | SEND_TEXT with the note's sentence | channels.rs alert, then lib.rs send |
| A phone turn's answer, a card, a command's reply | SEND_TEXT, one run per piece of at most 20,000 characters | channels.rs ask, say, then send |
POST /verb/channels/send {pane, text?} | SEND_TEXT with the caption, then SEND_FILE with the chart PNG written to the temp directory | channels.rs send, then lib.rs send |
| Your text to yourself | Read off chat.db within a second | lib.rs run, poll, hear |
POST /verb/channels/unlink | Nothing on the Mac: the kernel aborts run and forgets the owner | channels.rs unlink |
One message, in and out. You text yourself "how is AAPL?" from your phone.
-
Messages on the Mac writes the row to
chat.db. Within a second,run's tick callspoll.pollselects everymessagerow past the watermark, joined to its chat and handle, and moves the watermark to the last ROWID it saw, heard or not. -
hearkeeps the row when all of these hold:serviceisiMessage;chat.styleis 45;- it is the
is_from_me = 0copy; - its handle is one of your own addresses;
- its text (from
text, else decoded fromattributedBody, with U+FFFC removed) is not empty and does not start withTaji:.
It returns
Inbound { id: <message guid>, sender: <chat guid>, at_utc, text }. -
Inbox::heardcallsChannels::heard, which runs the kernel's owner rule. The row'ssendermust equal the owner thatlinkstored. Then it drops anidalready seen and answers "Not run: Taji heard this late." to a row older than 120 s. Next it matches a card reply (yes <t>), then atajicommand, and asks anything else on the attached desk's Agent chat. -
The agent's last message comes back as
Said::Answer.send_torenders it withMarkup::Plain, cuts it at 20,000 characters and callsIMessage::sendwith the chat guid asowner. -
sendrunsosascript -withSEND_TEXTon standard input and two arguments,Taji: <text>and the chat guid. Messages sends it into the self-chat. Its own row reacheschat.db, starts withTaji:, and step 2 drops it.
Why it is built this way
- The self-chat is the owner proof. A channel's owner rule is the one guard between a chat account and a card that can run a shell (
channels.rsheader). Only you can send an iMessage from your own Apple Account into your own self-chat, solinkreturns the owner and no pairing code is needed. Anthropic's plugin does the same and argues against pairing on a personalchat.db; Taji follows it (ruling, 2026-11-17). - iMessage only. The code says it in
hear's comment: "Apple-ID-authenticated; SMS senders are spoofable". Apple confirms that SMS is a carrier service without end-to-end encryption (104972). - Own addresses come from
message.account. They come from the rows this Mac sent, not fromchat.last_addressed_handle, which "holds short codes and other people's numbers" (own_addresses, ported from the reference). - The mark, not an echo window. Anthropic's plugin drops its own sends with a 15-second text-match window. Taji starts every text with
Taji:and never hears a row that starts withTaji:. This fails closed and needs no id fromosascript, which returns none. - A ROWID watermark from the newest row at start. The first
runafter Taji starts, and the first after eachlink, begins atMAX(ROWID), so a restart or a relink never replays history into your agent. The cost is that a text sent while Taji is down is never heard (the README says so). The arm holds the watermark betweenruns, so a rerun afterUnreachedbegins where the last good poll ended and hears what arrived in between. - Arguments through argv.
SEND_TEXTandSEND_FILEtake the text and chat id asitem 1 of argvanditem 2 of argv, so no text is ever spliced into AppleScript source. The testsend_marks_the_text_and_passes_it_by_argvsends" & (do shell script "id") & "and checks that it arrives as one argument. - Read-only, polled each second. Messages owns
chat.db. Taji opens it withSQLITE_OPEN_READ_ONLYand writes nothing. The dictionary offers no event for a received message, so a poll is the only way in. One second follows the reference. - The Automation prompt is met at link.
linksends the hello inside thesendstep, so the macOS dialog lands on a named step while you are at the Mac. Otherwise your first alert might hit it with nobody there. Only your press of Link sends the hello (ruling, 2026-11-17, following OpenClaw over Anthropic's plugin). - Two
osascriptcodes, two words. -1743 isautomationand -1712 isno_answer; OpenClaw treats -1712 as "a timeout, not proof of a denied grant". Anything else isRefused("Messages could not send that text."). The raw standard error goes only to the kernel's own standard error, never to a client. - Plain markup. Messages renders no Markdown, so the kernel strips the markers.
- The decisions it follows. Taji calls no model here (0002). The plugin depends on
taji-pluginalone (0003). No Apple shape reaches a client: rows are served as the genericChannel(0004).
Constraints and limits
-
macOS only. The arm is compiled into the kernel only on macOS.
-
Permissions are per process. Full Disk Access and Automation are granted to the app that macOS holds responsible for the kernel. That is Taji when Taji.app launched it, and the terminal or your agent's app when one of those did (the
accessstep says so). Which name macOS shows, and whether a grant reaches a kernel already running, are unmeasured on record; the step says to quit and reopen Taji. -
Refusals. Each word below lands on one link step, and its sentence is the manifest's:
Word Raised when Step accessThe open or first read of chat.dbfails, inlinkorrun. The path and SQLite error go to standard erroraccessno_chatNo style-45 chat has an iMessagehandle among your own addresseschatautomationosascriptstandard error holds(-1743)sendno_answerIt holds (-1712)sendAny other failure to read the database is
Unreached. The kernel then sets the row'serrorand rerunsrunafter 5 s; the rerun keeps the arm's watermark, so a row of the failed poll and a text sent in the 5 s are heard. -
A
Wordfromrunstops it.accessthere is kept as the row'serroruntil a link or a send lands. -
The self-chat chosen.
self_chattakes only a style-45 chat whose handle is one of your own addresses withhandle.serviceiMessage, becauseheardrops every SMS row and an SMS self-chat would hear nothing. Of several, it picks the one whose newest message has the highest ROWID. -
Images. A picture is written to
taji-imessage-<nanos>.pngin the temp directory and left for the OS's sweep, because Messages reads the file afterosascriptreturns. -
Timestamps.
at_utcisAPPLE_EPOCH + date / 1_000_000_000(APPLE_EPOCHis978_307_200), which assumes the nanosecond unit. The kernel's 120-second lateness check depends on it. -
Measured numbers. The README has no measured section and there is no coverage page. Whether a self-sent text buzzes your phone, and which binary the Full Disk Access pane names, are owed by a walk on a real Mac.
Examples
No capture yet from a real chat.db or a real Messages send: no live test or walk script covers iMessage (engine/crates/taji/scripts/channels_walk.py drives Discord alone). A capture would come from the link and a self-chat round trip on a Mac. The exchanges below are copied from the crate's test bodies, their values made up, and the wire fixture. The owner's address is p1.
Link. The wire fixture engine/crates/taji/tests/fixtures/wire/link-forms.json gives the form's post:
"post": { "body": { "channel": "imessage" }, "route": "channels/link" }
The arm then runs one script. link_says_the_steps_in_order_and_sends_the_hello in plugins/imessage/src/lib.rs records the steps and the osascript run:
steps: ["access", "chat", "send"]
script: on run argv
tell application "Messages" to send (item 1 of argv) to chat id (item 2 of argv)
end run
argv: ["Taji: Linked to Taji.", "iMessage;-;p1"]
owner: "iMessage;-;p1"
The kernel answers 200 {"channel":"imessage"}, a ChannelLinked with no pair, because the arm named the owner.
One message in. only_the_owners_imessage_in_the_self_chat_is_heard builds a chat.db with these rows and keeps only the last. Each row's date is 800_000_000_000_000_000.
message row | service | is_from_me | handle | chat (style) | Heard |
|---|---|---|---|---|---|
| "a stranger's DM" | iMessage | 0 | stranger | DM (45) | no: not an own address |
| "a stranger in the self-chat" | iMessage | 0 | stranger | self (45) | no |
| "the owner in a group" | iMessage | 0 | p1 | group (43) | no: style 43 |
| "an SMS" | SMS | 0 | p1 | self (45) | no: SMS |
| "a sent receipt" | iMessage | 1 | p1 | self (45) | no: is_from_me |
| "no handle" | iMessage | 0 | none | self (45) | no |
| "mine" | iMessage | 0 | p1 | self (45) | yes |
Inbound { id: "p2", sender: "iMessage;-;p1", at_utc: APPLE_EPOCH + 800_000_000, text: "mine" }
APPLE_EPOCH is 978_307_200, 2001-01-01 in Unix seconds.
A text in attributedBody. attributed_body_is_decoded_when_text_is_null stores a null text and this blob, built by the test's body:
04 0b "streamtyped" 81 e8 03 84 01 "@" 84 84 84 12 "NSAttributedString" 00 … 84 84 84 08 "NSString" 01 94 84 01 "+" 0a "buy 1 AAPL" 86 84 02 "iI" 01
attributed_text finds NSString, skips to +, and reads the length byte 0a (10) and then buy 1 AAPL. A length of 128 or more is 81 and a little-endian u16, or 82 and a u32: crabstep's read_unsigned_int (src/deserializer/number.rs, tags in src/deserializer/constants.rs) and pytypedstream's _read_integer (src/typedstream/stream.py, _TAG_INTEGER_2 -127 and _TAG_INTEGER_4 -126), little-endian for the streamtyped signature. The test writes its 200-character text as 81 c8 00 and its 70,000-character text as 82 70 11 01 00.
One message out, with a picture. send_marks_the_text_and_passes_it_by_argv calls send with a hostile text and a PNG, and records two runs:
1: SEND_TEXT argv ["Taji: \" & (do shell script \"id\") & \"", "iMessage;-;p1"]
2: SEND_FILE argv ["<temp dir>/taji-imessage-<nanos>.png", "iMessage;-;p1"]
on run argv
tell application "Messages" to send (POSIX file (item 1 of argv)) to chat id (item 2 of argv)
end run
send returns "", so POST /verb/channels/send answers {"sent":[""]}.
A refusal. osascript_words_and_refusals_hold_for_link_and_send feeds the standard error Not authorized to send Apple events to Messages. (-1743), and both link and send fail with Failed::Word("automation"). channels/link then answers 502 channel with "macOS is not letting Taji control Messages."
Testing
Every test is offline. None needs a key, an Apple Account or Messages. The crate's tests build a throwaway SQLite file with the five tables and made-up example.com addresses, and replace osascript with a closure that records each script and its arguments (the Osascript seam).
| Command | Covers |
|---|---|
cargo test -p taji-imessage | The steps' yours flags; link order and hello; access and no_chat; an SMS self-chat never picked; the osascript words; the owner rule's database half; the mark; attributedBody with one-, two- and four-byte lengths; the watermark; run hearing only later rows, a rerun hearing the gap and a link starting afresh; argv sends |
cargo test -p taji --lib -- channels | The kernel side with fake arms: the owner rule table, cards, commands, the 120 s rule, Plain rendering and cutting, alerts, and a refusal word kept on its step (a_standing_step_and_refusal_word_follow_link_run_and_send uses iMessage's no_chat sentence) |
cargo test --locked -p taji-open --test headless | channels in engine/crates/taji-open/tests/headless/surface.rs: on macOS, imessage is among GET /read/channels' rows and reads unlinked |
cargo test -p taji --lib wire::fixture | the_wire_fixture_is_the_kernels, which holds the imessage form in link-forms.json |
There is no tests/live.rs and no walk script. Today the real round trip is a person on a Mac:
- Boot a headless kernel (
AGENTS.md, Commands) from a terminal that has Full Disk Access. POST /verb/channels/link {"channel":"imessage"}.- Text yourself from your phone and watch the reply arrive.
References
All fetched or read on 2026-12-02.
- What is the difference between iMessage, RCS, and SMS/MMS?
- Forward text messages from your iPhone to other devices
- Set up Messages on Mac
- Change Privacy & Security settings on Mac
- If an app asks for Full Disk Access or System & App Protection Override on your Mac
- Controlling app access to files in macOS
- Allow apps to automate and control other apps
- Allow apps to control other apps on Mac
- NSAppleEventsUsageDescription
- Apple Events Entitlement
- errAETimeout
- NSDate
- NSArchiver
- Apple Messages for Business: messaging documentation
- Read locally on macOS 27.0.1:
man osascript;sdef /System/Applications/Messages.app; the macOS SDK headersAE.framework/Headers/AppleEvents.handCarbonCore.framework/Headers/MacErrors.h