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.
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 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.
gcloudApplication 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/--replaceand MCPreplace_doc_textabort before contacting Google if a target phrase matches zero times or multiple times. - Optimistic Concurrency (
revisionId): Every write binds to the document's last-seenrevisionId, preventing silent clobbering if a teammate edited the doc concurrently. - Unified
--dry-runDiffs: Preview exact section or text replacements locally before committing a single API call. - TUI
Shift+YConfirmation Modal: Pushing edits from the interactive TUI requires explicit uppercaseShift+Y(normalized for Korean 2-beolsikShift+ㅛ).
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 (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
{
"mcpServers": {
"gdocs": {
"command": "gdocs",
"args": ["mcp"]
}
}
}
| MCP Tool | Mode | Purpose & Safety Guarantee |
|---|---|---|
| get_doc | Read | Fetches a public or private Google Doc (accepts doc ID or full URL) as clean structured Markdown/JSON. |
| list_doc_sections | Read | Lists heading hierarchy and section anchors so agents target specific sections without full-doc bloat. |
| list_docs | Read | Lists accessible Google Docs from Drive and local SQLite cache. |
| search_docs | Read | Searches cached docs via SQLite FTS5 + 1–2 char CJK LIKE fallback. |
| list_doc_comments | Read | Reads review comments and anchored discussion threads on a Google Doc. |
| gdocs_status | Read | Reports active auth mode, cache health, and read-only status. |
| create_doc | Write | Creates a new Google Doc with initial Markdown content (blocked under --read-only). |
| append_doc_markdown | Write | Appends formatted Markdown cleanly at document end using exact UTF-16 indices. |
| replace_doc_section | Write | Replaces a targeted heading section under optimistic revisionId locking. |
| replace_doc_text | Write | Performs 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
Microsoft Teams MCP for Claude Code, Cursor & Codex
Connect Claude Code, Cursor, and Codex to Microsoft Teams via native Rust MCP & CLI (@bitefoundry/teams@0.14.0, ~33 MB RAM vs 1,240 MB Desktop, 16 stdio & Streamable HTTP MCP tools, --json compact reads, -p ANSI print, HTTP :8788, Shift+Y and confirm:true delete safety).
Atlassian Jira & Confluence MCP & Terminal Client (Zero Docker)
Unified Atlassian Jira & Confluence MCP server and Rust terminal client without Docker or Node (@bitefoundry/atlassian@0.12.0, 37 MCP tools / 15 --read-only tools, ADF <-> Markdown, cross-linking, j/cf aliases, HTTP :8789 + POST /mcp).
Unified Microsoft 365 MCP Stack: Outlook, OneNote & SharePoint/OneDrive
Unified Microsoft 365 MCP stack in native Rust: Outlook (24 tools, :3939, fields projection), OneNote (18 tools, :8793, scoped data-id edits, native Linux), SharePoint & OneDrive (20 tools, :8790, ETag-safe uploads), all with OS keychain auth and zero cloud relay.