03 / GOOGLE WORKSPACE · 6 min read · UPDATED 2026-12-06

Reading Public & Private Google Docs and Drive URLs from the Terminal & AI Agents

Open any public Google Doc or Drive .txt/.md URL with zero login (gdocs <url>), pipe styled -p ANSI or -j JSON output, edit private docs safely with exact UTF-16 offsets and requiredRevisionId locks, and wire 11 typed stdio & Streamable HTTP MCP tools on :8794.

Zero-Login Public URLs 11 MCP Tools HTTP :8794 5.4 MiB Binary
Package & Repo @bitefoundry/gdocs@0.4.0 (BiteFoundry/google)
Binary & Idle CPU 5.4 MiB native Rust · 0.0% idle CPU
MCP Surface gdocs mcp (11 tools + HTTP /mcp)
Local HTTP API 127.0.0.1:8794

1. Zero-Login Public Google Docs & Drive URL Reading (gdocs <url>)

Sharing an RFC, design doc, or runbook as a public Google Doc link usually forces engineers and AI agents through a 300–800 MB Chromium tab or brittle OAuth setup just to read plain text. With @bitefoundry/gdocs@0.2.2 (built from the BiteFoundry/google monorepo), passing any public Google Doc URL (docs.google.com/document/d/...) or public Google Drive .txt/.md link (drive.google.com/file/d/...) works immediately with zero authentication.

Open it in the borderless Google Docs Native Blue editorial TUI (#1A73E8 Light / #669DF6 Dark, with z pane zoom, which-key leader popups, and a 16-theme Ctrl+T live picker), print styled ANSI straight to stdout with -p, or extract structured JSON with -j—with automatic macOS Hangul NFD→NFC normalization built in.

Install & Read Any Public Google Doc or Drive File Instantly
# Install the 5.0 MiB native Rust binary
brew install bitefoundry/tap/gdocs
# Or curl (macOS/Linux): curl -fsSL https://bitefoundry.dev/i | sh -s gdocs
# Or Windows PowerShell: & ([scriptblock]::Create((irm https://bitefoundry.dev/w))) gdocs
# Or npm:                npm i -g @bitefoundry/gdocs

# Zero-login interactive editorial TUI reader
gdocs "https://docs.google.com/document/d/<DOC_ID>/edit"

# Zero-login non-interactive ANSI print mode (great for pipes & pagers)
gdocs "https://docs.google.com/document/d/<DOC_ID>/edit" -p | less -R

# Zero-login structured JSON extraction for scripts & LLMs
gdocs "https://docs.google.com/document/d/<DOC_ID>/edit" -j

# Also works for public Google Drive .txt / .md links
gdocs "https://drive.google.com/file/d/<FILE_ID>/view" -p

# Try offline without any URL or account
gdocs --demo

2. Private Docs: 4-Mode Authentication & Local FTS5 + CJK Search

When you need to list private Drive documents, read internal comments, or push edits, gdocs supports four clean authentication paths without locking you into a single enterprise flow:

  • OAuth 2.0 PKCE (Read/Write): Interactive browser sign-in with tokens stored in your local OS keychain.
  • Read-Only OAuth Scope: Restricts the Google OAuth grant itself so neither CLI nor MCP can ever modify documents.
  • gcloud Application Default Credentials (ADC): Reuses existing GCP developer credentials with zero extra client secrets.
  • Service Account JSON: Headless CI/CD automation and server-side document generation pipelines.

3. UTF-16 Exact Editing Engine, revisionId Locks & --dry-run Diffs

Google Docs' batchUpdate API indexes document positions in UTF-16 code units—not UTF-8 bytes and not Unicode scalar values. Naive editors that pass Rust/UTF-8 byte offsets silently corrupt documents containing Korean Hangul (3 UTF-8 bytes = 1 UTF-16 code unit) or Emoji surrogate pairs (4 UTF-8 bytes = 2 UTF-16 code units).

gdocs computes exact UTF-16 code-unit spans for every edit and pairs them with four layers of mutation safety:

  • Uniqueness Enforcement (match_count == 1): --find / --replace and MCP replace_doc_text abort before contacting Google if a target phrase matches zero times or multiple times.
  • Optimistic Concurrency (revisionId): Every write binds to the document's last-seen revisionId, preventing silent clobbering if a teammate edited the doc concurrently.
  • Unified --dry-run Diffs: Preview exact section or text replacements locally before committing a single API call.
  • TUI Shift+Y Confirmation Modal: Pushing edits from the interactive TUI requires explicit uppercase Shift+Y (normalized for Korean 2-beolsik Shift+ㅛ).

4. Wiring All 10 Typed MCP Tools (+ --read-only & HTTP :8794)

Register gdocs mcp in Claude Code, Cursor, or Codex to expose 10 typed stdio MCP tools backed by local SQLite WAL + FTS5 (plus automatic 1–2 character Korean/CJK LIKE fallback). Pass --read-only to strip all 4 write tools at startup.

Claude Code, Cursor & Codex MCP Setup
# Claude Code (full 10 tools or safe 6-tool --read-only mode)
claude mcp add gdocs -- gdocs mcp
claude mcp add gdocs-ro -- gdocs mcp --read-only

# Start local HTTP JSON API on 127.0.0.1:8794
gdocs serve --port 8794
Cursor (.cursor/mcp.json) / Claude Desktop
{
  "mcpServers": {
    "gdocs": {
      "command": "gdocs",
      "args": ["mcp"]
    }
  }
}
MCP ToolModePurpose & Safety Guarantee
get_docReadFetches a public or private Google Doc (accepts doc ID or full URL) as clean structured Markdown/JSON.
list_doc_sectionsReadLists heading hierarchy and section anchors so agents target specific sections without full-doc bloat.
list_docsReadLists accessible Google Docs from Drive and local SQLite cache.
search_docsReadSearches cached docs via SQLite FTS5 + 1–2 char CJK LIKE fallback.
list_doc_commentsReadReads review comments and anchored discussion threads on a Google Doc.
gdocs_statusReadReports active auth mode, cache health, and read-only status.
create_docWriteCreates a new Google Doc with initial Markdown content (blocked under --read-only).
append_doc_markdownWriteAppends formatted Markdown cleanly at document end using exact UTF-16 indices.
replace_doc_sectionWriteReplaces a targeted heading section under optimistic revisionId locking.
replace_doc_textWritePerforms exact UTF-16 find/replace enforcing match_count == 1 and revisionId lock.

Frequently Asked Questions

Can Claude Code or a shell script read a public Google Doc without setting up Google Cloud OAuth?

Yes. Any publicly viewable Google Doc (`docs.google.com/document/d/...`) or public Drive `.txt`/`.md` link (`drive.google.com/file/d/...`) can be read immediately with `gdocs "<URL>"`, `gdocs "<URL>" -p`, `gdocs "<URL>" -j`, or MCP `get_doc` with zero login.

Why do UTF-16 code-unit offsets matter when AI agents edit Google Docs?

Google Docs' API counts character indices in UTF-16 code units. Hangul characters take 3 bytes in UTF-8 but 1 UTF-16 code unit, while emoji take 4 UTF-8 bytes and 2 UTF-16 code units. Computing exact UTF-16 spans prevents off-by-one corruption in multilingual or emoji-rich docs.

Where is the source code for @bitefoundry/gdocs hosted?

`gdocs` is developed and released in the `BiteFoundry/google` monorepo (`https://github.com/BiteFoundry/google`), sharing `google-core` across BiteFoundry's Google Workspace terminal binaries. Installers at `bitefoundry.dev/i` and `bitefoundry.dev/w` automatically map `gdocs` to `BiteFoundry/google` releases.

Related BiteFoundry Product Pages

More Technical Guides