Skip to main content

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.

PermissionWhat Apple says it grantsHow it is givenSource
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, AutomationAllow 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.

InterfaceWhat Taji usesApple's documentation
osascriptThe 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 errorman osascript (osascript(1), dated April 24, 2014), read locally; Apple's online copy of the page answers 404
Messages' scripting dictionarysend with a text or a file to a chat; a chat's id is "A guid identifier for this chat". send returns no resultsdef /System/Applications/Messages.app, read locally. Apple publishes no web page for it
~/Library/Messages/chat.dbSQLite tables message, chat, handle, chat_message_join, chat_handle_join, read-onlyNone. Apple documents neither the file nor its schema
message.dateNanoseconds since 00:00:00 UTC on 1 January 2001, the reference date of NSDateNSDate documents the reference date; nothing documents the column's unit
message.attributedBodyAn archived NSAttributedString in the typedstream format of NSArchiver, deprecated since macOS 10.13NSArchiver 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.style 45 is a one-to-one chat; 43 is a group;
  • message.service is iMessage or SMS, and handle.service is the service of its handle, so one address has a handle per service;
  • message.account is E:<email> or p:<number> on rows this Mac sent;
  • in the self-chat, the text lands on the is_from_me = 0 copy of a row;
  • a null text means the text is in attributedBody;
  • 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. hear drops every row whose service is not iMessage.
  • 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's id, which link already read from the database. The manifest's chat step uses participant once, 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 typing keeps the trait's no-op default.
  • An event for a received message. The dictionary has none, which is why inbound reads chat.db.
  • login and logout. 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.

FileOwnsRead first
plugins/imessage/src/lib.rsThe 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 testimpl Channel for IMessage, then hear
plugins/imessage/taji-plugin.tomlThe imessage link form: brief, three steps, risk line and the four refusal words with their sentencessteps
plugins/imessage/Cargo.tomlDependencies: taji-plugin, rusqlite (bundled SQLite), tokio, async-trait—
plugins/imessage/ui/mark.svgThe 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):

MethodiMessage's answer
id, nameimessage, iMessage
fieldsnone. The kernel seals nothing, the vault never locks it, and the slot holds an empty Secret from boot
capsinbound: true, images: true, text_limit: 20_000
markupMarkup::Plain: the kernel strips Markdown markers before send (engine/crates/taji/src/wire/markup.rs)
linkOpens chat.db, finds the self-chat, sends the hello. Returns owner: Some(<chat guid>), so the kernel links at once with no pairing code
sendOne osascript run for the text, one more for a picture. Returns "", because send in Messages names nothing it sent
runPolls chat.db every second and hands each heard row to inbox until a read fails
send_framed, typingThe 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 surfaceWhat happens on the MacFile
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 imessageNothing: 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 targetopener.rs
An alert's desk noteSEND_TEXT with the note's sentencechannels.rs alert, then lib.rs send
A phone turn's answer, a card, a command's replySEND_TEXT, one run per piece of at most 20,000 characterschannels.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 directorychannels.rs send, then lib.rs send
Your text to yourselfRead off chat.db within a secondlib.rs run, poll, hear
POST /verb/channels/unlinkNothing on the Mac: the kernel aborts run and forgets the ownerchannels.rs unlink

One message, in and out. You text yourself "how is AAPL?" from your phone.

  1. Messages on the Mac writes the row to chat.db. Within a second, run's tick calls poll. poll selects every message row past the watermark, joined to its chat and handle, and moves the watermark to the last ROWID it saw, heard or not.

  2. hear keeps the row when all of these hold:

    • service is iMessage;
    • chat.style is 45;
    • it is the is_from_me = 0 copy;
    • its handle is one of your own addresses;
    • its text (from text, else decoded from attributedBody, with U+FFFC removed) is not empty and does not start with Taji:.

    It returns Inbound { id: <message guid>, sender: <chat guid>, at_utc, text }.

  3. Inbox::heard calls Channels::heard, which runs the kernel's owner rule. The row's sender must equal the owner that link stored. Then it drops an id already 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 a taji command, and asks anything else on the attached desk's Agent chat.

  4. The agent's last message comes back as Said::Answer. send_to renders it with Markup::Plain, cuts it at 20,000 characters and calls IMessage::send with the chat guid as owner.

  5. send runs osascript - with SEND_TEXT on standard input and two arguments, Taji: <text> and the chat guid. Messages sends it into the self-chat. Its own row reaches chat.db, starts with Taji:, 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.rs header). Only you can send an iMessage from your own Apple Account into your own self-chat, so link returns the owner and no pairing code is needed. Anthropic's plugin does the same and argues against pairing on a personal chat.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 from chat.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 with Taji:. This fails closed and needs no id from osascript, which returns none.
  • A ROWID watermark from the newest row at start. The first run after Taji starts, and the first after each link, begins at MAX(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 between runs, so a rerun after Unreached begins where the last good poll ended and hears what arrived in between.
  • Arguments through argv. SEND_TEXT and SEND_FILE take the text and chat id as item 1 of argv and item 2 of argv, so no text is ever spliced into AppleScript source. The test send_marks_the_text_and_passes_it_by_argv sends " & (do shell script "id") & " and checks that it arrives as one argument.
  • Read-only, polled each second. Messages owns chat.db. Taji opens it with SQLITE_OPEN_READ_ONLY and 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. link sends the hello inside the send step, 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 osascript codes, two words. -1743 is automation and -1712 is no_answer; OpenClaw treats -1712 as "a timeout, not proof of a denied grant". Anything else is Refused("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-plugin alone (0003). No Apple shape reaches a client: rows are served as the generic Channel (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 access step 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:

    WordRaised whenStep
    accessThe open or first read of chat.db fails, in link or run. The path and SQLite error go to standard erroraccess
    no_chatNo style-45 chat has an iMessage handle among your own addresseschat
    automationosascript standard error holds (-1743)send
    no_answerIt holds (-1712)send

    Any other failure to read the database is Unreached. The kernel then sets the row's error and reruns run after 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 Word from run stops it. access there is kept as the row's error until a link or a send lands.

  • The self-chat chosen. self_chat takes only a style-45 chat whose handle is one of your own addresses with handle.service iMessage, because hear drops 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>.png in the temp directory and left for the OS's sweep, because Messages reads the file after osascript returns.

  • Timestamps. at_utc is APPLE_EPOCH + date / 1_000_000_000 (APPLE_EPOCH is 978_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 rowserviceis_from_mehandlechat (style)Heard
"a stranger's DM"iMessage0strangerDM (45)no: not an own address
"a stranger in the self-chat"iMessage0strangerself (45)no
"the owner in a group"iMessage0p1group (43)no: style 43
"an SMS"SMS0p1self (45)no: SMS
"a sent receipt"iMessage1p1self (45)no: is_from_me
"no handle"iMessage0noneself (45)no
"mine"iMessage0p1self (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).

CommandCovers
cargo test -p taji-imessageThe 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 -- channelsThe 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 headlesschannels 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::fixturethe_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:

  1. Boot a headless kernel (AGENTS.md, Commands) from a terminal that has Full Disk Access.
  2. POST /verb/channels/link {"channel":"imessage"}.
  3. Text yourself from your phone and watch the reply arrive.

References​

All fetched or read on 2026-12-02.