Docsbook
← Back to catalog
automation

docs-sync

Detect and fix code↔docs drift before every push. Orchestrates a four-subagent pipeline — Haiku planner clusters changed code files, Haiku searchers find drifted pages per cluster in parallel worktrees, Sonnet editors rewrite the affected sections, and a Sonnet curator merges everything atomically into the commit. Works as a manual command or as an auto-installed pre-push git hook.

Install & use this skill

Pick your AI client — install this single skill and call it.

1. Install
npx skills add Docsbook-io/docs-skills --skill docs-sync -a claude-code
2. Use
/docs-sync

Invoke as a slash command in chat.

Or: runtime discovery via Docsbook MCP

Already connected to the Docsbook MCP server? Skip install — ask your agent to load this skill on demand.

@docsbook find_skill "docs-sync"

docs-sync — code↔docs drift orchestrator

Orchestrates four subagents (planner, searcher, editor, curator) to detect and fix documentation drift in parallel git worktrees, then atomically amend the commit before push.

Workflow#

  1. Stale-worktree cleanup — unconditionally remove any leftover docs-sync-* worktrees from previous runs before doing anything else. They are always garbage.
  2. Hook check — on first run, offer to install a pre-push git hook so the command runs automatically. On subsequent runs, skip this prompt silently.
  3. Detect changed code + docs layout — compute the diff between HEAD and the remote merge-base. If no non-documentation files changed, exit cleanly. Also detect whether docs/ is a regular folder or a git submodule (changes the apply/commit flow at step 8).
  4. MCP probe — verify the markdown-lsp MCP server is reachable. Abort with a clear error if it is not; never block push silently.
  5. Plan clusters (Haiku) — the docs-planner subagent groups changed code files into semantic clusters and produces a hypothesis per cluster about which docs sections might have drifted.
  6. Fan out per cluster (parallel) — for each cluster, create an isolated git worktree (in the main repo for regular docs/, or inside the submodule when docs/ is a submodule), then invoke docs-searcher (Haiku) to locate drifted pages with a confidence score.
  7. Edit drifted pages (Sonnet) — for each cluster whose confidence meets the threshold, invoke docs-editor (Sonnet) in the worktree to rewrite the affected sections.
  8. Curate (Sonnet) — the docs-curator subagent receives all editor hunks, resolves cross-cluster conflicts, normalizes style, drops speculative edits AND verifies grounding of CLI commands / URLs / version numbers against the original diff, then produces a final edit list.
  9. Apply atomically (branches on docs layout):
    • Regular folder: apply final edits in main repo → git add docs/git commit --amend --no-edit.
    • Submodule: apply final edits in a submodule worktree → commit inside the submodule → ask the user before pushing to the submodule's public remote → on consent, push + fast-forward the submodule + amend HEAD in the parent.
  10. Cleanup — remove worktrees unconditionally on success or no-op; keep them on awaiting_push_consent or hard failure for triage.
  11. Emit structured report — final JSON to stdout with status, submodule_commit, main_repo_commit, remote_pushes_pending, worktrees_cleaned, human_review_needed. Parent orchestrators rely on this contract.

Guardrails#

MCP Tools#

Tool Purpose
doc_workspace_outline Probe liveness of the markdown-lsp MCP server
doc_search_text Locate documentation sections relevant to a code cluster
doc_search_paths Enumerate candidate pages by path pattern
doc_resolve_link Validate internal links before and after edits
doc_outline Read page structure to plan targeted edits

Acceptance Criteria#

View source on GitHub →Browse full catalog repo →
Keywords
syncdriftpre-pushsubagentsworktreemarkdowncode-docs