Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Installation and First Checks

Install gog and check it before adding Google credentials. Use a temporary home directory to inspect the status, account list, and command schema and learn where to find global flags in the top-level help.

Install gog

The gogcli project distributes a single binary called gog. The install guide lists these methods:

MethodCommand or sourceNotes
Homebrew (macOS, Linux)brew install openclaw/tap/gogcliPrebuilt macOS binaries need macOS 15 or later
Gogo install github.com/openclaw/gogcli/cmd/gog@latestReplace latest with v0.48.1 to match this book
Dockerdocker run --rm ghcr.io/openclaw/gogcli:latest versionRuns as a non-root user. See the container setup below for persistent state.
Windowsgogcli_<version>_windows_amd64.zip or _arm64.zip from the releases pagePut gog.exe on PATH
Release archivesgogcli_<version>_<os>_<arch>.tar.gz for darwin and linux, amd64 and arm64A checksums.txt file accompanies them
Sourcegit clone, then make, then ./bin/gog --versionNeeds the Go version declared in go.mod (Go 1.26.0 or later)

The machine used to test this book installed gog from nixpkgs, where the package is named gogcli. The upstream install guide lists only the methods in the table.

For containers, the install guide recommends a persistent GOG_HOME volume and the encrypted file keyring, which How gog Talks to Google explains. The image runs as a non-root user with UID 10001 and prepares /persist/gogcli for that user:

docker volume create gogcli-state

docker run --rm -it \
  -e GOG_HOME=/persist/gogcli \
  -e GOG_KEYRING_BACKEND=file \
  -e GOG_KEYRING_PASSWORD \
  -v gogcli-state:/persist/gogcli \
  ghcr.io/openclaw/gogcli:latest \
  auth add you@example.com --services gmail,calendar

-e GOG_KEYRING_PASSWORD passes the value from your shell environment without putting the password on the command line. Keep it in your shell session or your CI secret store.

A safety-profile binary compiles command restrictions into the executable for agents. Safety Controls for Scripts and Agents covers it.

To update later, use brew upgrade openclaw/tap/gogcli, pull a newer Docker tag, replace the archive, or run git pull && make in a source checkout. The install guide states that refresh tokens and OAuth clients stay valid across point releases.

Check the version

$ gog --version
v0.48.1 (refs/tags/v0.48.1 1970-01-01T00:00:00Z)

The binary records the version, source reference, and build date at build time. This package records the Unix epoch as its build date, so use the tag to identify the release. gog version prints the same line, and with --json it returns the 3 parts as fields:

$ gog --json version
{
  "commit": "refs/tags/v0.48.1",
  "date": "1970-01-01T00:00:00Z",
  "version": "v0.48.1"
}

Work in a throwaway home

Every check in the rest of this chapter runs against an empty directory, so that it cannot read or change a real setup:

export GOG_HOME=$(mktemp -d)
export DBUS_SESSION_BUS_ADDRESS=disabled:

GOG_HOME moves gog’s config, data, state and cache directories under one root. On a Linux desktop, the second line makes the auto keyring backend use the file keyring inside GOG_HOME.

The desktop’s Secret Service is shared across all gog home directories. In the outputs below, the temporary directory is /tmp/tmp.NRnBLwNcIk; yours will have a different name.

The status view

Run gog with no arguments, and it reports where it is installed and where it would look for its configuration:

$ gog
bin: /nix/store/99c5lzzb0k0jhxgb2x6dwkvnn6cxmbap-gogcli-0.48.1/bin/gog
description: Google Workspace from the terminal
config_path	/tmp/tmp.NRnBLwNcIk/config/config.json
config_exists	false
keyring_backend	auto
keyring_backend_source	default

config_exists false is normal: gog creates config.json only when a command needs to store a setting. keyring_backend_source tells you where the backend choice came from: default, config (from config.json) or env (from GOG_KEYRING_BACKEND).

The top-level help

gog --help has 5 sections.

  1. Usage and build. Usage: gog <command> [flags], followed by the version.
  2. Config. The config file path and the keyring backend, as in the status view.
  3. Flags. The global flags, which every command accepts.
  4. Automation. A short contract for scripts.
  5. Commands. Every top-level command with its aliases.

The global flags fall into a few groups:

PurposeFlags
Choose identity--account (-a), --client, --access-token, --home
Choose output--json (-j), --plain (-p), --results-only, --select, --color
Restrict what runs--readonly, --gmail-no-send, --enable-commands, --enable-commands-exact, --disable-commands, --dry-run (-n)
Control interaction--no-input, --force (-y), --verbose (-v)
Handle fetched content--wrap-untrusted

The Automation block is short enough to quote in full:

Automation:
  Use --json or --plain for stable output; --no-input disables prompts.
  Common read-only commands:
    gog gmail labels list --json --results-only
    gog calendar calendars --json --results-only
    gog drive search <text> --json --results-only
  For exact Drive API filters, add --raw-query to drive search.
  Run "gog schema <command path>" for a targeted machine-readable contract.
  Use "gog help <command>" or "gog <command> --help" for prose help.
  Exit codes: 0 success, 1 error, 2 usage, 3 empty, 4 auth, 5 not found,
    6 denied, 7 rate limited, 8 retryable, 10 config, 11 orphaned,
    130 interrupted.
  Run "gog schema --json" for the complete machine-readable contract.

The command list starts with shortcuts for frequent actions: send (for gmail send), login (for auth add), logout (for auth remove), status (for auth status), me and whoami (for people me), and several Drive shortcuts. Then come the service groups, of which this book uses gmail and calendar, followed by the tools around them: auth, config, schema, mcp, version and completion. Every group has its own help, for example gog gmail --help or gog auth add --help.

Authentication status on a fresh home

gog auth status shows the same configuration facts as the status view; once an account is selected, it also reports the account, its OAuth client and where the client credentials are stored:

$ gog auth status
config_path	/tmp/tmp.NRnBLwNcIk/config/config.json
config_exists	false
keyring_backend	auto
keyring_backend_source	default

gog auth list lists the accounts that have a stored token. On a fresh home there are none:

$ gog auth list
No tokens stored
$ gog --json auth list
{
  "accounts": []
}

In scripts, use JSON so you can test whether the accounts array is empty.

Where the files go

These 3 commands show where gog keeps its files.

$ gog config path
/tmp/tmp.NRnBLwNcIk/config/config.json
$ gog auth keyring
path	/tmp/tmp.NRnBLwNcIk/config/config.json
keyring_backend	auto
source	default
Hint: gog auth keyring <auto|keychain|file>
$ gog auth doctor
ok	config.path	/tmp/tmp.NRnBLwNcIk/config/config.json (optional; not created)
ok	keyring.backend	auto (source: default)
ok	keyring.dir	/tmp/tmp.NRnBLwNcIk/data/keyring
ok	keyring.open	opened
warn	tokens	no OAuth tokens stored
hint	tokens	run `gog auth add <email>`
status	warn

gog auth keyring without an argument reports the backend; with auto, keychain or file it writes that choice to config.json. gog auth doctor checks the configuration and the keyring step by step.

Here the file keyring opened in data/keyring, and the only warning is the missing token, which the next chapter fixes. Adding --check also exchanges every stored refresh token with Google, so use the plain form while you are offline.

As the install guide explains, gog auth doctor exits with code 0 whenever it produces a report, including one with status warn. In a script, test the status field of gog --json auth doctor.

The command schema

gog schema prints a machine-readable description of the command line, generated from the running binary. It is the reference that scripts and agents use to discover commands and flags without parsing help text. Without arguments it covers the whole program, which is several megabytes of JSON:

$ gog schema --json | wc -c
6710376

The document has 4 top-level keys: schema_version, build, automation (output formats, exit codes and the active safety settings) and command (the command tree). Pass a command path to describe one command:

$ gog schema auth status --json | jq '.command | {path, help, usage}'
{
  "path": "gog auth status",
  "help": "Show auth configuration and keyring backend",
  "usage": "auth status"
}
$ gog schema gmail search --json | jq '.command.flags[] | select(.name == "max")'
{
  "name": "max",
  "aliases": [
    "limit"
  ],
  "help": "Max results",
  "type": "int64",
  "default": "10",
  "has_default": true,
  "placeholder": "10"
}

A command object has type, name, path, help, usage and flags, plus aliases, positionals or subcommands where they apply. Output, Schemas and Dry Runs uses the schema in more depth.

Shell completion

gog completion <shell> prints a completion script for bash, zsh, fish or powershell. For Bash, for example:

gog completion bash >> ~/.bash_completion