Introduction
gog is a command-line client for Google Workspace APIs, including Gmail, Google Calendar, Drive, Docs, and Sheets. The gog binary provides machine-readable output and controls that limit which actions a caller can take. The independent gogcli project develops the client in Go and releases it under the MIT License.
This book teaches gog using Gmail and Google Calendar. The examples show how to authorize accounts for both services and how to use gog from scripts and AI agents.
- Search and read mail from the terminal.
- Write drafts, reply to messages, and send mail after previewing it.
- List and manage calendar events.
- Run gog from shell scripts, scheduled jobs, and agents with read-only tokens, command allowlists, and other safety controls.
What gog looks like
A typical gog command names a service, an action and its arguments, and global flags choose the account and the output format:
gog --account me --json gmail search 'is:unread newer_than:7d' --max 10
gog --account me calendar events --today
Both commands need an authorized account, so they cannot run before you have finished Authentication and Accounts. The first prints JSON that a script can process with jq.
The second lists today’s events in a table. me is an alias for you@example.com, a convention that the whole book uses.
Scope of this book
The book covers these parts of gog:
| Area | Commands | Chapters |
|---|---|---|
| Setup and identity | gog auth, gog config, gog version | How gog Talks to Google, Installation and First Checks, Authentication and Accounts |
| Output contract | --json, --plain, gog schema, --dry-run | Output, Schemas and Dry Runs |
gog gmail | Reading Gmail, Writing Gmail: Drafts, Replies, and Sending | |
| Calendar | gog calendar | Google Calendar |
| Safety and automation | --readonly, --gmail-no-send, command allowlists, --no-input | Safety Controls for Scripts and Agents, Automation and Troubleshooting |
gog also covers Drive, Docs, Sheets, Slides, Forms, Contacts, Tasks, Chat, Meet, Classroom, Apps Script, Analytics, Search Console, YouTube, Photos, Maps and Google Workspace administration, and it has a generic gog api command for any Google API with a Discovery document.
The other services follow the same patterns for accounts, output, and safety. Use gog <service> --help to find their commands.
Version and sources
The book describes gog v0.48.1, built from commit 44364d3 (44364d310173f8fc5aced529ba8633231d533919) of github.com/openclaw/gogcli. Its statements about gog come from that commit: the README.md, the guides in docs/, the generated command pages in docs/commands/, and the Go source where the guides are silent. Links to the source point to the same commit, so they stay valid when the project moves on.
Commands, flags and outputs were checked against a gog binary built from that tag. Commands that work offline (help pages, gog schema, gog auth status, dry runs) are shown with their real output. Commands that need a signed-in Google account are shown without output, and their results are described from gog schema and the documentation.
Check your own version before you start:
gog --version
If it reports a newer version, most of the book still applies, but flags and outputs can differ. Compare against gog <command> --help whenever something does not match.
Who this book is for
The book is written for software engineers who are comfortable in a Unix shell. You should know how to set environment variables, use pipes, and read JSON with jq.
Some experience with OAuth helps but is not required, because the book defines every Google-specific and gog-specific term the first time it uses it. Familiarity with Gmail’s search syntax is useful for the Gmail chapters.
You also need a Google account and permission to create a project in the Google Cloud console. A personal Google account works for everything in this book.
How the chapters build on each other
The chapters are meant to be read in order, because each one relies on the setup or the concepts of the previous ones:
- How gog Talks to Google explains the objects between gog and Google: the Cloud project, the OAuth client, scopes, tokens, the keyring, accounts and gog’s files.
- Installation and First Checks installs gog and inspects it without any account.
- Authentication and Accounts creates the OAuth client and authorizes accounts, including read-only accounts, second accounts and headless machines.
- Output, Schemas and Dry Runs covers the output formats, the command schema and previews of write commands, which every later chapter uses.
- Reading Gmail searches mail, reads messages and threads, lists labels and downloads attachments.
- Writing Gmail: Drafts, Replies, and Sending creates drafts, sends, replies, forwards and changes labels.
- Google Calendar lists, creates, updates and deletes events, answers invitations and queries free and busy time.
- Safety Controls for Scripts and Agents restricts what gog may do when a program runs it.
- Automation and Troubleshooting puts gog into scripts and scheduled jobs and explains how to diagnose failures.
- Worked Example and Glossary closes the book with an end-to-end morning brief script and a glossary of the terms used throughout.
If you already have a working gog setup, you can skim chapters 1 to 3, but read chapter 4 before the service chapters and chapter 8 before you hand gog to an agent.
Conventions
- Identities:
you@example.comis your account, with the aliasme.you@example.orgis a second account, with the aliaswork.friend@example.comis a correspondent. Replace them with your own addresses. - Time zone: Examples that need a time zone use
America/Toronto. - Commands and output: Every output in the book is copied from a real run of gog v0.48.1. Long URLs are sometimes shortened, and the text says so where that happens.