@tannerlinsley/imessage
Read, search, draft, and explicitly send iMessages on a Mac, using only built-in macOS tools.
- License
- Published
- November 1, 2026
- Pinned commit
2fab559- Rating
- No ratings yet
- Forks
- 0
- Adaptation effort
- —
README
Agent docsMessages on your Mac
Intent
Read and search your local Messages history, prepare drafts, and send only when you explicitly approve the recipient and exact text. Run on the Mac that holds your messages, with no Homebrew, third-party bridge, or other software to install.
Setup
Use a Mac supported by Kody Desktop, signed into Messages. Sending from the signed desktop app requires Kody 0.1.4 or newer. Keep Kody running and enable host commands for its execution context.
In System Settings > Privacy & Security > Full Disk Access, allow Kody Desktop, then quit and reopen it. If you run the daemon another way, the app launching that daemon needs access instead. macOS may ask separately for permission to control Messages when you first explicitly send, under Privacy & Security > Automation.
Run the root export to check reading access. It does not verify Automation permission for sending. Pin all message operations to the intended Mac's execution context, without cloud fallback. Conversation IDs belong to that Mac's local database.
import status from "kody:@tannerlinsley/imessage";
const readiness = await status({});Read and search
/conversations lists conversation IDs and participants. /messages reads one conversation. /search finds literal, case-insensitive text across conversations, including newer archived message bodies. Reads use the database in read-only mode and do not mark messages as read.
import search from "kody:@tannerlinsley/imessage/search";
const page = await search({ query: "dinner", limit: 10, scanLimit: 100 });Follow nextBeforeMessageId while hasMore is true. Search scans at most 200 rows per call, returns at most 50 matches, and reports unavailable or truncated text. Very large bodies and unsupported archive formats may be unavailable. Returned text is capped at 8000 characters. Search checks up to 65536 characters of plain text or 64 KiB of an archive, and reports searchTruncatedRows and unreadableTextRows. A zero-match page can still have more history to scan. Results use descending local message ID order, which can differ from sent time after a sync.
Find people by name
Contacts lookup needs Kody Desktop 0.1.5 or newer and separate macOS Contacts
permission. Full Disk Access does not grant it. Ordinary reads never request
new access. To initiate the first Contacts prompt, explicitly call
contacts({query:"Kent",requestAccess:true}) and let the user approve it.
Denied access must be enabled in System Settings > Privacy & Security > Contacts
for Kody or the actual daemon host.
import contacts from "kody:@tannerlinsley/imessage/contacts";
import conversations from "kody:@tannerlinsley/imessage/conversations";
import messages from "kody:@tannerlinsley/imessage/messages";
const matches = await contacts({ query: "Kent" });
// If ambiguous or hasMore, ask which person or narrow the query. Never choose the first match.
// After identifying the contact, use each relevant phone/email to find their chats:
const chats = await conversations({ participant: "+15555550100" });
// Inspect participants and service, then read the selected chat and find its latest incoming row./contacts accepts exactly one of query (contact name) or handle (phone/email).
It returns matching contacts, including phone numbers and email addresses.
ambiguous flags multiple matching identities, and hasMore means narrow the
query. It never edits Contacts. Read and search results include senderName
and senderContacts; conversations include contactName and
participantContacts. Raw sender addresses, participants and chat titles are
preserved. Names are null when absent, ambiguous or unavailable. Every read page
includes contactLookup permission status. Limited Contacts access only sees
contacts the user shared with Kody. These names are address-book labels, not
proof of a sender's identity.
The participant filter matches an exact phone/email, ignoring phone formatting and email case. It never guesses a country code or matches a phone-number suffix. A local-format number without its country code may need the user's clarification. Check all relevant addresses and chats; message order is newest stored first and may differ from sent time after sync.
Draft and send
/draft returns an object for review. It does not save a draft in Messages. Use an exact phone number with country code, an email address, or a conversation ID whose participants you have checked.
import prepare from "kody:@tannerlinsley/imessage/draft";
import send from "kody:@tannerlinsley/imessage/send";
const draft = await prepare({
target: { recipient: "test@example.invalid" },
text: "Synthetic preview, do not send.",
});
const preview = await send({ draft, confirmSend: false });Sending defaults to a preview and makes no host command. Set confirmSend: true only after approving the exact draft. Editing the draft invalidates its digest, so prepare and review a new draft after changes. The digest detects accidental changes, it is not an authorization token.
New-recipient sends request iMessage. To reply to an existing SMS or RCS conversation, prepare a draft with its chatId and explicit service, either SMS or RCS. The service must match the conversation on this Mac. Messages itself controls delivery and any system fallback behavior. A recorded result confirms a matching new outgoing row on this Mac, not delivery to the recipient. If a result is uncertain, inspect Messages before doing anything else. Never automatically retry a send.
Privacy and limits
The package reads your Mac's database through built-in SQLite and Foundation and sends through built-in Messages automation. It does not install a helper or modify the database. Message content requested by a caller is returned to that Kody execution and its caller, so only request the history you need. It does not export attachments, delete messages, or recover unsent messages. It has no app interface or background polling.
Run npm test with Node 26 on macOS to exercise synthetic databases, archived text, search, and mocked sending. Tests never send real messages. The fixture archive was generated with Foundation's NSArchiver for an NSAttributedString and contains only synthetic text.
Report this listing
Log in to report this listing.