Google Workspace CLI

2026-03-050:22950290github.com

Google Workspace CLI — one command-line tool for Drive, Gmail, Calendar, Sheets, Docs, Chat, Admin, and more. Dynamically built from Google Discovery Service. Includes AI agent skills. - googlework...

gws logo

One CLI for all of Google Workspace — built for humans and AI agents.
Drive, Gmail, Calendar, and every Workspace API. Zero boilerplate. Structured JSON output. 40+ agent skills included.

npm version license CI status install size


npm install -g @googleworkspace/cli

gws doesn't ship a static list of commands. It reads Google's own Discovery Service at runtime and builds its entire command surface dynamically. When Google Workspace adds an API endpoint or method, gws picks it up automatically.

Important

This project is under active development. Expect breaking changes as we march toward v1.0.

Demo

npm install -g @googleworkspace/cli gws auth setup # walks you through Google Cloud project config + OAuth login
gws drive files list --params '{"pageSize": 5}'

Or build from source:

For humans — stop writing curl calls against REST docs. gws gives you tab‑completion, --help on every resource, --dry-run to preview requests, and auto‑pagination.

For AI agents — every response is structured JSON. Pair it with the included agent skills and your LLM can manage Workspace without custom tooling.

# List the 10 most recent files
gws drive files list --params '{"pageSize": 10}' # Create a spreadsheet
gws sheets spreadsheets create --json '{"properties": {"title": "Q1 Budget"}}' # Send a Chat message
gws chat spaces messages create \ --params '{"parent": "spaces/xyz"}' \ --json '{"text": "Deploy complete."}' \ --dry-run # Introspect any method's request/response schema
gws schema drive.files.list # Stream paginated results as NDJSON
gws drive files list --params '{"pageSize": 100}' --page-all | jq -r '.files[].name'

The CLI supports multiple auth workflows so it works on your laptop, in CI, and on a server.

Credentials are encrypted at rest (AES-256-GCM) with the key stored in your OS keyring.

gws auth setup # one-time: creates a Cloud project, enables APIs, logs you in
gws auth login # subsequent logins

Requires the gcloud CLI to be installed and authenticated.

Use this when gws auth setup cannot automate project/client creation, or when you want explicit control.

  1. Open Google Cloud Console in the target project:
    • OAuth consent screen: https://console.cloud.google.com/apis/credentials/consent?project=<PROJECT_ID>
    • Credentials: https://console.cloud.google.com/apis/credentials?project=<PROJECT_ID>
  2. Configure OAuth branding/audience if prompted:
    • App type: External (testing mode is fine)
    • Add your account under Test users
  3. Create an OAuth client:
  4. Download the client JSON and save it to:
    • ~/.config/gws/client_secret.json

Then run:

You can complete OAuth either manually or with browser automation.

  • Human flow: run gws auth login, open the printed URL, approve scopes.
  • Agent-assisted flow: the agent opens the URL, selects account, handles consent prompts, and returns control once the localhost callback succeeds.

If consent shows "Google hasn't verified this app" (testing mode), click Continue. If scope checkboxes appear, select required scopes (or Select all) before continuing.

  1. Complete interactive auth on a machine with a browser.
  2. Export credentials:
    gws auth export --unmasked > credentials.json
  3. On the headless machine:
    export GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE=/path/to/credentials.json
    gws drive files list # just works

Point to your key file; no login needed.

export GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE=/path/to/service-account.json
gws drive files list

For Domain-Wide Delegation, add:

export GOOGLE_WORKSPACE_CLI_IMPERSONATED_USER=admin@example.com

Useful when another tool (e.g. gcloud) already mints tokens for your environment.

export GOOGLE_WORKSPACE_CLI_TOKEN=$(gcloud auth print-access-token)
Priority Source Set via
1 Access token GOOGLE_WORKSPACE_CLI_TOKEN
2 Credentials file GOOGLE_WORKSPACE_CLI_CREDENTIALS_FILE
3 Encrypted credentials (OS keyring) gws auth login
4 Plaintext credentials ~/.config/gws/credentials.json

Environment variables can also live in a .env file.

The repo ships 100+ Agent Skills (SKILL.md files) — one for every supported API, plus higher-level helpers for common workflows and 50 curated recipes for Gmail, Drive, Docs, Calendar, and Sheets. See the full Skills Index for the complete list.

# Install all skills at once
npx skills add https://github.com/googleworkspace/cli # Or pick only what you need
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
OpenClaw setup
# Symlink all skills (stays in sync with repo)
ln -s $(pwd)/skills/gws-* ~/.openclaw/skills/ # Or copy specific skills
cp -r skills/gws-drive skills/gws-gmail ~/.openclaw/skills/

The gws-shared skill includes an install block so OpenClaw auto-installs the CLI via npm if gws isn't on PATH.

  1. Authenticate the CLI first:

  2. Install the extension into the Gemini CLI:

    gemini extensions install https://github.com/googleworkspace/cli

Installing this extension gives your Gemini CLI agent direct access to all gws commands and Google Workspace agent skills. Because gws handles its own authentication securely, you simply need to authenticate your terminal once prior to using the agent, and the extension will automatically inherit your credentials.

gws mcp starts a Model Context Protocol server over stdio, exposing Google Workspace APIs as structured tools that any MCP-compatible client (Claude Desktop, Gemini CLI, VS Code, etc.) can call.

gws mcp -s drive # expose Drive tools
gws mcp -s drive,gmail,calendar # expose multiple services
gws mcp -s all # expose all services (many tools!)

Configure in your MCP client:

{ "mcpServers": { "gws": { "command": "gws", "args": ["mcp", "-s", "drive,gmail,calendar"]
    }
  }
}

Tip

Each service adds roughly 10–80 tools. Keep the list to what you actually need to stay under your client's tool limit (typically 50–100 tools).

Flag Description
-s, --services <list> Comma-separated services to expose, or all
-w, --workflows Also expose workflow tools
-e, --helpers Also expose helper tools
gws drive files create --json '{"name": "report.pdf"}' --upload ./report.pdf
Flag Description Default
--page-all Auto-paginate, one JSON line per page (NDJSON) off
--page-limit <N> Max pages to fetch 10
--page-delay <MS> Delay between pages 100 ms

Integrate Google Cloud Model Armor to scan API responses for prompt injection before they reach your agent.

gws gmail users messages get --params '...' \ --sanitize "projects/P/locations/L/templates/T"
Variable Description
GOOGLE_WORKSPACE_CLI_SANITIZE_TEMPLATE Default Model Armor template
GOOGLE_WORKSPACE_CLI_SANITIZE_MODE warn (default) or block

gws uses a two-phase parsing strategy:

  1. Read argv[1] to identify the service (e.g. drive)
  2. Fetch the service's Discovery Document (cached 24 h)
  3. Build a clap::Command tree from the document's resources and methods
  4. Re-parse the remaining arguments
  5. Authenticate, build the HTTP request, execute

All output — success, errors, download metadata — is structured JSON.

If a required Google API is not enabled for your GCP project, you will see a 403 error with reason accessNotConfigured:

{ "error": { "code": 403, "message": "Gmail API has not been used in project 549352339482 ...", "reason": "accessNotConfigured", "enable_url": "https://console.developers.google.com/apis/api/gmail.googleapis.com/overview?project=549352339482"
  }
}

gws also prints an actionable hint to stderr:

💡 API not enabled for your GCP project.
   Enable it at: https://console.developers.google.com/apis/api/gmail.googleapis.com/overview?project=549352339482
   After enabling, wait a few seconds and retry your command.

Steps to fix:

  1. Click the enable_url link (or copy it from the enable_url JSON field).
  2. In the GCP Console, click Enable.
  3. Wait ~10 seconds, then retry your gws command.

Tip

You can also run gws auth setup which walks you through enabling all required APIs for your project automatically.

cargo build # dev build
cargo clippy -- -D warnings # lint
cargo test # unit tests
./scripts/coverage.sh # HTML coverage report → target/llvm-cov/html/

Apache-2.0

This is not an officially supported Google product.


Read the original article

Comments

  • By ksri 2026-03-058:183 reply

    I have been working on extrasuite (https://github.com/think41/extrasuite). This is like terraform, but for google drive files.

    It provides a git like pull/push workflow to edit sheets/docs/slides. `pull` converts the google file into a local folder with agent friendly files. For example, a google sheet becomes a folder with a .tsv, a formula.json and so on. The agent simply edits these files and `push`es the changes. Similarly, a google doc becomes an XML file that is pure content. The agent edits it and calls push - the tool figures out the right batchUpdate API calls to bring the document in sync.

    None of the existing tools allow you to edit documents. Invoking batchUpdate directly is error prone and token inefficient. Extrasuite solves these issues.

    In addition, Extrasuite also uses a unique service token that is 1:1 mapped to the user. This means that edits show up as "Alice's agent" in google drive version history. This is secure - agents can only access the specific files or folders you explicitly share with the agent.

    This is still very much alpha - but we have been using this internally for our 100 member team. Google sheets, docs, forms and app scripts work great - all using the same pull/push metaphor. Google slides needs some work.

    • By sothatsit 2026-03-0510:033 reply

      We have been using something similar for editing Confluence pages. Download XML, edit, upload. It is very effective, much better than direct edit commands. It’s a great pattern.

      • By grantcarthew 2026-03-062:46

        Yes, Atlassian's CLI support is shocking.

        This is for Confluence. Markdown all the way:

        https://github.com/grantcarthew/acon

        Jira, same, markdown all the way:

        https://github.com/grantcarthew/ajira

        Other agent tools:

        https://github.com/grantcarthew/homebrew-tap

      • By holmb 2026-03-0510:443 reply

        I would be very interested in this if you could share? Maintaining a Knowledge Base without a Git workflow is a pain currently.

        • By Jagerbizzle 2026-03-0514:50

          You can use the Copilot CLI with the atlassian mcp to super easily edit/create confluence pages. After having the agent complete a meaningful amount of work, I have it go create a confluence page documenting what has been done. Super useful.

        • By sothatsit 2026-03-0511:302 reply

          I'm afraid I can't easily share this, as we have embedded a lot of company-specific information in our setup, particularly for cross-linking between confluence/jira/zendesk and other systems. I can try explain it though, and then Claude Code is great at implementing these simple CLI tools and writing the skills.

          We wrote CLIs for Confluence, Jira, and Zendesk, with skills to match. We use a simple OAuth flow for users to login (e.g., they would run jira login). Then confluence/jira/zendesk each have REST APIs to query pages/issues/tickets and submit changes, which is what our CLIs would use. Claude Code was exceptional at finding the documentation for these and implementing them. Only took a couple days to set these up and Claude Code is now remarkably good at loading the skills and using the CLIs. We use the skills to embed a lot of domain-specific information about projects, organisation of pages, conventions, standard workflows, etc.

          Being able to embed company-specific links between services has been remarkably useful. For example, we look for specific patterns in pages like AIT-553 or zd124132 and then can provide richer cross-links to Jira or Zendesk that help agents navigate between services. This has made agents really efficient at finding information, and it makes them much more likely to actually read from multiple systems. Before we made changes like this, they would often rabbit-hole only looking at confluence pages, or only looking at jira issues, even when there was a lot of very relevant information in other systems.

          My favourite is the confluence integration though, as I like to record a lot of worklog-style information in there that I would previously write down as markdown files. It's nicer to have these in Confluence as then they are accessible no matter what repo I am working in, what region I am working in, or what branch or feature I'm working on. I've been meaning to try to set something similar up for my personal projects using the new Obsidian CLI.

          • By holmb 2026-03-0515:20

            Thanks for the insights!

            We have been doing something similar but it sounds like you have come further along this way of working. We (with help from Claude) have built a similar tool that you describe to interface with our task- and project management system, and use it together with the Gitlab and Github CLI tools to allow agents to read tickets, formulate a plan and create solutions and create MR/PR to the relevant repos. For most of our knowledge base we use Markdown but some of it is tied up in Confluence, that's why I have an interest in that part. And, some is even in workflows are in Google Docs which makes the OP tool interesting as well -- currently our tool output Markdown and we just "paste from markdown" into Gdocs. We might be able to revise and improve that too.

          • By graeme 2026-03-0513:251 reply

            Thank you! Sounds like a fantastic setup. Are the claude code agents acting autonomously from any trigger conditions or is this all manual work with them? And how do you manage write permissions for documents amongst team members/agents, presumably multiple people have access to this system?

            (Not OP, but have been looking into setting up a system for a similar use case)

            • By sothatsit 2026-03-0522:33

              This is all manual, so people ask their agent to load Jira issues, edit Confluence pages, etc. Users sign-in using their own accounts using the CLIs, so the agents inherit their own permissions. Then we have the permissions in Claude Code setup so any write commands are in Ask, so it always prompts the user if it wants to run them.

        • By reachableceo 2026-03-0520:48

          Edit the markdown using GitHub workflow. Then insert markup (pick markdown) into the confluence page.

          Works wonderfully!

      • By neuronexmachina 2026-03-0515:411 reply

        I've found that usually works ok, but currently tends to timeout with the Atlassian MCP when trying to do updates on large Confluence pages: https://github.com/atlassian/atlassian-mcp-server/issues/59

        • By sothatsit 2026-03-0522:30

          Yeah, we wrote our own CLIs for Jira/Confluence/Zendesk using their REST APIs instead. Works well, although a bit more work.

    • By lewisjoe 2026-03-0520:191 reply

      Excellent project! I see that the agent modifies the google docs using an interesting technique: convert doc to html, AI operates over the HTML and then diff the original html with ai-modified html, send the diff as batchUpdate to gdocs.

      IMO, this is a better approach than the one used by Anthropic docx editing skill.

      1. Did you compare this one with other document editing agents? Did you have any other ideas on how to make AI see and make edits to documents?

      2. What happens if the document is a big book? How do you manage context when loading big documents?

      PS:I'm working on an AI agent for Zoho Writer(gdocs alternative) and I've landed on a similar html based approach. The difference is I ask the AI to use my minimal commands (addnode, replacenode, removenode) to operate over the HTML and convert them into ops.

      This works pretty well for me.

      • By ksri 2026-03-067:20

        re. comparing with other editing agents - actually, I didn't find any that could work with google docs. Many workflows were basically "replace the whole document" - and that was a non-starter.

        re. what happens if its a big book - each "tab" in the google doc is a folder with its own document.xml. A top-level index.xml captures the table of contents across tabs. The agent reads index.xml and then decides what else to read. I am now improving this by giving it xpath expressions so it can directly pick the specific sections of interest.

        Philosophically, we wanted "declarative" instead of "imperative". Our key design - the agent needs to "think" in terms of the business, and not worry about how to edit the document. We move all the reconcilliation logic in the library, and free the agent from worrying about the google doc. Same approach in other libraries as well.

    • By tianzhou 2026-03-066:22

      Good stuff. I added to the latest star-history.com issue https://www.star-history.com/blog/ai-ui-irrelevant

  • By tclancy 2026-03-052:305 reply

    Interesting post from the main contributor about this (at least I assume it’s what he’s referencing) https://justin.poehnelt.com/posts/rewrite-your-cli-for-ai-ag...

    • By dang 2026-03-055:301 reply

      Thanks! Looks like he submitted it here, judging by the username:

      You need to rewrite your CLI for AI agents - https://news.ycombinator.com/item?id=47252459.

      I think that's pretty cool so I put the post in the SCP (https://news.ycombinator.com/item?id=26998308).

      • By Barbing 2026-03-056:01

        TIL Second Chance Pool, great idea

    • By juanre 2026-03-0510:231 reply

      This is really interesting: "Humans hate writing nested JSON in the terminal. Agents prefer it." Are others seeing the same thing? I've just moved away from json-default because agents were always using jq to convert it to what I could have been producing anyway.

      • By lostmsu 2026-03-0517:52

        In my experience agents struggle with escape sequence nesting as much as humans do. IMHO that is one well-paved road to RCE via code injection.

    • By albert_e 2026-03-055:221 reply

      Looks like I am hitting some Cloudflare Block when accessing this URL

      • By abustamam 2026-03-0513:491 reply

        Probably because he built his site for agents not humans

        • By hamasho 2026-03-0514:08

          lol but it’s definitely happening. Some services are solely for llm consumption and human is not a welcomed customer.

    • By winwang 2026-03-052:54

      Really interesting. I was thinking about something similar regarding the shape of code. I have no qualms recommending my agents take static analysis to the extreme, though it would cumbersome for most people.

    • By blks 2026-03-0513:03

      No, we won’t be in fact doing that. Machine parsable, readable for other tools - yes.

  • By d4rkp4ttern 2026-03-0512:322 reply

    Related, I often work with markdown docs (usually created via CLI agents like Claude Code) and need to collaborate with others in google docs, which is extremely markdown-unfriendly[1], so I built small quality-of-life CLI tools to convert Gdocs -> md and vice versa, called gdoc2md and md2gdoc:

    https://pchalasani.github.io/claude-code-tools/integrations/...

    They handle embedded images in both directions. There are similar gsheet2csv and csv2gsheet tools in the same repo.

    Similar to the posted tool, there is a first time set up involving creating an app, that is documented above.

    [1] in the sense there are multiple annoying clicks/steps to get a markdown doc to look good in Gdocs. You'd know the pain if you've tried it.

    • By greymalik 2026-03-0512:572 reply

      Paste from markdown (Chrome only) works _really_ well for me. What are the extra steps you’re running into?

      • By rendaw 2026-03-063:09

        After reading a comment here about how google docs had awesome markdown handling (I didn't know it supported it at all) I tried it out and it was bad to the extent that I don't think I'll use it again. I can't remember everything, but for instance it kept the syntactic newlines that should be swallowed during rich text conversion and IIRC it had issues with code too.

        And then you have to edit it thereafter with their WYSIWYG editor. I was hoping there was an actual "markdown mode" where I could avoid getting into wars about whether this bullet point is in a new list or part of the previous list, etc.

        IIRC there's no way to get markdown back out either, once you've realized you made the wrong choice.

      • By d4rkp4ttern 2026-03-0513:151 reply

        Interesting, in my Arc browser, I just tried File -> open -> upload -> blah.md and it does seem to render fine. This exact thing did not work a few weeks ago, meaning the various header markers etc showed up as raw "##" etc, and I had to further select something like "open as new doc" to finally make it look good.

        • By z3ugma 2026-03-0514:461 reply

          Right click > "Paste from Markdown" instead of just straight up pasting in

          • By d4rkp4ttern 2026-03-0515:131 reply

            Images wouldn't work though, right? I'd be amazed if that worked. My CLI tools handle those.

            • By chrisweekly 2026-03-0515:383 reply

              Obsidian has become almost an operating system for working with markdown. Its Live View / Edit mode is excellent (WYSIWYG) and its ability to accept pasted content and handle it appropriately is good and getting better. Its plugin/extension ecosystem is robust (and has a low barrier to entry), and now that it has a CLI I expect to see an acceleration of clever workflows and integrations.

              No affiliation, just a very happy ~early adopter and daily user.

              • By Lord_Zero 2026-03-0518:513 reply

                BUT the main supported sync module is cloud only they wont let you self host for free which is really shitty and lame.

                • By chrisweekly 2026-03-0519:47

                  Wow, that's a strong opinion and harsh words that come across as really entitled, and probably unfair. From my PoV, they're a tiny, scrappy, transparent and likeable company who built and maintain a fantastic software application that radically improved ~everything about my daily workflow and PKM. I get more value out of Obsidian in a day than most other apps in their entire lifespan. The core app is free! They have to eat. I'd probably throw $ at them even if they didn't charge a few bucks / month for Sync. (Which works flawlessly.) Sure it'd be cool if you could self-host their Sync module -- but many Obsidian users use other DIY approaches for sync; in the end it's markdown files on a local disk, do with it what you will.

                • By joquarky 2026-03-060:23

                  git + cron

                • By quietsegfault 2026-03-0519:38

                  [dead]

              • By d4rkp4ttern 2026-03-0515:43

                I’m intrigued by their recent CLI release as well. I’ll have to check out the markdown edit support too, thanks

              • By eudiwjfie 2026-03-0615:35

                [dead]

    • By ritzaco 2026-03-0515:26

      interesting we have a very similar internal flow - we like working in markdown but our customers want to leave feedback in Google docs, so we also have an md -> gdoc tool. We don't do the reverse as we ask them to only leave comments/suggested changes and we apply those directly to the markdown and re-export.

      I ran into similar issues as you for the image handling, and the work around I use is to use pandoc to convert to docx as a first step and then import that as a Google Doc using the API, as Google Docs seems to handle docx much better than markdown from what I've seen.

HackerNews