safe-history-rewrite

safe-history-rewrite is a skill for Claude Code, Codex from toejough/engram. It costs 58 tokens per session (1,237 once invoked), scanned A, original, Apache-2.0.

A safety procedure for rewriting Git history, meaning changing existing commits across branches or other references. It covers preserving recovery information and safely force-pushing the rewritten result.

In plain words
What is it for?
Use it when removing secrets from commit history, rewriting several branches, preparing a force-push, or checking that remote-tracking references are current.
Why use it?
History rewrites can erase the original commits or push over newer remote work if references are handled carelessly. The procedure keeps recovery points and avoids relying on a backup branch that may be rewritten too.

Skill for Claude CodeCodex

Written for no agent in particular: nothing here depends on one.

Good fit Use it when removing secrets from commit history, rewriting several branches, preparing a force-push, or checking that remote-tracking references are current.

Compare 6 skills from other repositories ↓
Install with agentmods
npx agentmods add skills/toejough/engram/safe-history-rewrite
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.

Any agent
npx skills add toejough/engram --skill safe-history-rewrite
Clone the repo
git clone --depth 1 https://github.com/toejough/engram

Made for: Claude Code, Codex.

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 safe-history-rewrite

README.md
[![agentmods](https://agentmods.dev/badge/skills/toejough/engram/safe-history-rewrite/github.svg)](https://agentmods.dev/skills/toejough/engram/safe-history-rewrite)
Your own site
<a href="https://agentmods.dev/skills/toejough/engram/safe-history-rewrite"><img src="https://agentmods.dev/badge/skills/toejough/engram/safe-history-rewrite/github.svg" alt="Measured on agentmods" height="20"></a>

Or the 80×15 button, for a site that already has a row of RSS and ATOM ones. Only the verdict fits; the numbers stay here.

agentmods 80×15 button for safe-history-rewrite

Your own site · 80×15
<a href="https://agentmods.dev/skills/toejough/engram/safe-history-rewrite"><img src="https://agentmods.dev/badge/skills/toejough/engram/safe-history-rewrite.svg" alt="Reviewed on agentmods" width="80" height="20"></a>
Per session 58 Skills are progressive disclosure: only the name and description are preloaded; the body loads when the skill is used.
When invoked 1,237 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. A grade says what 26 rules found in the file — not that it is safe.
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.1 $0.00058 $0.01237
Opus 5.5 $0.00023 $0.00495
Sonnet 5.5 $0.00012 $0.00247
Haiku 4.5 $0.00006 $0.00124

Measured 28d ago against content hash 74175bf4a2f1, method: parsed. Prices are Anthropic first-party input rates as of 2026-10-07, from the pricing page.

Security

Grade A, and why

safe-history-rewrite 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 28d 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.

dev/eval/cumulative/runbook_vs_skill/phase2/encodings/taskHR/HR-S/skills/safe-history-rewrite/SKILL.md · 59 lines

How it starts

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

Safe Git History Rewrite and Force-Push

Overview

History rewrites with git filter-branch (or similar tools that rewrite all refs) are powerful for removing sensitive data but dangerous if you lose the ability to recover the pre-rewrite state or if you force-push against stale tracking refs. This skill prevents three critical failures: the backup branch getting swept up and lost, force-push failing with outdated tracking refs, and sensitive data becoming unrecoverable.

When to Use

Before rewriting git history with git filter-branch or any all-refs history rewrite, especially when:

  • Keeping a safety backup branch for recovery
  • Removing sensitive data (API keys, passwords, tokens)
  • Force-pushing the result to a remote
  • Multiple branches need to be rewritten at once

Procedure

  1. Record the pre-rewrite tip outside the ref space. Before starting any rewrite, capture the current tip of each branch you're about to rewrite as a bare SHA (not a branch name). Alternatively, rely on refs/original/ (created by filter-branch) plus the reflog for recovery — but do NOT rely on a plain backup branch, since the rewrite can sweep it.

  2. Scope the rewrite to explicit refs, not -- --all. A backup branch is not a safe exception to this rule — git filter-branch ... -- --all rewrites every ref it can see, backup branches included. Specify the exact refs you want rewritten (e.g., -- main dev-feature) or use -- --all only if you intend to rewrite the backup branch too (and understand it will be gone after).

  3. Run the history rewrite. Execute your filter-branch command with the appropriate filters (e.g., --index-filter, --tree-filter, or --subdirectory-filter) to achieve the rewrite goal.

  4. Before force-pushing, refresh local tracking refs with git fetch. The rewrite also rewrites your local remote-tracking refs (like origin/main in .git/refs/remotes/origin/). These now point to the old, pre-rewrite commits. A stale tracking ref will cause --force-with-lease to fail, thinking the remote has changed. Run git fetch origin to refresh refs/remotes/origin/* with the real remote state.

Read the full file on GitHub · 59 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. 28d ago First seen · 59 lines · 58 tokens per session scan A 74175bf4a2f1

Subscribe to this mod's changes

safe-history-rewrite is a skill published in the GitHub repository toejough/engram (8 stars, last pushed yesterday), licensed Apache-2.0. It adds 58 tokens to every session and 1,237 once invoked, about $0.0002 per session on Opus 5.5. 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-09-21.