Rewrite history

From doodledood/claude-code-plugins · View interactive version

Rewrite history is an AI agent skill from the GitHub repository doodledood/claude-code-plugins. Rewrite branch into clean, narrative-quality commits. Creates backup, reimplements on fresh branch, verifies byte-identical, then replaces original branch history.

How to use this skill

Skill file

Rewrite the current branch's history into clean, narrative-quality commits suitable for code review.

Goal

Transform messy development history into a logical story reviewers can follow commit-by-commit. Original branch is rewritten; backup preserved for rollback.

Arguments

$ARGUMENTS = optional flags (--auto skips interactive approval)

Preconditions

Abort with clear error if:

Execution

  1. Create backup branch: {branch}-backup-{timestamp} — permanent until manually deleted
  2. Analyze the diff between current branch and main—understand the complete change set
  3. Create temp branch from main for clean reimplementation
  4. Plan the narrative—structure changes into logical, self-contained commits (foundations → features → polish)
  5. Reimplement by recreating changes commit-by-commit with conventional commit messages; use --no-verify for intermediate commits
  6. Verify byte-identical: git diff {original-branch} MUST be empty—abort if any difference
  7. Replace original branch: point original branch to clean history (final commit runs hooks normally)
  8. Offer to push with --force-with-lease

Verification Requirement

The byte-identical check is non-negotiable. If git diff {backup-branch} shows ANY difference after reimplementation:

Constraints

Interactive Mode

Unless $ARGUMENTS contains --auto:

Rollback

If anything goes wrong: git reset --hard {branch}-backup-{timestamp}

Output

Report commit count, backup branch name, and the new commit log.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.