Google Workspace CLI (gws) — One CLI for Drive, Gmail, Calendar & More
Set up the Google Workspace CLI (gws), a Rust-based tool that provides unified command-line access to all Google Workspace APIs with dynamic command generation, structured JSON output, and 100+ AI agent skills.
- Step 1
Overview
The Google Workspace CLI (
gws) is a Rust-based command-line tool that provides unified access to all Google Workspace APIs — Drive, Gmail, Calendar, Sheets, Docs, Chat, and more. Unlike traditional CLIs with static commands,gwsreads Google's Discovery Service at runtime and builds its entire command surface dynamically. When Google adds a new API endpoint,gwspicks it up automatically.Key features:
- Dynamic command generation from Google's Discovery Service (no hardcoded API list)
- Structured JSON output for all responses (human-readable tables also available)
- 100+ AI agent skills included for Claude Code, OpenClaw, and Gemini CLI
- OAuth 2.0 authentication with encrypted credential storage
- Auto-pagination, dry-run mode, and schema introspection
- Helper commands for common workflows (e.g.,
+send,+triage,+agenda)
⚠ Heads up: This is not an officially supported Google product. The project is under active development with breaking changes expected before v1.0. - Step 2
Prerequisites
Before installing
gws, ensure you have:- Node.js 18+ — required if installing via npm (or download pre-built binaries)
- A Google Cloud project — required for OAuth credentials (can be created via Google Cloud Console,
gcloudCLI, orgws auth setup) - A Google account with access to Google Workspace
- Rust toolchain (optional) — only needed if building from source via
cargo
- Step 3
Installation Methods
Choose the installation method that best fits your environment. The recommended approach is downloading pre-built binaries from GitHub Releases.
# Option 1: Download pre-built binary (recommended) # Visit https://github.com/googleworkspace/cli/releases # Extract and place in your $PATH # Option 2: Install via npm (downloads binary from releases) npm install -g @googleworkspace/cli # Option 3: Install via Homebrew (macOS/Linux) brew install googleworkspace-cli # Option 4: Build from source with Cargo cargo install --git https://github.com/googleworkspace/cli --locked # Option 5: Run via Nix flake nix run github:googleworkspace/cli - Step 4
Verify Installation
After installation, verify that
gwsis available in your PATH and check the version.gws --version gws --help - Step 5
Authentication Setup — Interactive Flow
The fastest way to authenticate is using
gws auth setup, which automates Google Cloud project creation, API enablement, and initial login. This requires thegcloudCLI to be installed and authenticated.Credentials are encrypted at rest using AES-256-GCM with the encryption key stored in your OS keyring (macOS Keychain, Windows Credential Manager, or Linux Secret Service).
# One-time setup: creates Cloud project, enables APIs, logs you in gws auth setup # Subsequent logins (after setup) gws auth login⚠ Heads up: If your OAuth app is unverified (testing mode), Google limits consent to ~25 scopes. The `recommended` preset includes 85+ scopes and will fail for unverified apps (especially `@gmail.com` accounts). Choose individual services instead: `gws auth login -s drive,gmail,sheets` - Step 6
Authentication Setup — Manual (No gcloud)
If you don't have
gcloudinstalled or want explicit control over the OAuth setup, you can configure credentials manually via the Google Cloud Console.# 1. Open Google Cloud Console OAuth consent screen: # https://console.cloud.google.com/apis/credentials/consent?project=<PROJECT_ID> # 2. Configure OAuth branding/audience: # - App type: External (testing mode is fine) # - Add yourself under "Test users" # 3. Create OAuth client: # https://console.cloud.google.com/apis/credentials?project=<PROJECT_ID> # - Type: Desktop app # - Download client JSON # 4. Save the downloaded JSON to: mkdir -p ~/.config/gws mv ~/Downloads/client_secret_*.json ~/.config/gws/client_secret.json # 5. Login gws auth login⚠ Heads up: You MUST add yourself as a test user in the OAuth consent screen. Without this, login will fail with "Access blocked" error. - Step 7
Quick Start — Basic Commands
Once authenticated, you can start using
gwsto interact with Google Workspace APIs. All commands follow the pattern:gws <service> <resource> <method> [flags]# List the 5 most recent Drive files gws drive files list --params '{"pageSize": 5}' # Create a new Google Sheets spreadsheet gws sheets spreadsheets create --json '{"properties": {"title": "Q1 Budget"}}' # Send a Chat message (dry-run to preview) gws chat spaces messages create \ --params '{"parent": "spaces/xyz"}' \ --json '{"text": "Deploy complete."}' \ --dry-run # Introspect API schema for any method gws schema drive.files.list # Stream paginated results as NDJSON gws drive files list --params '{"pageSize": 100}' --page-all | jq -r '.files[].name' - Step 8
Helper Commands
gwsincludes hand-crafted helper commands (prefixed with+) for common workflows. These provide a simpler interface than raw API calls and handle complex logic like threading, metadata, and timezone awareness.Run
gws <service> --helpto see both Discovery methods and helper commands.# Gmail helpers gws gmail +send --to alice@example.com --subject "Hello" --body "Hi there" gws gmail +reply --message-id MESSAGE_ID --body "Thanks!" gws gmail +triage # Show unread inbox summary gws gmail +watch # Watch for new emails and stream as NDJSON # Calendar helpers gws calendar +agenda # Today's agenda (uses your Google timezone) gws calendar +agenda --today --timezone America/New_York gws calendar +insert # Create a new event # Sheets helpers gws sheets +append --spreadsheet SPREADSHEET_ID --values "Alice,95" gws sheets +read --spreadsheet SPREADSHEET_ID --range "Sheet1!A1:C10" # Drive helpers gws drive +upload ./report.pdf --name "Q1 Report" # Workflow helpers gws workflow +standup-report # Today's meetings + open tasks gws workflow +meeting-prep # Prepare for next meeting gws workflow +weekly-digest # Weekly summary - Step 9
AI Agent Skills (Claude Code, OpenClaw, Gemini CLI)
The repository includes 100+ AI agent skills as
SKILL.mdfiles — one for every supported Google Workspace API plus 50+ curated recipes for common workflows. These skills can be integrated into Claude Code, OpenClaw, or Gemini CLI.# Install all skills at once npx skills add https://github.com/googleworkspace/cli # Or install specific skills npx skills add https://github.com/googleworkspace/cli/tree/main/skills/gws-drive npx skills add https://github.com/googleworkspace/cli/tree/main/skills/gws-gmail # For OpenClaw: symlink all skills (stays in sync with repo) ln -s $(pwd)/skills/gws-* ~/.openclaw/skills/ # For Gemini CLI: install as extension gemini extensions install https://github.com/googleworkspace/cli - Step 10
Headless / CI Authentication
For CI/CD pipelines or headless servers, you can export credentials from an authenticated machine and use them elsewhere via environment variables.
# On a machine with a browser (one-time): gws auth login gws auth export --unmasked > credentials.json # On the headless/CI machine: export GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE=/path/to/credentials.json gws drive files list # just works # Or use a service account: export GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE=/path/to/service-account.json gws drive files list - Step 11
Advanced Features
Multipart Uploads:
gws drive files create --json '{"name": "report.pdf"}' --upload ./report.pdfPagination:
# Auto-paginate (NDJSON output, one page per line) gws drive files list --page-all # Limit pages gws drive files list --page-all --page-limit 5 # Add delay between pages gws drive files list --page-all --page-delay 200Google Sheets Range Escaping:
# Always wrap ranges in single quotes (! triggers bash history expansion) gws sheets spreadsheets values get \ --params '{"spreadsheetId": "ID", "range": "Sheet1!A1:C10"}'Model Armor (Response Sanitization):
# Scan API responses for prompt injection gws gmail users messages get --params '...' \ --sanitize "projects/P/locations/L/templates/T" - Step 12
Tech Stack Deep Dive
Understanding the underlying technology helps with troubleshooting and customization.
Core Language: Rust (Cargo workspace with 2 crates:
google-workspace-cliandgoogle-workspace)Key Dependencies:
clap(v4) — CLI framework with derive macros for dynamic command generationtokio(v1) — Async runtime for concurrent HTTP requestsreqwest(v0.12) — HTTP client with rustls-tls, JSON, streaming, and SOCKS proxy supportyup-oauth2(v12) — OAuth 2.0 flow implementationaes-gcm(v0.10) — AES-256-GCM encryption for credential storagekeyring(v3.6) — OS-level keyring integration (macOS Keychain, Windows Credential Manager, Linux Secret Service)serde+serde_json— JSON serialization/deserializationratatui+crossterm— Terminal UI for interactive promptschrono+chrono-tz— Timezone-aware date/time handlingdotenvy—.envfile loader
Architecture:
- Parse
argv[1]to identify service (e.g.,drive) - Fetch service Discovery Document from Google (cached 24h)
- Build
clap::Commandtree from resources/methods - Re-parse remaining arguments against dynamic schema
- Authenticate, build HTTP request, execute, return structured JSON
- Step 13
Environment Variables
All environment variables are optional. They can be set in your shell or in a
.envfile in the working directory.# Authentication (precedence order: 1 highest) GOOGLE_WORKSPACE_CLI_TOKEN # Pre-obtained OAuth access token (priority 1) GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE # Path to credentials JSON (priority 2) GOOGLE_WORKSPACE_CLI_CLIENT_ID # OAuth client ID GOOGLE_WORKSPACE_CLI_CLIENT_SECRET # OAuth client secret # Configuration GOOGLE_WORKSPACE_CLI_CONFIG_DIR # Override config dir (default: ~/.config/gws) GOOGLE_WORKSPACE_CLI_KEYRING_BACKEND # Set to 'file' to use ~/.config/gws/.encryption_key instead of OS keyring GOOGLE_WORKSPACE_PROJECT_ID # GCP project ID override # Model Armor (response sanitization) GOOGLE_WORKSPACE_CLI_SANITIZE_TEMPLATE # Default Model Armor template GOOGLE_WORKSPACE_CLI_SANITIZE_MODE # 'warn' (default) or 'block' # Logging GOOGLE_WORKSPACE_CLI_LOG # Log level for stderr (e.g., 'gws=debug') GOOGLE_WORKSPACE_CLI_LOG_FILE # Directory for JSON log files with daily rotation - Step 14
Troubleshooting
"Access blocked" or 403 during login: Your OAuth app is in testing mode and your account is not listed as a test user. Fix: Open the OAuth consent screen → Test users → Add users → enter your email.
"Google hasn't verified this app": Expected for testing mode apps. Click Advanced → "Go to <app name> (unsafe)" to proceed. Safe for personal use.
Too many scopes / consent screen error: Unverified apps are limited to ~25 scopes. The
recommendedpreset has 85+ scopes. Fix:gws auth login --scopes drive,gmail,calendarredirect_uri_mismatch: OAuth client was not created as "Desktop app" type. Delete the client, create a new one with type "Desktop app", and re-download.API not enabled (
accessNotConfigured): The required Google API is not enabled for your GCP project. Enable it in the API Library or run the command again —gwswill print the exact enable link. - Step 15
Exit Codes
gwsuses structured exit codes so scripts can branch on failure types without parsing error output.- 0 — Success
- 1 — General error
- 2 — Authentication error
- 3 — API error (e.g., 404, 403)
- 4 — Network error
- 5 — Configuration error
- 6 — User cancellation
Example:
if ! gws drive files list; then case $? in 2) echo "Auth failed. Run: gws auth login" ;; 3) echo "API error. Check permissions." ;; 4) echo "Network error. Check connectivity." ;; esac fi - Step 16
Use Cases & Workflows
Email Automation:
# Triage unread emails gws gmail +triage # Watch for new emails and process with jq gws gmail +watch | jq -r 'select(.from | contains("boss@")) | .subject' # Send automated reports gws gmail +send --to team@example.com --subject "Daily Report" --body "$(./generate-report.sh)"Drive File Management:
# Upload files in bulk find ./reports -name "*.pdf" -exec gws drive +upload {} \; # List shared files gws drive files list --params '{"q": "sharedWithMe=true"}' --page-all | jq -r '.files[].name'Calendar Integration:
# Daily standup: show today's agenda gws calendar +agenda --today # Create meeting from script gws calendar +insert \ --summary "Team Sync" \ --start "2026-05-23T14:00:00-07:00" \ --end "2026-05-23T15:00:00-07:00"Sheets Data Pipeline:
# Append CSV rows to a sheet cat data.csv | while IFS=, read -r name score; do gws sheets +append --spreadsheet SHEET_ID --values "$name,$score" done - Step 17
Next Steps
- Explore the API surface: Run
gws <service> --helpfor any service (e.g.,gws drive --help,gws gmail --help) to see available resources and methods - Read the Skills Index: Check docs/skills.md for the full list of 100+ AI agent skills
- Join the community: Star the repo on GitHub, file issues, or contribute helper commands
- Integrate with Claude Code: Install the skills and use
gwsin your development workflow for automated Google Workspace interactions - Build automation: Use
gwsin CI/CD pipelines, cron jobs, or serverless functions to automate Workspace tasks
- Explore the API surface: Run
Feature requests
Sign in to suggest features or vote on existing ones.
No feature requests yet.
Discussion
Sign in to join the discussion.
No comments yet.