/gws:gws-authfrom gws
Manages OAuth2 authentication for the gws Google Workspace CLI, including login, logout, service-account modes, and credential troubleshooting.
Ships in gws. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
gws auth manages OAuth2 authentication for all Google Workspace services.
Disclaimer:
gwsis not the official Google CLI. This is an independent, open-source project not endorsed by or affiliated with Google.
Before executing any gws command, verify the CLI is installed:
gws version
If not found, install: go install github.com/omriariav/workspace-cli/cmd/gws@latest
| Task | Command |
|---|---|
| Check auth status | gws auth status |
| Login (all scopes) | gws auth login |
| Login (specific services) | gws auth login --services gmail,calendar,chat |
| Login read-only | gws auth login --readonly |
| Login read-only for some services | gws auth login --services gmail,drive --readonly |
| Add a service to the existing login | gws auth login --add --services tasks |
| Use an existing access token | GWS_ACCESS_TOKEN=<token> gws gmail list |
Scopes gws auth login requests for a command's service | gws gmail send --show-scopes |
| Describe a command's flags as JSON | gws gmail send --schema |
| Login with credentials | gws auth login --client-id <id> --client-secret <secret> |
| Logout (revokes token) | gws auth logout |
Besides the default interactive OAuth flow, gws supports two explicit
service-account modes via auth_mode (GWS_AUTH_MODE or config file).
Modes are mutually exclusive and validated fail-closed with actionable
errors; key material is never persisted, printed, or echoed.
| Mode | Required settings | Behavior |
|---|---|---|
oauth (default) | none | Interactive OAuth2 + PKCE via gws auth login |
service-account-dwd | service_account_key_file (GWS_SERVICE_ACCOUNT_KEY_FILE) + impersonate_user (GWS_IMPERSONATE_USER) | Domain-wide delegation: the service account acts as the named Workspace user across all services |
service-account-app | service_account_key_file | Admin-approved Google Chat app credentials; limited to gws events subscriptions on individual Chat spaces — every other service command is rejected |
# Domain-wide delegation (requires DWD enabled for the service account
# and the scopes authorized in the Admin console)
export GWS_AUTH_MODE=service-account-dwd
export GWS_SERVICE_ACCOUNT_KEY_FILE=~/keys/sa.json
export [email protected]
gws gmail list # runs as the impersonated user, no login needed
# Chat app auth (events subscriptions only)
export GWS_AUTH_MODE=service-account-app
export GWS_SERVICE_ACCOUNT_KEY_FILE=~/keys/chat-app-sa.json
gws events subscriptions create --target //chat.googleapis.com/spaces/AAA ...
Notes:
gws auth login fails fast in service-account modes (no login needed);
gws auth status reports the configured mode instead of token state.impersonate_user, app mode with impersonate_user, or OAuth mode with
leftover service-account settings all produce clear errors.Start read-only and add write access only for the services that need it.
gws auth login --readonly # read-only, every service
gws auth login --services gmail,drive --readonly # read-only, two services
gws auth login --add --services gmail # later: upgrade gmail to full access
--readonly requests only read-only scopes. Commands that create, change,
or delete data then fail with an insufficient-scope error (exit code 3) and
a hint naming the login that grants write access.gws events subscriptions create, update, renew, reactivate and delete still work for
those targets after a read-only login that includes the events
service. Drive file and permission subscriptions need the
drive.metadata scope, and Meet subscriptions made with
--meet-created-scope need meetings.space.created; only a full
events login requests those.
Leave events out of --services if a read-only login must not manage
subscriptions.--add merges the selected services into the existing authorization
instead of replacing it. The consent screen asks for the previously
granted scopes again together with the new ones; if any previously
granted scope is missing from the result, a scope that was not requested
comes back, or a different Google account was chosen in the browser, the
login is rejected and nothing changes. To
switch accounts, run gws auth logout first. It requires --services (or a services list
in config), so it can never widen the request to every service. Without --add, a login replaces the previous
grant.auth status.gws auth logout (which revokes the
old grant) and then log in again with the narrower options. Check the
logout output: if it says "revoked": false, Google could not be
reached and the old grant may still be active; the local credentials
are deleted regardless, so remove the grant at
https://myaccount.google.com/permissions before relying on the narrower
login.gws auth status reports the access level per service — full,
readonly, partial (some write scopes were granted, others unticked)
or partial-readonly (some read scopes were unticked) — and
read_only: true only when no service holds a write scope.If another system already manages Google OAuth tokens (CI, a secrets broker,
a domain-wide-delegation token service), hand the token to gws directly:
export GWS_ACCESS_TOKEN="$(my-token-broker)"
gws calendar events --days 1
gws uses it as-is: it is never refreshed, stored, or printed. An expired
or under-scoped token surfaces the API error (exit code 3).--show-scopes
lists what gws auth login requests for the command's whole service
(plus any known endpoint-specific scope); it does not inspect the token
and is not the minimum for that one command. A default
gcloud auth print-access-token token, for example, has no Workspace
scopes.gws auth logout refuses to run while an external token is set: it
acts on the stored login, which may be a different account.config.yaml.GWS_ACCESS_TOKEN="", or
--access-token "") is an error: gws never falls back to the stored
login in that case. Unset the variable to use the stored login.chat build-cache, chat find-group and chat find-space refuse to
run, and chat members does not use the local name cache or the People
lookup that fills it: members come back as Chat reports them, so some
may lack display_name / email.gws hooks) never use it, and while it is set
they add no Workspace context at all: that context is gathered and
cached with the stored login, which may be a different account.--access-token <token> also works, but a flag value is visible in process
listings and shell history — prefer the environment variable.An expired stored token is refreshed under a lock file in the gws config
directory (~/.config/gws). If that lock cannot be created (read-only or
full directory), gws does not refresh and the command fails with "the
login lock is unavailable": refreshing without it could invalidate the
stored login for other gws processes. Make the directory writable, or
supply a token with GWS_ACCESS_TOKEN. Logging in again does not help.
The no-concurrent-refresh guarantee holds between gws binaries of this version or later. An older binary sharing the same config directory refreshes without the lock, so upgrade every copy that uses it.
Two global flags print JSON and exit without calling any Google API and without needing credentials:
gws drive share --schema # flags (name, type, default, required), usage, subcommands
gws drive share --show-scopes # full and read-only scopes of the command's service
--schema also shows whether the confirmation gate covers a command:
"sensitive": true (with an effect) when it always does, and
"sensitive_when": {"flag": "...", "effect": "..."} when it does only if
that flag is used. If only certain values of the flag trigger it, they are
listed as "values" (for example ["TRASH", "SPAM"] for
gmail label --add); any other value runs without confirmation. Where it
depends on the payload instead, the shape is
"sensitive_when": {"flags": ["..."], "condition": "...", "effect": "..."}
(for example sheets write, when a cell value is an empty string). Scope
output is per service, not per command.
Off by default. When turned on, commands that send messages, change sharing, or delete data ask for approval before they run.
export GWS_CONFIRM_SENSITIVE=1 # or confirm_sensitive: true in config.yaml
gws gmail send --to [email protected] --subject Hi --body Hello
# stderr: About to run: gws gmail send --body "Hello" --subject "Hi" --to "[email protected]"
# gws gmail send sends an email. Proceed? [y/N]:
1/true/yes/on and 0/false/no/off
(any case). If the setting is anything else (a typo, an empty value),
or the config file exists but cannot be read or parsed, gws cannot tell
whether the gate is on: sensitive commands are then refused until the
setting or file is fixed, or --yes is given.y/n from stdin.confirmation required instead of hanging. Ask the user for explicit
approval, then re-run the same command with --yes. Never add --yes
on your own initiative.delete, trash,
remove, clear, empty or batch-delete, in any service (including
content deletes such as docs delete-table-row or sheets clear).drive update --trashed, chat setup-space --members, calendar create --attendees, calendar update --add-attendees, calendar rsvp --message, drive approve / decline / cancel-approval --message, forms update --file, drive resolve-comment --content and
drive unresolve-comment --content, Drive commands given a
destination folder (drive upload --folder, drive create-folder --parent), and gmail label --add / gmail batch-modify --add-labels when the labels include TRASH or SPAM, and
docs replace, slides replace-text and sheets find-replace when
--replace is empty, and docs replace-named-range when --text is
empty (that deletes every match), and sheets write / sheets batch-write when a cell value is an empty string (that clears the
cell; a JSON null leaves the cell as it is and needs no confirmation).docs replace-content (replaces the whole document
body); sheets merge (discards every value in the range except the upper-left one); sheets copy-to (copies a sheet into another spreadsheet); events subscriptions create, reactivate, renew and
update (start, resume, extend or change delivery of events to a
Pub/Sub topic); auth logout (revokes the stored login); commands that send (Gmail send, reply, forward,
send-draft; Chat send, upload) and commands that change access (Calendar
share, unshare, update-acl, unsubscribe, move; Drive share, unshare,
update-permission, move, copy, convert, add-comment, reply,
comment-approval,
start-approval, reassign-approval; Chat
add-member, update-member); Chat react and unreact.untrash, and responding to
a Drive approval (approve, decline, cancel-approval).gws <command> --schema shows
"sensitive": true for a command that always needs confirmation, and
"sensitive_when" naming the flag for one that needs it only when that
flag is used (for example calendar create with --attendees). Check
both fields.If you haven't set up Google Cloud credentials yet, see the detailed setup guide: Setup Guide
Quick summary:
gws auth logingws auth status
Shows whether you're authenticated, the current user email, and token expiry info.
gws auth login [flags]
Flags:
--client-id string — OAuth client ID (overrides env/config)--client-secret string — OAuth client secret (overrides env/config)--services string — Comma-separated services to authorize (e.g. gmail,calendar,chat). Omit for all scopes.--readonly — Request only read-only scopes for the selected services--add — Add the selected services to the existing authorization instead of replacing itOpens a browser for Google OAuth consent. The token is stored at ~/.config/gws/token.json.
Available services: gmail, calendar, drive, docs, sheets, slides, tasks, chat, forms, contacts
Credential sources (in priority order):
--client-id, --client-secret)GWS_CLIENT_ID, GWS_CLIENT_SECRET)~/.config/gws/config.yaml)gws auth logout
Revokes the token server-side with Google, then deletes the local token at ~/.config/gws/token.json.
export GWS_CLIENT_ID="your-client-id.apps.googleusercontent.com"
export GWS_CLIENT_SECRET="your-client-secret"
~/.config/gws/config.yaml)client_id: "your-client-id.apps.googleusercontent.com"
client_secret: "your-client-secret"
services:
- gmail
- calendar
- chat
~/.config/gws/token.json (atomic writes, file-locked)~/.config/gws/granted_services.json; per-service access level, tied to the stored token, in ~/.config/gws/granted_access.jsongws auth login stores the new refresh token Google returns and never reuses the previous one; if Google returns none, the login is rejected and the stored authorization is left unchanged--services to request only needed scopes (smaller consent screen)services: [gmail, calendar, chat]gws auth login --add --services drive (or re-run the full list without --add)gws auth status before running any gws command to verify authenticationgws auth login --readonly for tasks that only read data; ask the user before requesting write accessconfirmation required, ask the user to approve the action, then re-run it with --yes--schema and --show-scopes to learn a command's flags and scopes instead of guessingreferences/setup-guide.mdgws auth logout then gws auth loginWhat SKILL.md sets; muted values are Claude Code's defaults
Other plugins' skills for the same job
npx claudepluginhub omriariav/workspace-cli --plugin gws16 skills in this plugin
/gws-calendarGoogle Calendar CLI operations via gws. Use when users need to list calendars, view events, create/update/delete events, RSVP to invitations, manage calendar CRUD, subscriptions, ACL, free/busy queries, colors, and settings. Triggers: calendar, events, meetings, schedule, rsvp, invite, share, freebusy./gws-chatGoogle Chat CLI operations via gws. Use when users need to list/create/manage chat spaces, read/send messages, manage members, track read state, handle attachments, or monitor space events. Triggers: google chat, gchat, chat spaces, chat messages./gws-contactsGoogle Contacts CLI operations via gws. Use when users need to list, search, view, create, or delete contacts. Triggers: contacts, google contacts, people api, contact management./gws-docsGoogle Docs CLI operations via gws. Use when users need to read, create, or edit Google Docs documents. Triggers: google docs, document, gdoc, word processing./gws-driveGoogle Drive CLI operations via gws. Use when users need to list, search, upload, download, manage files/folders, permissions, approvals, revisions, comments, shared drives, and more. Triggers: drive, files, upload, download, folders, google drive, file management, permissions, approvals, share, shared drives./gws-eventsGoogle Workspace Events API operations via gws. Use when users need to create or manage event subscriptions for Chat, Drive, or Meet resources (Pub/Sub delivery), renew or reactivate subscriptions, or decode Pub/Sub CloudEvent notifications. Triggers: workspace events, event subscription, subscribe to chat events, drive events, meet events, pubsub notifications, cloudevent.