AI-powered Gmail inbox classifier using Claude API.
- Monitors Gmail inbox in real-time
- Classifies emails into dynamic categories using Claude AI
- Applies Gmail labels and archives classified emails
- Skip rules let actionable emails stay in your inbox untouched
- Categories and rules are fully customizable via
rules.md - Logs all classification decisions
gh repo clone longrackslabs/inbox-classifier
cd inbox-classifier
python -m venv .venv
source .venv/bin/activate
pip install -e .- Go to https://console.cloud.google.com/
- Create new project: "Inbox Classifier"
- Enable Gmail API
- Create OAuth 2.0 credentials (Desktop app)
- Download credentials as
credentials.json - Place
credentials.jsonin project root
See docs/setup-gmail.md for detailed instructions.
- Get API key from https://console.anthropic.com/
- Create
.envfile in project root:
ANTHROPIC_API_KEY=your_api_key_here
inbox-classifierOr: python -m inbox_classifier.main
First run will open browser for Gmail authentication.
The service runs continuously and:
- Checks for new unread emails every 60 seconds
- Skips emails matching skip rules (leaves them in inbox, marks as read to avoid reprocessing)
- Classifies remaining emails using Claude AI
- Applies a Gmail label and archives (removes from inbox)
- Logs decisions to
~/.inbox-classifier/classifications.jsonl - Service log at
~/.inbox-classifier/service.log
Rules live in ~/.inbox-classifier/rules.md (created on first run with defaults). See rules.md.example for a full example. The service re-reads this file every cycle — no restart needed.
Define categories with the format CategoryName emails include:. Use number prefixes to control Gmail label sort order:
0_Important emails include:
- Security: password resets, security alerts, 2FA codes
- Personal: real people asking questions
- Action required: needs response or follow-up
1_Routine emails include:
- Monthly statements, balance updates
- Automated confirmations that don't need action
2_Receipts emails include:
- Purchase receipts and transaction confirmations
- Order confirmations with itemized details
3_Optional emails include:
- Newsletters: regular updates, digests
- Notifications: social media, app updates
4_Ads emails include:
- Promotional: sales, deals, marketing campaigns
- Marketing emails with discount codesNote: "Important" is a reserved Gmail label name. Use a prefix like 0_Important.
Emails matching skip rules are left in your inbox untouched — no AI call, no label, no archive. Use this for emails that need manual action (eBay sales, bills, etc.).
Skip classification for:
- from:ebay@ebay.com
- from:notifications@ebay.com
- subject:Your item sold
- subject:Payment receivedfrom:— case-insensitive substring match on sendersubject:— case-insensitive substring match on subject- Skipped emails stay in your inbox but are marked as read to prevent reprocessing
- No Claude API calls are made for skipped emails (saves cost)
Store your rules.md in a private GitHub repo so you can train the classifier from any machine.
- Create a private repo (e.g.,
longrackslabs/inbox-rules) with yourrules.mdat the root - Create a GitHub personal access token with
reposcope - Add to your
.env:
RULES_REPO=longrackslabs/inbox-rules
GITHUB_TOKEN=ghp_your_token_here
The service fetches rules.md from GitHub each cycle and caches it locally. If GitHub is unreachable, the last cached version is used.
From any machine with Claude Code and git access to the rules repo:
- Clone the rules repo:
git clone git@github.com:longrackslabs/inbox-rules.git - Edit
rules.mdusing Claude Code training workflow - Commit and push — service picks up changes within 60 seconds
If RULES_REPO is not set, the service reads from ~/.inbox-classifier/rules.md (original behavior).
Ask Claude Code questions like:
- "Show me what emails were classified today"
- "How many emails were marked as optional this week?"
- "Show me the classification log"
- "reset" — resets all classified emails back to inbox as unread
Claude Code can read ~/.inbox-classifier/classifications.jsonl to answer.
Say "reset" to Claude Code to reprocess all classified emails. This will:
- Find all messages with classifier labels (0_Important, 1_Routine, etc.)
- Remove those labels
- Add INBOX and UNREAD labels back
The service will reclassify them on its next polling cycle. Useful after updating rules.md to see how new rules affect existing emails.
See docs/launchd-setup.md for setting up automatic startup.
- ~$0.0015 per email classified (skipped emails are free)
- 50 emails/day = ~$2.25/month
- 100 emails/day = ~$4.50/month