Claude Code for Google Sheets: Apps Script and API
Wire Sheets through Apps Script or gspread, audit formulas, and keep schema hygiene before any agent write.
Published here , updated · 10 sources · Resume reading
Claude Code helps Sheets when the sheet is a contract: named tabs, typed columns, and a checksum after every write. Wire Apps Script or gspread, export formulas with Range.getFormulas() or Sheets ValueRenderOption FORMULA, then stage writes on a non-prod tab. [1] [2]
After this page you can pick Apps Script versus API, auth gspread with a service account, and fail a write when headers or totals drift. Related: Claude Code for accounting when the sheet is a workpaper. Browse the Claude Code topic.
Decide Apps Script vs Sheets API first
Google's Apps Script Sheets guide covers scripts that call SpreadsheetApp for menus, custom functions, and bound automation inside a spreadsheet. The Sheets API concepts guide describes spreadsheets, sheets, and cell value resources over HTTPS for external apps. [3] [4]
Use Apps Script when the trigger must live next to the sheet (onEdit, time-driven). Use the Sheets API (or gspread on top of it) when Claude Code should run from your laptop or CI against a service account. [3] [4] [5]
Authenticate gspread with a service account
gspread documents service-account auth: enable Sheets and Drive APIs, create a service account key, share the spreadsheet with client_email, then call gspread.service_account(). Default scopes are read/write for Sheets and Drive; READONLY_SCOPES exists when you only need reads. [5] [6]
pip install gspreadimport gspread
gc = gspread.service_account(filename="path/to/service_account.json")
sh = gc.open("Month-end workpaper")
print(sh.sheet1.get("A1"))Warning: keep the JSON key out of git and out of Claude's default read set. Point Claude at a wrapper script that loads the key from a secret store. [5] [8]
You should print a known cell value before any write path is enabled.
Put schema hygiene in the first Claude task
Ask Claude to invent nothing about columns. Hand it a SCHEMA.md that lists tab name, header row, each column type, and the primary key. Then ask for a read-only audit that fails if:
- Header cells drift from
SCHEMA.md. - Duplicate keys appear in the key column.
- Numeric columns contain mixed text.
Claude Code best practices say to give Claude a check it can run. Make that check a script that exits non-zero on drift. [8]
Audit formulas before rewriting them
Export formula text with Apps Script Range.getFormulas() or Sheets API ValueRenderOption.FORMULA into a file Claude can diff. Ask for a rewrite only of named ranges you list. Keep a staging tab for proposed values; never overwrite the production tab until the checksum of key columns matches your source CSV. [1] [2]
Anthropic's Finance plugin README notes spreadsheet MCP connectors for workpapers. If you connect one, still keep the staging-tab rule. [7]
Automate reporting as a pipeline, not a chat
A durable loop:
- Nightly export or API pull into a
raw_tab or local CSV. - Script transforms into a
mart_tab with fixed headers. - Claude drafts the narrative from
mart_only. - Person publishes the chart or email.
For accounting close sheets, continue on Claude Code for accounting. For DuckDB and local files, use Choose five tools for spreadsheet data. [9] [10]
You now have a Sheets loop for Claude Code: pick Apps Script or API, service-account gspread, schema checks, formula audit on staging, pipeline reporting.
Send this to the operator whose board pack still lives in one fragile tab.
Keep this guide
Filed under Claude Code, Dev tools
Questions about this guide
Is this the same as the spreadsheet data tools page?
No. That page picks DuckDB, csvkit, Datasette, marimo, and Anthropic's data plugin for local files. This page is live Google Sheets: Apps Script, Sheets API, and gspread.
How does gspread authenticate for a bot?
gspread's OAuth docs describe a service account JSON key. Share the spreadsheet with the service account client_email or gspread raises SpreadsheetNotFound.
Should Claude write cells directly?
Prefer read, propose, then write to a staging tab. Keep production tabs protected and require a checksum of key columns after any write.
Where do Apps Script projects live?
Google's Apps Script Sheets guide covers bound and standalone scripts that call SpreadsheetApp. Keep script source in a repo Claude can edit, then deploy through clasp or the editor you already use.
Sources
- Apps Script Spreadsheet Range.getFormulas(), accessed 2026-11-26developers.google.com
- Sheets API ValueRenderOption FORMULA, accessed 2026-11-26developers.google.com
- Google Apps Script: Extending Google Sheets, accessed 2026-11-26developers.google.com
- Google Sheets API concepts, accessed 2026-11-26developers.google.com
- gspread authentication docs, accessed 2026-11-26docs.gspread.org
- gspread API: service_account, accessed 2026-11-26docs.gspread.org
- Anthropic Finance plugin README (spreadsheet MCP note), accessed 2026-11-26raw.githubusercontent.com
- Claude Code best practices, accessed 2026-11-26code.claude.com
- Full Byte Developer: Choose five tools for spreadsheet datafullbytedeveloper.com
- Full Byte Developer: Claude Code for accountingfullbytedeveloper.com