writing — Claude Code prompt: what it does, how to install
writing tells the agent how to edit a spreadsheet: formulas instead of hand-computed numbers, bulk range ops instead of cell-by-cell writes.
Apache-2.0 ★ 12,746 updated 2026-10-29
.claude/commands/writing.mdWhat writing does
The command file spells out which operations the agent may use on a sheet: set_cell, set_formula, set_range, fill_range, copy_range, move_range, convert_to_values, clear_range. Each entry lists its arguments and its ceiling. fill_range works like Excel's fill handle, tiling the source block and its formulas across the target while relative references shift and $ anchors hold.
A batch tops out at 2000 changed cells; range-level ops reach 200 000. Retyping a table one cell at a time runs into that cap, so set_range does the same work in a single call. copy_range carries a block once, move_range does the same and then clears the source.
Formula rules get their own section. The agent is told to leave calculations to formulas and never paste in a number it computed itself. Criteria formulas that scan a large column, such as a SUMPRODUCT/COUNTIF distinct count, are rejected because they evaluate quadratically; aggregate_range answers that question instead.
What it helps with
- fill a formula down an entire column in one operation
- move a block of rows to another sheet with formulas intact
- split a large sheet into one sheet per value in a column
- freeze formula results before deleting the source data
- rewrite a whole row range so old fragments don't survive
Example prompts for the agent
/writingFill column C with=B2*1.2down to the last row- Copy the
Januarysheet into a new one, formulas included - Replace the formulas in
D2:D500with their current values
How to install writing
Manually: put the files in place
.claude/commands/writing.mdHow to use
Paste the text at the start of a chat or into project instructions
Questions about writing
How do I install writing in Claude Code?
Put the command file at .claude/commands/writing.md inside your project. It is then available as /writing.
What does writing do?
It defines the sheet operations the agent can call and the rules around formulas: bulk range writes, fills, block copies and moves, converting formulas to values.
Why is a SUMPRODUCT/COUNTIF distinct count rejected?
Formulas whose criteria function receives a large column as its per-element argument evaluate quadratically and would freeze the app. The agent counts distinct values with aggregate_range and reports the number in text.
Source text
writing.md · Apache-2.0
# Content writing guide (writing)
## Operation definitions
- `{op:"set_cell", sheetId, address:"B2", value}` — writes a single value (string/number/boolean/null). Optional `expectedValue` for concurrency protection.
- `{op:"set_formula", sheetId, address, formula:"=SUM(A1:A10)"}` — writes a formula, must start with =. Optional `expectedFormula`.
- `{op:"clear_cell", sheetId, address}` — clears a single cell.
- `{op:"set_range", sheetId, start:"B2", values:[[row1], [row2], …]}` — bulk write: a 2D array laid out by rows, spreading right and down from start. **values must be rectangular — every row the same length** (use null for a cell to clear; a shorter row would silently leave stale content behind). Instead of start you may pass `range:"B2:D5"`, whose size must exactly match values. **Strings starting with = are written as formulas.** Always use set_range for contiguous regions; never split them into many set_cell ops.
- **When rewriting rows of an existing table, cover the full row span**: values rows should span all of the table's columns (or the write should be paired with clear_range for the leftover cells) so no stale fragments from the old content survive next to the new one.
- `{op:"fill_range", sheetId, source:"B2", target:"B2:B88588", sourceSheetId?}` — fill/copy, Excel's fill handle as one operation: the source block's values **and formulas** tile across the target. Relative references shift per copy (=A2+1 filled down becomes =A3+1, =A4+1, …); `$`-anchored axes stay pinned. **This is THE way to fill a formula or pattern down a whole column** — one small op instead of spelling out thousands of set_range rows. Rules: write/verify the source cell(s) first, then fill; source ≤ 2000 cells; target up to **200,000 cells** and each dimension a whole multiple of the source's; an overlapping source must sit at the target's top-left (fill-down/right includes the source as the first tile); `sourceSheetId` lets the source live on another sheet (copy header rows between sheets). Fills of formulas that re-scan a large absolute range per copy (=SUM(B$2:B$88588), lookups against big tables) are rejected — use relative references so each row touches only its own cells.
- `{op:"copy_range", sheetId, source:"A1:F5000", target:"H1", sourceSheetId?, filterColumn?, filterValues?}` — copies one block to one destination exactly once (Excel copy → paste as one operation), values **and formulas**; relative references shift by the block's offset, `$`-anchored axes stay pinned. On large streamed workbooks (cached-value mode) formulas are carried live within the shared engine budget (their referenced file cells are loaded on demand); when the copied formulas' references exceed that budget — or a formula is too expensive to evaluate live — the copy writes the source cells' current values instead and the result notes how many formula cells were frozen and why. `target` is the destination's top-left cell (or a range exactly the source's size). Unlike fill_range there is no tiling and the source may be large — up to **200,000 cells** — so this is THE way to duplicate a big table or move a column's data (source and target must not overlap; `sourceSheetId` copies across sheets).
- **Filtered copy (row extraction)**: with `filterColumn` (an absolute column letter inside the source range) and `filterValues` (1–100 strings), copy_range copies **only the source rows whose cell in that column matches one of the values** (compared as text, trimmed, case-insensitive), compacted at the target with no gaps, as **static values** (formulas are not carried over). `target` must be a single anchor cell. It reads the real file data chunk by chunk, so it works on large streamed workbooks where FILTER-style formulas are rejected. This is THE way to split a big sheet by a column's values: aggregate_range the column first for the distinct values and counts, add_sheet each target with `rows` sized to its count (plus header), copy the header row with a plain copy_range, then one filtered copy_range per value with the target anchored below the header. A filter that matches zero rows fails with an error (check the actual cell values); a match count exceeding the target sheet's grid also fails and tells you how many rows were needed.
- `{op:"move_range", sheetId, source:"A2:V14", target:"A1", sourceSheetId?}` — Excel's cut → paste as one operation: copies the block exactly like copy_range (values **and** formulas, relative references shift, up to **200,000** cells), then clears the source cells. `sheetId` is the destination sheet; `sourceSheetId` lets the source live on another sheet. Source and target must not overlap; the source rows stay in place as empty cells — follow with delete_rows / delete_cols in a separate structural batch if the user wants them gone.
- **Moving existing data — pick the op by what changes**: when the user says move / cut / relocate / transfer / "put these rows on that sheet" and the content travels unchanged, use ONE move_range (or copy_range when the original must stay). Rewriting the cells through set_cell / set_range is only right when the data changes on the way (reordered or dropped columns, transposed, transformed values) or the geometry rules out a block op (overlapping source and target). Never read a block and re-type it cell by cell when move_range / copy_range can carry it: it is slower, shows the user hundreds of edits, and risks typos.
- `{op:"convert_to_values", sheetId, range:"B2:B88588"}` — freezes formulas into their current computed values (Excel's copy → paste-values), up to **200,000 cells**. Only formula cells change; values, text, and formatting stay untouched. Use when the user asks to "remove the formulas but keep the results", or before deleting source data that formulas reference. It reads what the grid holds **now**, so it must not share a batch with ops writing formulas into its range (rejected) — write the formulas in one batch, verify the results, then convert in a follow-up batch.
- `{op:"clear_range", sheetId, range:"A1:C10"}` — clears a rectangular region (up to 200,000 cells — whole columns are fine).
Limit: at most 2000 expanded cell changes per batch — the range-level ops fill_range / copy_range / move_range / convert_to_values / clear_range / find_replace / format_range are exempt and handle up to 200,000 cells each.
## Formula rules
- **Always leave calculations to formulas** — never compute values yourself and hard-code them; the table should update automatically when source data changes.
- **No array-criteria formulas over large ranges**: formulas where a criteria/lookup function receives a large range as its per-element argument — e.g. the distinct-count idiom `SUMPRODUCT(1/COUNTIF(A2:A88588,A2:A88588))` — evaluate quadratically, would freeze the app, and are rejected. For distinct counts / frequency statistics use the aggregate_range tool and report the answer in text.
- If a reference can be expressed with relative/absolute references ($), don't write a constant.
- Stay consistent with existing conventions: if earlier rows use formulas, new rows use formulas too; if earlier tax amounts are negative, newly filled ones should be negative too.
**Wrong** — computed mentally and hard-coded:
```json
{ "op": "set_cell", "sheetId": "s1", "address": "B10", "value": 5000 }
```
**Right** — let the sheet compute it:
```json
{ "op": "set_formula", "sheetId": "s1", "address": "B10", "formula": "=SUM(B2:B9)" }
```
## Share/percentage columns (where the total must be 100%)
- Keep full precision in the cells: use a formula like `=B4/SUM($B$4:$B$8)` — do **not** write rounded constants row by row, which makes the total display 100.1% or 99.9%.
- Rounding belongs to display formatting (format_range's numberFormat, at least `0.000%`), not to the stored value.
## Values and units
- Ratios/growth rates/shares and other relative values are stored as **decimals in (0,1)** (0.1234 means 12.34%); if the source data is a percent number like 26.64, divide by 100 before writing.
- Keep units, decimal places, and currency symbols consistent within a column; note the unit in the header or title (e.g. "Amount (USD millions)").
- Dates: prefer writing ISO form (2026-07-23) + a number format controlling the display.
## Find & replace (find_replace)
`{op:"find_replace", sheetId, range:"A1:D50", find:"old text", replace:"new text", matchCase?, wholeCell?}`
- Replaces **text values only**: formula cells and numbers are untouched.
- Case-insensitive by default (matchCase:true enables case sensitivity); with wholeCell:true a cell is replaced only when its whole content matches exactly.
- range is required, up to **200,000 cells** (a whole used column is fine). Ranges ≤2000 cells expand into per-cell edits (preview/undo match manual input) and must be loaded first; larger ranges apply as one range-level scan that loads each region itself.
© genspark-ai · Apache-2.0 · genspark-ai/genoffice