| name | google-workspace |
| description | Set up and authenticate the gws CLI (@googleworkspace/cli) for Google Workspace access. Use when setting up OAuth, authenticating on headless/remote machines, configuring agent account access, or troubleshooting gws auth issues. For daily Gmail/Calendar/Drive usage, defer to the official gws skills shipped with the CLI. |
Google Workspace Setup Guide
Setup and auth for the gws CLI. For daily usage, generate the official per-service skills:
gws generate-skills
See the full skills index.
Install
npm install -g @googleworkspace/cli
Setup
Quick Setup
gws auth setup
gws auth login
Manual Setup
When gws auth setup fails or you want control:
- GCP Project: Create at console.cloud.google.com or use existing
- Enable APIs: Gmail, Calendar, Drive, etc.
- OAuth consent screen: External user type, add your account(s) as test users
- Create OAuth client: Credentials > OAuth client ID > Desktop app
- Save
client_secret.json to ~/Library/Application Support/gws/ (macOS) or ~/.config/gws/ (Linux)
- Authenticate:
gws auth login
gws auth login --readonly
gws auth login --scopes gmail.readonly,calendar,drive,tasks
Headless / Remote Machine Auth
gws auth login needs a browser. On headless machines:
With agent browser (OpenClaw): Run gws auth login in the background, open the printed OAuth URL via the browser tool (profile="user"), click through consent. Localhost redirect completes automatically since browser and CLI share the same host.
Without browser: Run gws auth login, open the URL on any machine, approve consent, copy the full redirect URL from the browser bar, extract the code param, and exchange it manually with curl or Python against https://oauth2.googleapis.com/token. Save the resulting refresh token as credentials.json.
Credential Storage
Credentials are encrypted by default (AES-256-GCM). The CLI handles decryption and token refresh.
gws auth status
gws auth export
Agent Account Pattern
Recommended for AI assistants: authenticate as a dedicated agent account (e.g., agent@gmail.com). The user shares access to their data. User credentials never touch the agent machine.
Start with minimal scopes: gmail.readonly, drive, calendar, tasks
Gmail: Delegation
Gives the agent full read access to the user's entire inbox, sent mail, and thread history.
- User: Gmail > Settings > Accounts > "Grant access to your account" > add agent email
- Agent receives invitation email, accepts via link
- Propagates in up to 30 minutes
- Read user's inbox:
gws gmail +triage with userId: "user@gmail.com"
gws gmail users messages list --params '{"userId": "user@gmail.com", "maxResults": 10}'
Security: Delegation technically grants send, but gmail.readonly scope rejects any write attempt at the API level. Two layers of protection.
Why not forwarding? Forwarding only gets new mail. Delegation reads the full inbox and thread history, which is critical for triage.
Calendar & Drive: Sharing
- Calendar: User shares via Settings > "Share with specific people" > agent email
- Drive: User shares specific folders with agent email
gws calendar events list --params '{"calendarId": "user@gmail.com", "singleEvents": true, "orderBy": "startTime", "timeMin": "..."}'
gws drive files list --params '{"q": "'\''user@gmail.com'\'' in owners"}'
Email Drafts (No Send)
With readonly scopes, write drafts as local markdown files for the user to review and send:
---
to: recipient@example.com
subject: Re: Original Subject
---
Draft body here...
Scopes Reference
| Scope | Access |
|---|
gmail.readonly | Read email only |
gmail.modify | Read + send + delete + labels |
calendar / calendar.readonly | Full / read-only calendar |
drive / drive.readonly | Full / read-only drive |
tasks / tasks.readonly | Full / read-only tasks |
Start with --readonly and expand only as needed.
Troubleshooting
| Problem | Fix |
|---|
| "Access blocked: app not verified" | Add account as test user in GCP > Auth Platform > Audience |
| "Google hasn't verified this app" | Expected for personal projects. Click Continue |
| 403 on API calls | Check API is enabled in GCP console |
| 403 "Delegation denied" | Takes up to 30 min to propagate after acceptance |
| Wrong account's data | gws auth status to check active credentials |
| Redirect fails during auth | Headless machine, use agent browser or manual exchange |