imsgctl
Use imsgctl to read Apple Messages data available on the current machine.
Use This Skill When
- - The user wants to inspect iMessage or SMS data from Apple Messages.
- The user wants to list recent chats.
- The user wants message history for a specific chat.
- The user wants to filter message history by time.
- The user wants attachment metadata.
- The user wants to watch for new messages or reactions.
Do Not Use This Skill When
- - The user wants to send or reply to a message.
- The user wants to delete, edit, react to, or otherwise modify Messages data.
- The request is about Slack, Discord, Telegram, Signal, WhatsApp, or another messaging system.
Operating Rules
- - Prefer
--json when results may be parsed or reused. - INLINECODE2 emits one JSON object.
- INLINECODE3 ,
history --json, and watch --json emit JSONL. - Use
--db PATH when the user gives a specific database path or when the backend must be explicit. - Use
watch only for live monitoring. It streams until interrupted.
Defaults And Access
- - On macOS, running without
--db prefers ~/Library/Application Support/imsgkit/replica.db when a valid replica exists. Otherwise it falls back to ~/Library/Messages/chat.db. - On Linux, running without
--db reads ~/.local/share/imsgkit/replica.db, or $XDG_DATA_HOME/imsgkit/replica.db when XDG_DATA_HOME is set to an absolute path. - Direct access to
~/Library/Messages/chat.db requires macOS and Full Disk Access for the process doing the reading. - If contact resolution is unavailable, chat and sender labels may fall back to raw identifiers.
Common Commands
Check Access
CODEBLOCK0
List Recent Chats
CODEBLOCK1
Read Recent History For A Chat
CODEBLOCK2
Read History With Attachment Metadata
CODEBLOCK3
Read History In A Time Window
CODEBLOCK4
Watch New Activity
CODEBLOCK5
Watch New Messages, Attachments, and Reactions
CODEBLOCK6
Use An Explicit Database Path
CODEBLOCK7
Recommended Workflow
- 1. Run
imsgctl health --json to confirm access. - Run
imsgctl chats --limit 20 --json to identify the target chat. - Use the returned chat ID with
imsgctl history --chat-id ... --json. - Add
--start, --end, --limit, or --attachments only as needed. - Use
imsgctl watch only if the user asked for live monitoring.
Viewing Image Attachments
When --attachments reveals an image, the file is often too large to read directly. Convert it to a smaller JPEG preview, then read the result:
- - macOS: INLINECODE25
- Linux: INLINECODE26
Failure Modes
- - If direct macOS reads fail, check Full Disk Access first.
- If the expected local database path is missing, access will fail until the correct database is available on the current machine.
- If chat labels are ambiguous or missing, rely on chat IDs and raw identifiers.
imsgctl
使用 imsgctl 读取当前机器上可用的 Apple 信息数据。
使用场景
- - 用户想要查看 Apple 信息中的 iMessage 或短信数据。
- 用户想要列出最近的聊天记录。
- 用户想要查看特定聊天的消息历史。
- 用户想要按时间筛选消息历史。
- 用户想要获取附件元数据。
- 用户想要监控新消息或反应。
禁止使用场景
- - 用户想要发送或回复消息。
- 用户想要删除、编辑、回复或以其他方式修改信息数据。
- 请求涉及 Slack、Discord、Telegram、Signal、WhatsApp 或其他消息系统。
操作规则
- - 当结果可能需要解析或复用时,优先使用 --json。
- imsgctl health --json 输出单个 JSON 对象。
- imsgctl chats --json、history --json 和 watch --json 输出 JSONL 格式。
- 当用户指定了特定的数据库路径,或后端需要明确指定时,使用 --db PATH。
- 仅用于实时监控时使用 watch。它会持续输出直到被中断。
默认值与访问权限
- - 在 macOS 上,不指定 --db 运行时,如果存在有效的副本,则优先使用 ~/Library/Application Support/imsgkit/replica.db。否则回退到 ~/Library/Messages/chat.db。
- 在 Linux 上,不指定 --db 运行时,读取 ~/.local/share/imsgkit/replica.db,或当 XDGDATAHOME 设置为绝对路径时读取 $XDGDATAHOME/imsgkit/replica.db。
- 直接访问 ~/Library/Messages/chat.db 需要 macOS 系统,并且执行读取的进程需要拥有完全磁盘访问权限。
- 如果无法解析联系人,聊天和发送者标签可能会回退到原始标识符。
常用命令
检查访问权限
bash
imsgctl health --json
列出最近聊天
bash
imsgctl chats --limit 20 --json
读取聊天的最近历史
bash
imsgctl history --chat-id 42 --limit 50 --json
读取包含附件元数据的历史
bash
imsgctl history --chat-id 42 --limit 50 --attachments --json
读取指定时间范围内的历史
bash
imsgctl history \
--chat-id 42 \
--limit 50 \
--start 2026-03-01T00:00:00Z \
--end 2026-03-02T00:00:00Z \
--json
监控新活动
bash
imsgctl watch --chat-id 42 --json
监控新消息、附件和反应
bash
imsgctl watch --chat-id 42 --attachments --reactions --json
使用显式数据库路径
bash
imsgctl chats --db ~/Library/Application\ Support/imsgkit/replica.db --limit 20 --json
imsgctl history --db ~/.local/share/imsgkit/replica.db --chat-id 42 --limit 50 --json
推荐工作流程
- 1. 运行 imsgctl health --json 确认访问权限。
- 运行 imsgctl chats --limit 20 --json 确定目标聊天。
- 使用返回的聊天 ID 配合 imsgctl history --chat-id ... --json。
- 仅在需要时添加 --start、--end、--limit 或 --attachments。
- 仅当用户要求实时监控时使用 imsgctl watch。
查看图片附件
当 --attachments 显示有图片时,文件通常太大无法直接读取。将其转换为较小的 JPEG 预览图,然后读取结果:
- - macOS: sips -s format jpeg -Z 800 /path/to/image.heic --out /tmp/preview.jpg
- Linux: magick /path/to/image.heic -resize 800x800 /tmp/preview.jpg
失败模式
- - 如果 macOS 直接读取失败,首先检查完全磁盘访问权限。
- 如果预期的本地数据库路径不存在,访问将失败,直到当前机器上存在正确的数据库。
- 如果聊天标签不明确或缺失,请依赖聊天 ID 和原始标识符。