# 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.

Source: https://fullbytedeveloper.com/blog/claude-code-for-google-sheets
Published here: 2026-11-26, updated 2026-11-26

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](/blog/claude-code-for-accounting) when the sheet is a workpaper. Browse the [Claude Code topic](https://fullbytedeveloper.com/blog/topic/claude-code).

## 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]

```bash
pip install gspread
```

```python
import 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:

1. Header cells drift from `SCHEMA.md`.
2. Duplicate keys appear in the key column.
3. 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:

1. Nightly export or API pull into a `raw_` tab or local CSV.
2. Script transforms into a `mart_` tab with fixed headers.
3. Claude drafts the narrative from `mart_` only.
4. Person publishes the chart or email.

For accounting close sheets, continue on [Claude Code for accounting](/blog/claude-code-for-accounting). For DuckDB and local files, use [Choose five tools for spreadsheet data](/blog/claude-code-spreadsheet-data-tools). [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.

## Sources

1. [Apps Script Spreadsheet Range.getFormulas(), accessed 2026-11-26](https://developers.google.com/apps-script/reference/spreadsheet/range)
2. [Sheets API ValueRenderOption FORMULA, accessed 2026-11-26](https://developers.google.com/sheets/api/reference/rest/v4/ValueRenderOption)
3. [Google Apps Script: Extending Google Sheets, accessed 2026-11-26](https://developers.google.com/apps-script/guides/sheets)
4. [Google Sheets API concepts, accessed 2026-11-26](https://developers.google.com/sheets/api/guides/concepts)
5. [gspread authentication docs, accessed 2026-11-26](https://docs.gspread.org/en/latest/oauth2.html)
6. [gspread API: service_account, accessed 2026-11-26](https://docs.gspread.org/en/latest/api/auth.html)
7. [Anthropic Finance plugin README (spreadsheet MCP note), accessed 2026-11-26](https://raw.githubusercontent.com/anthropics/knowledge-work-plugins/main/finance/README.md)
8. [Claude Code best practices, accessed 2026-11-26](https://code.claude.com/docs/en/best-practices)
9. [Full Byte Developer: Choose five tools for spreadsheet data](https://fullbytedeveloper.com/blog/claude-code-spreadsheet-data-tools)
10. [Full Byte Developer: Claude Code for accounting](https://fullbytedeveloper.com/blog/claude-code-for-accounting)
