# Edit a Shared Google Doc Under Live Collaboration

## Scope the edit before touching the doc

- Read the document with `documents get` through the Google Docs connector before any edit and note which sections are in scope and which named sections must not change.

- Open a shared document only by an exact document ID from the user or from a connector result and say so when Drive search cannot supply it.

- Save the pre-edit text of the out of scope sections so you can compare them byte for byte after the edit.

- Confirm before editing a shared document, as the base Google Docs connector requires, and state the exact sections you will touch.

## Re-read and anchor every change

- Fetch the document again immediately before each `batchUpdate` call because a collaborator typing in the same doc shifts character indexes between reads.

- Anchor each insertion or replacement on unique surrounding text you just read rather than on an index captured in an earlier read.

- Work in small batches and fetch the document again after each batch before computing the next index.

- Stop and re-read when an index no longer lands on the text you expected instead of forcing the edit at that offset.

## Verify formatting, not just text

- Read back the changed ranges with their text styles after editing because a plain text read-back misses formatting the new text inherited from its neighbours.

- Sweep inserted names, citations and headings for unintended bold, italics, superscript and underline carried in from the insertion point.

- Clear inherited styling that the surrounding passage does not use and re-check the range after clearing it.

- Report an edit as done only after this formatting sweep passes, not after the write call alone succeeds.

## Prove the untouched parts stayed untouched

- Compare the out of scope sections against the pre-edit copy and report that they are unchanged only when the comparison is exact.

- Re-read the full edited section in order and check word count or reading time when the user gave a target length.

- Name what you changed, what you verified and anything a collaborator changed while you worked.

## Available connectors

- [Google Docs](/opt/hatch/connectors/google_docs/CONNECTOR.md) for reading a document by ID, targeted batch updates and read-backs with text styles.

- [Google Drive](/opt/hatch/connectors/google_drive/CONNECTOR.md) for finding a document by title when the user has not supplied its ID.

- Use `muse.connector_search` to find other connectors and `muse.skill_search` to find related skills.

- If nothing here fits, look on the web for a maintained API or MCP server and set it up with [Custom Connectors and MCPs](/opt/muse/skills/custom-connector-setup/SKILL.md), or build a custom connector.

## Alternatives for better results

- Ask the collaborator to pause or work in a separate section when the same paragraphs need heavy rewriting, since parallel edits to one passage keep invalidating indexes.

- Draft a large replacement in a local file and insert it in one anchored batch when the change is bigger than a few paragraphs.