rewrite-history

rewrite-history is a command for coding agents from alleneubank/claude-code. It costs 0 tokens per session (2,140 once invoked), scanned A, original, Apache-2.0.

A command for replacing the current Git branch history with a clean sequence of understandable commits. Git is the version-control system used to track code changes.

In plain words
What is it for?
Use it to reorganize messy branch history before review and update the rewritten branch on the remote repository.
Why use it?
It helps reviewers follow how the work developed, while requiring confirmation before history-changing commands.

Command

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add commands/alleneubank/claude-code/rewrite-history
Clone the repo
git clone --depth 1 https://github.com/alleneubank/claude-code

Wrote this? Show the measurements

A badge with what this costs and how it scanned, read live from this page, so it follows the numbers instead of freezing them. Markdown for a README, HTML for a documentation site or a project page.

agentmods badge for rewrite-history

README.md
[![agentmods](https://agentmods.dev/badge/commands/alleneubank/claude-code/rewrite-history.svg)](https://agentmods.dev/commands/alleneubank/claude-code/rewrite-history)
Your own site
<a href="https://agentmods.dev/commands/alleneubank/claude-code/rewrite-history"><img src="https://agentmods.dev/badge/commands/alleneubank/claude-code/rewrite-history.svg" alt="Measured on agentmods" height="20"></a>
Per session 0 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 2,140 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00000 $0.02140
Opus 5 $0.00000 $0.01070
Sonnet 5 $0.00000 $0.00428
Haiku 4.5 $0.00000 $0.00214

Measured 4d ago against content hash cbc356692edd, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

rewrite-history scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured 4d ago.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

commands/rewrite-history.md · 167 lines

How it starts

The opening of the file, as written. The whole thing — 167 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Reimplement the current branch with a clean, narrative-quality git commit history suitable for reviewer comprehension. Execute each step fully before proceeding to the next.

Determine Branch Name

First, determine the current branch name: !git branch --show-current

Store this value and use it wherever {branch_name} appears in subsequent steps.

Determine Default Branch

First, determine the repository's default branch: !gh repo view --json defaultBranchRef --jq '.defaultBranchRef.name'

Store this value and use it wherever {default_branch} appears in subsequent steps.

Hard Rules

  • Rewrite history in-place on the current branch name ({branch_name}).
  • You may create additional branches for independent changes (see Triage Changes and Create Independent Branches below).
  • Create a local backup ref before rewriting (prefer an annotated tag). Do not push backup refs unless I explicitly ask.
  • Before any history-rewriting command (git reset, git rebase, git push --force*), print the exact command(s) you will run and wait for my confirmation.
  • After rewriting, update the remote branch using git push --force-with-lease origin HEAD:{branch_name}. Do not push independent branches without my confirmation.
  • If syncing with origin/{default_branch} results in conflicts, abort and stop. Do not attempt to resolve conflicts as part of this rewrite-history workflow.

Validate and Backup

Before any changes, validate the current state:

  • Run git status to confirm no uncommitted changes or merge conflicts exist
  • Run git fetch origin to get the latest remote state
  • If issues exist, resolve them before proceeding
  • Record the current HEAD sha for verification later

Analyze Diff

Study all changes between the current branch and the default branch to form a complete understanding of the final intended state. Use git diff and read modified files to understand:

  • What functionality was added, changed, or removed
  • The logical groupings of related changes
  • The dependencies between different parts of the implementation

Read the full file on GitHub · 167 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. 4d ago First seen · 167 lines · 0 tokens per session scan A cbc356692edd

Subscribe to this mod's changes

rewrite-history is a command published in the GitHub repository alleneubank/claude-code (52 stars, last pushed 2mo ago), licensed Apache-2.0. It costs nothing until one of its globs matches a file; then it loads 2,140 tokens. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-30.