gws-gmail-watch
googleworkspace/cli
Watch Gmail for new emails and stream them as NDJSON in real-time.
What is gws-gmail-watch?
Monitors a Gmail account for incoming emails and outputs them as newline-delimited JSON. Use this to integrate Gmail into automated workflows, trigger actions on new messages, or build custom email processing pipelines.
- Stream new emails as NDJSON for real-time processing
- Filter emails by Gmail label IDs (INBOX, UNREAD, etc.)
- Configure message format (full, metadata, minimal, raw)
- Pull emails in batches with configurable intervals
- Write each message to separate JSON files
- Gracefully handle watch expiration and reconnection
How to install gws-gmail-watch
npx skills add null --skill gws-gmail-watch- Google Workspace account with Gmail enabled
- GCP project with Pub/Sub API enabled
- gws CLI installed and authenticated (see gws-shared skill)
- Appropriate Gmail API permissions granted
How to use gws-gmail-watch
- 1.Run `gws gmail +watch --project YOUR_GCP_PROJECT` to start watching for new emails
- 2.Optionally add `--label-ids INBOX,UNREAD` to filter specific labels
- 3.Use `--once` flag to pull messages once and exit, or omit to stream continuously
- 4.Add `--output-dir ./emails` to write each message to a separate JSON file
- 5.Press Ctrl-C to stop gracefully; use `--cleanup` to delete Pub/Sub resources on exit
Use cases
- Trigger automated workflows when new emails arrive in specific labels
- Export incoming emails to a data pipeline or logging system
- Monitor unread emails and stream them to a notification system
- Archive email metadata to a file-based system for analysis
- Integrate Gmail with custom chatbots or AI agents that need email context
- Automation engineers building email-triggered workflows
- Developers integrating Gmail with custom applications
- DevOps teams monitoring email-based alerts
- Data engineers processing email streams
gws-gmail-watch FAQ
Gmail watch expires after 7 days. Re-run the command to renew the watch.
By default, Pub/Sub resources persist for reconnection. Use `--cleanup` flag to delete them on exit.
Yes, use `--label-ids` with comma-separated Gmail label IDs like `INBOX,UNREAD` to filter specific labels.
Four formats: `full` (default, complete message), `metadata` (headers only), `minimal` (basic info), and `raw` (RFC 2822 format).
Yes, use `--output-dir ./path` to write each message to a separate JSON file in that directory.
Full instructions (SKILL.md)
Source of truth, from googleworkspace/cli.
name: gws-gmail-watch description: "Gmail: Watch for new emails and stream them as NDJSON." metadata: version: 0.22.5 openclaw: category: "productivity" requires: bins: - gws cliHelp: "gws gmail +watch --help"
gmail +watch
PREREQUISITE: Read
../gws-shared/SKILL.mdfor auth, global flags, and security rules. If missing, rungws generate-skillsto create it.
Watch for new emails and stream them as NDJSON
Usage
gws gmail +watch
Flags
| Flag | Required | Default | Description |
|---|---|---|---|
--project | — | — | GCP project ID for Pub/Sub resources |
--subscription | — | — | Existing Pub/Sub subscription name (skip setup) |
--topic | — | — | Existing Pub/Sub topic with Gmail push permission already granted |
--label-ids | — | — | Comma-separated Gmail label IDs to filter (e.g., INBOX,UNREAD) |
--max-messages | — | 10 | Max messages per pull batch |
--poll-interval | — | 5 | Seconds between pulls |
--msg-format | — | full | Gmail message format: full, metadata, minimal, raw |
--once | — | — | Pull once and exit |
--cleanup | — | — | Delete created Pub/Sub resources on exit |
--output-dir | — | — | Write each message to a separate JSON file in this directory |
Examples
gws gmail +watch --project my-gcp-project
gws gmail +watch --project my-project --label-ids INBOX --once
gws gmail +watch --subscription projects/p/subscriptions/my-sub
gws gmail +watch --project my-project --cleanup --output-dir ./emails
Tips
- Gmail watch expires after 7 days — re-run to renew.
- Without --cleanup, Pub/Sub resources persist for reconnection.
- Press Ctrl-C to stop gracefully.
See Also
- gws-shared — Global flags and auth
- gws-gmail — All send, read, and manage email commands
Related skills
More from googleworkspace/cli and the wider catalog.
gws-gmail
Send, read, and manage Gmail emails via Google Workspace CLI.
gws-drive
Manage Google Drive files, folders, and shared drives via CLI.
gws-docs
Read and write Google Docs via command line.
gws-calendar
Manage Google Calendar events, calendars, and access control via CLI.
gws-sheets
Read and write Google Sheets spreadsheets via CLI.
gws-gmail-send
Send emails via Gmail with attachments, CC/BCC, HTML support, and draft options.