Skip to content

the3asic/google-workspace-skill

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 

Repository files navigation

Google Workspace Skill

Claude Code skill for managing Google Calendar and Gmail through Python code execution.

Structure

google-workspace/              # Deploy this folder to ~/.claude/skills/
├── SKILL.md                  # Core skill instructions for Claude
├── scripts/
│   └── unified_auth.py      # OAuth authentication tool
└── references/              # Detailed API documentation
    ├── calendar-api.md      # Google Calendar API reference
    └── gmail-api.md         # Gmail API reference

Key Principle: Data processing happens in sandbox (Python execution), not in Claude's context. This reduces token consumption significantly.

Quick Start

1. Deploy Skill

cp -r google-workspace ~/.claude/skills/

2. Install Dependencies

mkdir -p ~/.google-workspace
python3 -m venv ~/.google-workspace/venv
source ~/.google-workspace/venv/bin/activate
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client
deactivate

3. Get OAuth Credentials

  1. Visit Google Cloud Console
  2. Create or select a project
  3. Enable Google Calendar API and Gmail API
  4. Navigate to: APIs & Services → Credentials → Create Credentials
  5. Choose OAuth 2.0 Client IDDesktop application
  6. Download the credentials JSON file
  7. Save it as ~/.google-workspace/credentials.json

4. Authenticate

cd ~/.claude/skills/google-workspace
source ~/.google-workspace/venv/bin/activate
python3 scripts/unified_auth.py

The script will:

  • Automatically open your browser for OAuth authorization
  • Save the access token to ~/.google-workspace/token.json
  • Test both Calendar and Gmail API connections
  • Display success confirmation

First-time only: Click "Allow" in the browser when prompted.

Usage

Once deployed, Claude Code automatically uses this skill when you mention calendars or emails:

Calendar Examples

"Show me this week's meetings"
"What's on my calendar for tomorrow?"
"Create a meeting with John at 3pm tomorrow"
"List all my calendars"

Gmail Examples

"What unread emails do I have?"
"Send an email to john@example.com"
"Search for emails from Sarah about project"
"Archive all emails from newsletter@example.com"

Combined Examples

"Generate a weekly report and email it to my manager"
"Find all meeting invites in my inbox and add them to calendar"

How It Works

Traditional MCP Approach (High Token Cost)

User request → MCP tool call → Full JSON response (6000+ tokens)
→ Data enters context → Process in context → Output

This Skill (Low Token Cost)

User request → Claude writes Python code (~200 tokens)
→ Execute in sandbox → Process data locally
→ Return summary only (~300 tokens) → Output

Result: ~94% token savings on typical operations.

Features

Calendar Operations

  • List: Get events from all calendars, specific date ranges
  • Create: Add new events with attendees, reminders
  • Update: Modify existing events
  • Delete: Remove events
  • Utilities: Check free/busy status, list available colors
  • Multi-calendar: Automatically queries all user calendars

Gmail Operations

  • Send: Compose and send emails (plain text or HTML)
  • Search: Use Gmail query syntax for powerful searches
  • Read: Fetch email content with metadata
  • Batch: Modify/delete multiple emails efficiently
  • Labels: Create, update, and manage labels
  • Drafts: Create and manage draft emails

Automation

  • Environment Detection: Automatically checks and creates venv if missing
  • Token Management: Auto-refresh expired tokens
  • Error Handling: Graceful fallbacks for API errors
  • Zero Configuration: No environment variables required

File Locations

All runtime files are stored in ~/.google-workspace/:

~/.google-workspace/
├── venv/                    # Python virtual environment
├── token.json              # OAuth access token (auto-refreshed)
└── credentials.json        # OAuth client credentials

Token Refresh

Tokens expire after ~7 days. When you see authentication errors:

cd ~/.claude/skills/google-workspace
source ~/.google-workspace/venv/bin/activate
python3 scripts/unified_auth.py

The script will guide you through re-authorization.

Security Notes

  • Token files have 600 permissions (owner read/write only)
  • Never commit credentials.json or token.json to git
  • Credentials are stored locally, not in cloud
  • OAuth uses industry-standard security practices

API References

Detailed API documentation is available in the references/ directory:

These are loaded by Claude only when needed (progressive disclosure).

Troubleshooting

"ModuleNotFoundError: No module named 'google'"

Install dependencies in the virtual environment:

source ~/.google-workspace/venv/bin/activate
pip install google-auth google-auth-oauthlib google-auth-httplib2 google-api-python-client

"Token invalid" or "Authentication expired"

Re-run the authentication script:

python3 ~/.claude/skills/google-workspace/scripts/unified_auth.py

"API not enabled"

Enable required APIs in Google Cloud Console:

  1. Visit API Library
  2. Search for "Google Calendar API" and "Gmail API"
  3. Click "Enable" for each

Technical Details

Code Execution Pattern

Claude generates Python code following this template:

source ~/.google-workspace/venv/bin/activate && python3 << 'EOF'
from google.oauth2.credentials import Credentials
from googleapiclient.discovery import build

# Load credentials
token_path = '~/.google-workspace/token.json'
creds = Credentials.from_authorized_user_file(token_path)

# Build service
calendar = build('calendar', 'v3', credentials=creds)

# Query and process data in sandbox
events = calendar.events().list(...).execute()
# ... filter, sort, aggregate ...

# Return only summary
print(f"Found {len(events)} events")
EOF

Multi-Calendar Support

The skill automatically queries all user calendars, not just the primary calendar:

calendars = calendar.calendarList().list().execute()['items']
for cal in calendars:
    events = calendar.events().list(calendarId=cal['id'], ...).execute()
    # Process events from each calendar

References

Official Documentation

Claude Documentation

Source References

This skill consolidates functionality from:

License

MIT

Contributing

Issues and pull requests are welcome! Please ensure:

  • Code follows existing patterns
  • Python code is executed in sandbox (not imported)
  • Documentation is updated for new features

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages