Auto-label Gmail emails into Action Required, Waiting On, and Reference categories. Use when user asks to label emails, triage inbox, categorize emails, or organize Gmail.
Fetch inbox emails, classify them via parallel subagents into Action Required / Waiting On / Reference, and apply labels in bulk via Gmail API.
./scripts/gmail_label_fetch.py - Fetch email summaries as compact JSON./scripts/gmail_label_split.py - Split emails into N chunks for parallel classification./scripts/gmail_label_merge.py - Merge classified chunks into single labels.json./scripts/gmail_label_apply.py - Apply label classifications in bulkemail-classifier — defined in .claude/agents/email-classifier.mdpython3 .claude/skills/gmail-label/scripts/gmail_label_fetch.py \
--account ACCOUNT --query "in:inbox" --limit 100 --output .tmp/emails.json
python3 .claude/skills/gmail-label/scripts/gmail_label_split.py \
--input .tmp/emails.json --chunks 10 --output-dir .tmp/chunks
Spawn 10 email-classifier subagents in background, one per chunk. Each subagent:
.tmp/chunks/chunk_N.json.tmp/chunks/classified_N.jsonUse the Task tool with run_in_background: true and model: "sonnet". Launch ALL 10 in a single message for true parallelism:
For each chunk 0-9, spawn a Task with:
subagent_type: "email-classifier"
model: "sonnet"
run_in_background: true
prompt: "Read /absolute/path/.tmp/chunks/chunk_N.json, classify each email, write results to /absolute/path/.tmp/chunks/classified_N.json"
CRITICAL: Do NOT use TaskOutput to read subagent results. The subagents write their results to files — the main agent never needs to see the classification data. Reading TaskOutput will flood the context window and cause "prompt too long" errors with large batches (500+ emails).
Instead, poll for file existence:
# Wait until all classified files exist (timeout after 120s)
for i in $(seq 0 9); do
while [ ! -f ".tmp/chunks/classified_$i.json" ]; do sleep 2; done
done
Then proceed directly to Step 4 (merge).
python3 .claude/skills/gmail-label/scripts/gmail_label_merge.py \
--input-dir .tmp/chunks --output .tmp/labels.json
python3 .claude/skills/gmail-label/scripts/gmail_label_apply.py \
--account ACCOUNT --input .tmp/labels.json
Action Required:
Waiting On:
Reference:
Accounts are stored in gmail_accounts.json at workspace root. Each account needs:
email - Gmail addresstoken_file - Path to OAuth tokenpython3 .claude/skills/gmail-inbox/scripts/gmail_multi_auth.py --account ACCOUNT_NAME --email EMAIL
| Name | Type | Required | Description |
|---|---|---|---|
account | string | Yes | Gmail account name from registry |
query | string | No | Gmail search query (default: 'in:inbox') |
limit | integer | No | Max emails to classify (default: 100) |
chunks | integer | No | Parallel classification chunks (default: 10) |
| Name | Type | Description |
|---|---|---|
labels_applied | object | Count per category: Action Required, Waiting On, Reference |
| Name | Source |
|---|---|
credentials.json | file |
token_*.json | file (auto-generated) |
Skills that chain well with this one: gmail-inbox
Claude Sonnet API for classification