| name | gmail-organize |
| description | Organize the user's Gmail: apply and remove labels, archive, mark read or unread, star, move to trash or restore, and manage the label list itself. Use when the user asks to label, tag, file, sort, archive, clean up, triage, or clear their inbox, to mark mail as read, to star something, or to delete or restore messages. Works on single messages or whole threads. |
gmail-organize
gmail label list | create <name> | delete <name>
gmail modify <id...> [--add L] [--remove L] [--action archive|read|star|...]
[--trash] [--untrash] [--thread] [--create] [--dry-run]
--json gives the Envelope. modify takes many ids at once.
Gmail has no folders
Everything is a label, including the states that look like something else. modify
exposes the readable verb and performs the underlying edit:
--action | What Gmail actually does |
|---|
archive | remove INBOX |
unarchive | add INBOX |
read / unread | remove / add UNREAD |
star / unstar | add / remove STARRED |
spam / unspam | add / remove SPAM |
--action repeats, and composes with --add and --remove:
gmail modify 1932ab... --action read --action archive
gmail modify 1932ab... 1932cd... --add work --remove INBOX
Labels resolve by name, case-insensitively, or by id. A name that does not exist is an
error, never a silent no-op, so a typo cannot quietly apply nothing to a hundred messages.
Pass --create when you mean to create it:
gmail modify 1932ab... --add follow-up --create
Nested labels use a slash: clients/acme.
Threads
--thread treats the ids as thread ids and acts on every message in the conversation.
That is usually what a user means by "archive that thread".
gmail modify 1932ab... --thread --action archive
Deleting
--trash moves to Trash, where Gmail keeps it for 30 days and --untrash brings it back.
There is deliberately no permanent-delete command here. If the user genuinely wants mail
gone forever, tell them to empty Trash in Gmail themselves.
Confirm before trashing anything you were not explicitly told to trash, and always
confirm before trashing in bulk.
Working in bulk
Search first, then act on the ids. Check the set before you change it.
gmail search "from:newsletter@example.com older_than:30d" --max 50 --json \
| jq -r '.data.messages[].id' > /tmp/ids.txt
gmail modify $(cat /tmp/ids.txt) --action archive --dry-run
--dry-run reports exactly which labels would be added and removed, and touches nothing.
Use it on every bulk operation, show the count to the user, and only then run it for real.
A bulk archive is recoverable; a bulk trash is recoverable for 30 days; a bulk label
change is a tedious afternoon to undo by hand.
Do not decide on your own what deserves archiving or trashing. Triage rules come from the
user, not from your read of what looks unimportant.
Managing labels
gmail label list
gmail label create "follow-up"
gmail label delete "follow-up"
Creating a label that already exists reports exists and is not an error. System labels
(INBOX, UNREAD, STARRED) cannot be deleted, and deleting a user label removes the
label from every message but never deletes the messages.
If a command fails, read error.hint; for anything auth-shaped, run gmail doctor.