Skip to main content
command CX Codex

_index · coco-research, email — Claude Code slash command: read Outlook email

_index — a Claude slash command that reads, searches and triages Outlook mail through subcommands such as unread, summary and triage.

MIT ★ 328 updated 2026-10-29

Install into Claude Code · Manually: put the files in place All methods and platforms ↓
.claude/commands/_index.md
Open on GitHub

What _index does

The command gives Claude a handle on Outlook mail: read and search messages, file them into project folders. It checks which client is running first, with defaults read com.microsoft.Outlook IsRunningNewOutlook. Zero or nothing back means Legacy Outlook, and AppleScript takes over. A 1 means the new client, where AppleScript dies quietly, so the command reads MIME and HxStore data instead.

Subcommands cover the daily loop: read <name>, unread, search <keywords>, today, this-week, thread <subject>, folders, summary, reply-draft <subject>, save <name/subject> to <folder>, plus triage and noise. Call it bare and unread runs. save writes each match into a project folder as a .txt file. summary opens the bodies and pulls out decisions, action items and meetings.

Triage is the part with strings attached. Classification comes from ~/.coco/email-triage.py reading ~/.coco/email-noise-rules.yaml, run with python3, so the rules decide and the model doesn't. Marking those messages read happens only in Legacy Outlook. The new client has no AppleScript to set that flag.

What it helps with

  • clear the unread pile without opening Outlook
  • find a message by a word in the subject or body
  • pull decisions and action items out of a day's mail
  • drop a thread into a project folder as text files
  • filter recurring noise with your own rules

Example prompts for the agent

  • Run /_index unread and group the results by sender.
  • /_index summary — give me the decisions and action items from today's mail.
  • /_index save Acme to docs/mail to keep that thread in the project.

How to install _index

Manually: put the files in place

.claude/commands/_index.md

Call it with /_index. For all projects use ~/.claude/commands/

Questions about _index

How do I install _index in Claude Code?

Put the command file in your project at .claude/commands/_index.md. Then call it with a subcommand: /_index today or /_index unread.

What does _index do?

It reads and searches Outlook mail, lists unread messages and threads, summarises a day, saves messages to text files and drafts replies.

Does _index work with the new Outlook?

Reading and searching switch to MIME and HxStore extraction. Marking messages read through triage only works in Legacy Outlook, because the new client doesn't support AppleScript.

Source text

_index.md · MIT
---
description: "Read, search, and manage Outlook emails. Auto-detects Legacy Outlook (AppleScript) vs New Outlook (MIME/HxStore extraction). Subcommands: read, unread, search, today, thread, save, summary, reply-draft."
allowed-tools:
  - Bash
  - Read
  - Write
  - Edit
  - Glob
  - Grep
  - Agent
  - AskUserQuestion
---

# /email — Outlook Email Commands

You manage Outlook email access. Parse the user's argument to determine which subcommand to run.

## Preflight: Detect Outlook variant (REQUIRED — run first)

Outlook for Mac has two incompatible variants. Detect which one is running before doing anything:

```bash
defaults read com.microsoft.Outlook IsRunningNewOutlook 2>/dev/null || echo 0
```

- Output `0` or unset → **Legacy Outlook** → use the AppleScript templates below.
- Output `1` → **New Outlook** → AppleScript is NOT supported (it will silently fail or error). Use **New Outlook (MIME) Mode** below instead. Do NOT attempt AppleScript.

If an AppleScript call errors with "Microsoft Outlook got an error" or the app is unscriptable, treat it as New Outlook and switch to MIME mode rather than retrying.

## CRITICAL: AppleScript Sender Pattern

The `sender` property in Legacy Outlook returns a **record**, not an object. Always access it like this:
```applescript
set s to sender of msg
set sName to name of s
set sAddr to address of s
```
NEVER use `name of sender of msg` directly — it will error.

## Subcommands

- **`read <name>`** — Show latest emails from a specific person
- **`unread`** — Show unread emails (count + top 20)
- **`search <keywords>`** — Search emails by subject/body keywords
- **`today`** — Show all emails received today
- **`this-week`** — Show emails from this week grouped by day
- **`thread <subject>`** — Show full email thread by subject
- **`save <name/subject> to <folder>`** — Save matching emails to a project folder
- **`summary`** — AI summary of today's/unread emails — key decisions, action items
- **`reply-draft <subject>`** — Draft a reply to a specific email
- **`folders`** — List all mail folders with message counts
- **`triage`** — Scan unread, auto-mark known noise (per rules file), show the rest
- **`noise`** — Show/add noise rules (`noise add auto|propose <field>=<value> [reason]`)

If no subcommand given, default to `unread`.

---

## AppleScript Templates

### Base: Read messages with sender info
```applescript
tell application "Microsoft Outlook"
    set allMsgs to messages 1 thru {LIMIT} of {FOLDER}
    repeat with msg in allMsgs
        try
            set s to sender of msg
            set sName to name of s
            set sAddr to address of s
            set subj to subject of msg
            set msgDate to time received of msg
            set isRead to is read of msg
            -- filter logic here
        end try
    end repeat
end tell
```

### For reading body content
```applescript
set bodyText to plain text content of msg
```

### For checking recipients (sent items)
```applescript
set recipList to to recipients of msg
repeat with r in recipList
    set recipAddr to address of r
end repeat
```

### Folder references
- Inbox: `inbox` or `mail folder "Inbox" of default account`
- Sent: `mail folder "Sent Items" of default account`
- Archive: `mail folder "Archive" of default account`
- Deleted: `mail folder "Deleted Items" of default account`
- All folders: `mail folders of default account`

---

## Subcommand Details

### `read <name>`
1. Search inbox (first 1000 messages) for sender name/address containing `<name>`
2. Show up to 10 most recent matches as a table: Status | Date | From | Subject
3. Ask if user wants to read the full body of any specific email
4. If user says yes, fetch `plain text content of msg` and display

### `unread`
1. Count unread: iterate messages and count where `is read of msg` is false
2. Show first 20 unread messages as table: Date | From | Subject
3. Group by sender if many from same person
4. Offer to mark as read or read full content

### `search <keywords>`
1. Search inbox (first 2000 messages) — check `subject of msg` for keyword match
2. Also optionally search body (`plain text content`) for deeper matches (warn: slower)
3. Show results as table: Date | From | Subject
4. Limit to 20 results

### `today`
1. Get today's date
2. Iterate inbox messages, stop when `time received of msg` is before today
3. Show all today's emails as table grouped by hour
4. Include read/unread status

### `this-week`
1. Get date 7 days ago
2. Iterate inbox, collect all messages from this week
3. Group by day, show count per day + subjects
4. Limit to 50 most recent

### `thread <subject>`
1. Search inbox + sent items for messages where subject contains `<subject>`
2. Sort by date
3. Show full thread chronologically with sender and body excerpts

### `save <query> to <folder>`
1. Search for emails matching `<query>` (by sender name or subject keyword)
2. For each match, save to the specified project folder as `.txt` files:
   ```
   Subject: ...
   From: ...
   Date: ...
   ============================================================

   [body content]
   ```
3. Report how many saved
4. This triggers the cron's file detection → auto-update pipeline

### `summary`
1. Get today's emails (or unread if specified)
2. Read the body of each
3. Generate an AI summary:
   - Key decisions made
   - Action items for you
   - Meetings scheduled
   - FYIs / newsletters (skip detail)
4. Group by project relevance if possible

### `reply-draft <subject>`
1. Find the email by subject
2. Read its full content
3. Ask user what they want to say in reply
4. Draft a professional reply
5. Show the draft — user can copy/paste into Outlook

### `folders`
1. List all mail folders with message counts
2. Show as table: Folder | Messages | Unread

### `triage` (Legacy Outlook only — needs mark-as-read)
Mechanically de-noises the inbox using the **curated rules file**, never your own judgment.

1. **Dump** the first 200 inbox messages as TSV (`idx \t U|R \t sender_addr \t subject`):
   ```applescript
   tell application "Microsoft Outlook"
       set out to {}
       set i to 0
       set msgs to messages 1 thru 200 of inbox
       repeat with m in msgs
           try
               set i to i + 1
               set s to sender of m
               set flag to "R"
               if (is read of m) is false then set flag to "U"
               set end of out to ((i as text) & "	" & flag & "	" & (address of s) & "	" & (subject of m))
           end try
       end repeat
       set AppleScript's text item delimiters to linefeed
       set t to out as text
       set AppleScript's text item delimiters to ""
       return t
   end tell
   ```
2. **Classify** by piping that dump into the shared classifier (deterministic, rule-driven):
   ```bash
   <dump> | python3 ~/.coco/email-triage.py
   ```
   It emits `AUTO` / `PROPOSE` / `PROTECT` lines + a `#SUMMARY`. See `~/.coco/email-noise-rules.yaml`.
3. **Auto-mark** every `AUTO` line read. Mark by matching first UNREAD message whose `address of sender` + `subject` equal the line's (robust against index drift); do NOT trust the raw index across calls:
   ```applescript
   -- for each (addr, subj) to mark:
   repeat with m in (messages 1 thru 200 of inbox)
       try
           if (is read of m) is false and (address of sender of m) is "ADDR" and (subject of m) is "SUBJ" then
               set is read of m to true
               exit repeat
           end if
       end try
   end repeat
   ```
4. **Show** the `PROPOSE` lines as a table (Date | From | Subject | rule_id) — these are candidates, NOT marked. Ask which to mark, and offer to promote a rule to `auto` if trusted.
5. **Report**: N auto-marked (grouped by rule), N proposed, N protected, remaining unread count.

NEVER mark anything not emitted as `AUTO`. If a message matched a noise rule but is `PROTECT`, surface it explicitly — it stays unread.

### `noise` — manage the rules
- **`noise`** (no args): print the current rules grouped by tier (`auto` / `propose`) + `protect`, with id, match, reason.
- **`noise add <tier> <field>=<value> [reason: ...]`**: append a rule to `~/.coco/email-noise-rules.yaml`.
  - `<tier>` ∈ `auto` | `propose`. Default new rules to **propose** unless the user says auto.
  - `<field>` ∈ `sender_equals` | `sender_contains` | `sender_regex` | `subject_startswith` | `subject_contains`.
  - Generate a kebab-case `id`, set `added:` to today's date, write `reason:`.
  - After writing, re-read the file to confirm it parses (it's the source of truth).
- **`noise protect <field>=<value>`**: add a protect entry (sender or subject) — always-keep override.

**Rules file** = `~/.coco/email-noise-rules.yaml` (schema documented in-file). It is **manually curated and continuous**: start rules in `propose`, promote to `auto` only once trusted, delete anything wrong. The classifier `~/.coco/email-triage.py` only ever does what the file says — it cannot invent noise.

---

## New Outlook (MIME) Mode

New Outlook stores mail in a proprietary binary index (`HxStore.hxd`) with no AppleScript or local API. There is **no clean full-inbox read** — extract best-effort from the on-disk caches below, in priority order.

**Paths** (under `~/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/Files/S0/4/`):
- `MimeFiles/` — full RFC822 messages (cleanest, but **often empty** — not every install populates it).
- `Attachments/0/*.eml` — received/forwarded messages saved as clean RFC822 `.eml` (reliable when present).
- `HxStore.hxd` (one level up, in `Main Profile/`) — the real store; binary, no per-message delimiters. `strings` + grep yields sender/subject fragments only (last resort, messy).

**Approach** (covers `read`, `search`, `today`, `this-week`, `thread`, `summary`, `save`):
```bash
P="$HOME/Library/Group Containers/UBF8T346G9.Office/Outlook/Outlook 15 Profiles/Main Profile/Files/S0/4"
# Tiers 1+2: clean RFC822 from MimeFiles + .eml attachments, most-recent first.
# Use find (not a glob) so it is portable across bash/zsh and survives an empty MimeFiles dir.
{ find "$P/MimeFiles" -type f -print0 2>/dev/null; find "$P/Attachments/0" -maxdepth 1 -name '*.eml' -print0 2>/dev/null; } \
  | xargs -0 ls -t 2>/dev/null | head -200 | while IFS= read -r f; do
  subj=$(grep -a -m1 -i '^Subject:' "$f"); [ -z "$subj" ] && continue
  from=$(grep -a -m1 -i '^From:' "$f"); date=$(grep -a -m1 -i '^Date:' "$f")
  printf '%s\t%s\t%s\t%s\n' "$date" "$from" "$subj" "$f"
done
# Tier 3 (only if the above returns nothing): subject/sender awareness from the binary store
#   strings "$P/../../HxStore.hxd" | grep -aiE '^(Subject|From):' | head -50
```
- Filter by sender (`read <name>`), keyword (`search`), or date (`today`/`this-week`). Body/`summary`: parse the matched file. `save <query> to <folder>`: copy the matched file into the target folder.

**Limitations on New Outlook (state honestly — do not guess):**
- This is **partial, not the full inbox**: `MimeFiles/` is frequently empty, and `.eml` attachments only cover received/forwarded messages. For complete access, use Legacy Outlook or the Microsoft Graph API — say so rather than implying full coverage.
- `unread` count / read state, `folders`, mark-as-read, and sending a `reply-draft` need the app API — unavailable. For `reply-draft`, still draft text for copy/paste.
- `HxStore.hxd` is binary; never present its raw `strings` dump as if it were clean email — use it only for awareness.

---

## Performance Notes

- AppleScript iteration is O(n) — searching 7000+ messages is slow
- Default search depth: 500 messages for quick commands, 2000 for `search`
- Always stop early when enough results found (exit repeat)
- For `today` and `this-week`, stop when date is older than target (messages are date-sorted)
- Use `messages 1 thru N` not `every message` to avoid loading entire mailbox

## Error Handling

- If Outlook is not running: `tell application "Microsoft Outlook" to activate` then retry
- If sender access fails: fall back to subject-only display
- If body is empty: try `content of msg` as fallback
- Timeout: 120 seconds per AppleScript call

© coco-research · MIT · coco-research/coco

Similar slash commands

All slash commands for Notes, tasks and projects →

_index by other authors comes first.

From the same set82

The whole set →
arch-index Builds a validated map of repository components in .arch/index.json and checks it for drift against the code. Use it to trace a component to its files or review structural changes after a refactor. CX Codex +1 ★ 328repo stars hyperframes-keyframes hyperframes-keyframes keeps HyperFrames motion seekable: builds keyframes for GSAP, CSS, Anime.js and WAAPI, then verifies frames before a render. CX Codex +1 ★ 328repo stars pmstudio-meeting-notes pmstudio-meeting-notes converts call transcripts into structured Markdown meeting notes. Cross-references people against stakeholder tables, logs decisions, and flags PRD updates. CX Codex +1 ★ 328repo stars hyperframes-cli The hyperframes-cli skill guides HyperFrames projects from composition checks to preview and rendering. It also helps diagnose build and render failures. CX Codex +1 ★ 328repo stars brain:wiki brain:wiki is a Claude Code skill that searches, generates, and merges articles about people, systems, and teams from a distributed knowledge graph. CX Codex +1 ★ 328repo stars hyperframes Entry point for building video, animation and motion graphics in Claude, taking a brief or a URL through to a finished HyperFrames composition. CX Codex +1 ★ 328repo stars code-verification code-verification runs a mechanical 7-category audit on code changes. Catches temporal dead zone bugs, import mismatches, dead code, and React state mistakes. CX Codex +1 ★ 328repo stars openai-agents Guides building text and voice workflows with the OpenAI Agents SDK, schemas, and multi-agent handoffs without common runtime traps. CX Codex +1 ★ 328repo stars

Project sponsors

Companies that keep this analytics open