This document contains instructions for working with the Gmail Inbox Summary project using Claude Code CLI.
Gmail Inbox Summary is a Python application that generates AI-powered summaries of Gmail inbox threads using configurable categorization and Claude Code CLI integration. The project uses Hatch as its build tool and package manager.
This project uses Hatch for dependency management and task execution. Always use Hatch commands when working with this project:
# Install dependencies and create environment
hatch env create
# Enter the development shell
hatch shellAlways use hatch run to execute the application:
# Generate email summary
hatch run gmail-summary run
# Run with specific configuration
hatch run gmail-summary run --config settings.yml
# Test Claude CLI connection
hatch run gmail-summary test-claude
# Clear cache (useful when data structures change)
hatch run gmail-summary cache clearBefore making commits, always run linting and tests:
# Run all linting checks
hatch run lint:all
# Run just the linting (faster)
hatch run lint:check
# Fix linting issues automatically
hatch run lint:fix
# Format code with Ruff
hatch run ruff format
# Run all tests
hatch run test
# Run tests with coverage
hatch run test-covALWAYS run tests and linters before committing. This project uses pre-commit hooks that will enforce these checks, but run them manually first to catch issues early.
Required steps before committing changes:
-
Run all linters and tests:
# Run all linting checks and tests (required before committing) hatch run lint:all hatch run test
-
Fix any linting issues:
# Fix automatic formatting issues hatch run lint:fix # Manually fix any remaining issues reported by lint:all
-
Only add the files you actually modified:
git add src/gmail_summarizer/file1.py src/gmail_summarizer/file2.py
-
Commit with descriptive messages following the established pattern.
gmail-inbox-summary/
├── src/gmail_summarizer/
│ ├── config.py # Configuration management
│ ├── imap_gmail_client.py # Gmail IMAP integration
│ ├── credential_manager.py # Secure keychain credential storage
│ ├── thread_processor.py # Thread categorization and date extraction
│ ├── llm_summarizer.py # Claude CLI integration
│ ├── html_generator.py # HTML report generation and template rendering
│ └── main.py # CLI interface
├── templates/
│ └── summary.html # Jinja2 HTML template
├── tests/ # Comprehensive test suite
├── config/ # Example configurations
└── pyproject.toml # Project configuration
- Date Extraction: The
_extract_most_recent_date()method extracts timestamps from Gmail message data - Data Sources: Uses Gmail API
internal_datefield first, then falls back to parsingDateheaders - Timestamp Format: Returns millisecond timestamps as integers for consistent sorting
- Thread Sorting: Threads are sorted by importance first, then by most recent date (newest first)
- Template Context: The
_prepare_template_context()method handles data preparation for Jinja2 - Date Formatting: Custom
format_datefilter provides smart date formatting (time for today, month/day for this year, full date for older messages)
- Responsive Design: Mobile-friendly layout with collapsible categories
- Date Display: Shows formatted dates next to thread titles in the metadata section
- Interactive Features: JavaScript for category expansion/collapse and keyboard navigation
- Identify the appropriate module based on functionality
- Add tests for new functionality first (TDD approach)
- Implement the feature
- Update templates if UI changes are needed
- Run linting and tests before committing
- Use the
--verboseflag for detailed logging - Use
--dry-runto test categorization without generating summaries - Clear cache if data structures have changed:
hatch run gmail-summary cache clear - Check Gmail API data format in debug logs
- Templates use Jinja2 with custom filters defined in
html_generator.py - CSS is embedded in the template for self-contained output
- Test template changes by regenerating reports with sample data
The application uses intelligent caching for performance. When modifying data extraction or processing logic:
# Clear cache to ensure fresh data extraction
hatch run gmail-summary cache clearThis is especially important when:
- Adding new fields to thread or message data
- Changing date extraction logic
- Modifying categorization criteria
- Python Version: 3.12+ required
- Package Manager: Hatch (do not use pip directly)
- Main Dependencies: Jinja2, PyYAML, BeautifulSoup4, python-dateutil, Click, Rich, Keyring, Pydantic
- Development Dependencies: pytest, pytest-cov, ruff, black, mypy, pre-commit
- Always use Hatch: Run
hatch runfor all Python commands - Test before commit: Run
hatch run lint:allANDhatch run testbefore every commit - Fix all issues: Address all linting and test failures before committing
- Clear cache when needed: Use
hatch run gmail-summary cache clearafter data structure changes - Follow existing patterns: Study existing code structure before adding features
- Use descriptive commit messages: Follow the established format with clear descriptions
- Only commit modified files: Use
git addwith specific file paths
This project is designed to work seamlessly with Claude Code CLI:
- The application uses Claude Code CLI for generating email summaries
- Configuration includes Claude CLI path and timeout settings
- Test Claude connection with:
hatch run gmail-summary test-claude
Recent improvements include:
- Thread Sorting: Implemented reverse chronological order (newest first) within categories
- Date Extraction: Added robust date parsing from Gmail API data with fallback mechanisms
- Date Display: Added formatted date display next to thread titles in HTML output
- Smart Formatting: Dates show as time (if today), month/day (if this year), or full date (if older)
This enhancement improves user experience by making it easy to identify recent email activity at a glance.