googleworkspace avatar

Recipe Create Gmail Filter

A straightforward recipe for setting up Gmail filters through the command line using Google Workspace tools. You'll create labels, define filter criteria based on sender or subject patterns, and specify actions like auto-labeling or starring messages. The four-step process covers listing existing labels, creating new ones, building the actual filter with JSON criteria, and verifying it worked. Most useful when you need to automate email organization at scale or integrate Gmail filtering into larger workflow scripts. The commands are clean and the JSON structure is simple enough to modify for different filter rules.

skills.sh installs
32K
GitHub stars
32.2K
last updated
Aug 21, 2026

Install

$ npx -y skills add googleworkspace/cli --skill recipe-create-gmail-filter --agent claude-code

Installs into .claude/skills of the current project.

Files

Create a Gmail Filter

PREREQUISITE: Load the following skills to execute this recipe: gws-gmail

Create a Gmail filter to automatically label, star, or categorize incoming messages.

Steps

  1. List existing labels: gws gmail users labels list --params '{"userId": "me"}' --format table
  2. Create a new label: gws gmail users labels create --params '{"userId": "me"}' --json '{"name": "Receipts"}'
  3. Create a filter: gws gmail users settings filters create --params '{"userId": "me"}' --json '{"criteria": {"from": "receipts@example.com"}, "action": {"addLabelIds": ["LABEL_ID"], "removeLabelIds": ["INBOX"]}}'
  4. Verify filter: gws gmail users settings filters list --params '{"userId": "me"}' --format table

Sponsors

Details

Repository
github.com/googleworkspace/cli
Categories
CLI & Terminal, Office & Documents

More from googleworkspace/cli

All 113
1googleworkspace avatarrecipe-save-email-attachmentsgoogleworkspace/cliFind Gmail messages with attachments and save them to a Google Drive folder.31.8Kskills.sh installs
2googleworkspace avatarrecipe-backup-sheet-as-csvgoogleworkspace/cliExport a Google Sheets spreadsheet as a CSV file for local backup or processing.31.7Kskills.sh installs
3googleworkspace avatarrecipe-organize-drive-foldergoogleworkspace/cliCreate a Google Drive folder structure and move files into the right locations.31.7Kskills.sh installs
4googleworkspace avatarpersona-exec-assistantgoogleworkspace/cliManage an executive's schedule, inbox, and communications.31.6Kskills.sh installs
5googleworkspace avatarrecipe-find-free-timegoogleworkspace/cliQuery Google Calendar free/busy status for multiple users to find a meeting slot.31.5Kskills.sh installs
6googleworkspace avatarrecipe-compare-sheet-tabsgoogleworkspace/cliRead data from two tabs in a Google Sheet to compare and identify differences.31.5Kskills.sh installs