# Check a stale branch is not undoing newer main work

> Check a stale branch is not undoing newer main work is an open-source agent skill for developer tools. Checks a branch for stale-base changes that would silently undo newer main work. It is available on Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose.

- **Kind:** Skill
- **Pricing:** Open source
- **Platforms:** Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Goose
- **Website:** https://github.com/wan-huiyan/agent-traffic-control/tree/main/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work
- **Repository:** https://github.com/wan-huiyan/agent-traffic-control
- **GitHub stars:** 5
- **License:** MIT
- **Skill name:** check-a-stale-branch-is-not-undoing-newer-main-work
- **Collection:** https://github.com/wan-huiyan/agent-traffic-control
- **Categories:** [developer tools](https://ai-powered.com/categories/developer-tools)
- **Listing updated:** 2026-12-04

## About

This skill guides an agent through checking whether a branch, before it merges, would delete files or roll back values and shared ledger rows that landed on main after the branch was cut. It explains that a clean merge and passing CI do not rule this out, because the damage comes from a stale working tree committed under a current parent rather than from a conflict.

The workflow fetches origin/main and compares the branch with three-dot diffs for stats and deletions, then falsifies large diff counts against the commit's own stat and the PR's file list. For shared files it greps anchored values on both trees, and for hand-edited ledgers it ships a Python script that parses both sides and compares row ids and bodies. The skill also covers recovery steps such as restoring deleted paths, rebuilding a ledger from main, and targeted reverts, plus a post-merge audit.

It expects a git repository with a fetchable origin and the GitHub CLI for PR inspection. The ledger script assumes a specific JavaScript data file layout and needs its paths and session ids edited for each repository.

## When your agent uses it

> A branch built on an out-of-date main is about to merge, or has merged, and may undo work that landed since. Use when a green, conflict-free PR deletes files you never touched, newer values or a whole redesign vanish after a sibling PR merged, rows of a shared ledger (tracker, registry, CHANGELOG) disappear or revert, or when `git diff main...HEAD` or a reviewer says your small PR touches dozens of files you did not change.

## What it can access

From a static check of the files on GitHub; nothing was run.

- [Instructions only, no scripts](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work)
- [License: MIT](https://github.com/wan-huiyan/agent-traffic-control/tree/HEAD/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work)

## Features

- **Stale-base deletion check:** Uses three-dot diffs against fetched origin/main to list files a branch would delete or touch unexpectedly.
- **Ledger row audit:** Compares row ids and bodies in a shared data file against main and flags removed or rolled-back rows.
- **Anchored value grep:** Checks that newly changed values still appear in shared files on both the branch and main trees.
- **Large diff falsification:** Compares git show stats with PR file lists to tell real over-scope from a misleading diff count.
- **Recovery procedure:** Covers restoring deleted files, rebuilding a hand-edited ledger from main, and targeted reverts after a merge.
- **Post-merge verification:** Provides commands to confirm files and needles survived on origin/main after a merge.

## Good for

- Check my PR for files it accidentally deletes before merging
- Find out whether a squash merge reverted rows in our shared tracker file
- Confirm that updated numbers on the site survived a later merge
- Restore a file that a stale branch removed from main
- Diagnose why a pull request diff shows dozens of unrelated files

## Install

### Claude Code

This skill ships in the `agent-traffic-control` plugin. In Claude Code, add the marketplace and install the plugin (it may include other skills too):

```sh
/plugin marketplace add wan-huiyan/agent-traffic-control
/plugin install agent-traffic-control@wan-huiyan-agent-traffic-control
```

Or copy only this skill to `~/.claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.claude/skills &&
rm -rf ~/.claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
cp -R "$tmp/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work" ~/.claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
rm -rf "$tmp"
```

For one project only, put the folder in `.claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work` inside it instead.

### Codex

Copy the skill folder to `~/.agents/skills/check-a-stale-branch-is-not-undoing-newer-main-work` to use it in every repository:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.agents/skills &&
rm -rf ~/.agents/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
cp -R "$tmp/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work" ~/.agents/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
rm -rf "$tmp"
```

For one repository only, put the folder in `.agents/skills/check-a-stale-branch-is-not-undoing-newer-main-work` inside it instead.

### Cursor

Copy the skill folder to `~/.cursor/skills/check-a-stale-branch-is-not-undoing-newer-main-work` to use it in every project:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.cursor/skills &&
rm -rf ~/.cursor/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
cp -R "$tmp/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work" ~/.cursor/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
rm -rf "$tmp"
```

For one project only, put the folder in `.cursor/skills/check-a-stale-branch-is-not-undoing-newer-main-work` inside it instead.

### Gemini CLI

Run in a terminal (add `--scope workspace` to install it for the current workspace only):

```sh
gemini skills install https://github.com/wan-huiyan/agent-traffic-control.git --path plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work
```

Or copy the folder to `~/.gemini/skills/check-a-stale-branch-is-not-undoing-newer-main-work` yourself.

### VS Code

For GitHub Copilot in VS Code, copy the skill folder to `~/.copilot/skills/check-a-stale-branch-is-not-undoing-newer-main-work`:

```sh
tmp=$(mktemp -d) &&
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git "$tmp" &&
mkdir -p ~/.copilot/skills &&
rm -rf ~/.copilot/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
cp -R "$tmp/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work" ~/.copilot/skills/check-a-stale-branch-is-not-undoing-newer-main-work &&
rm -rf "$tmp"
```

For one project only, put the folder in `.github/skills/check-a-stale-branch-is-not-undoing-newer-main-work` inside it instead.

### Other agents

Get the folder:

```sh
git clone --depth 1 https://github.com/wan-huiyan/agent-traffic-control.git
```

Then copy `agent-traffic-control/plugins/agent-traffic-control/skills/check-a-stale-branch-is-not-undoing-newer-main-work` into your agent's skills folder as `check-a-stale-branch-is-not-undoing-newer-main-work`. Agents that support SKILL.md read one folder per skill.

## FAQ

### Does Check a stale branch is not undoing newer main work need any scripts or tools to run?

It needs git and, for PR inspection, the GitHub CLI. The ledger audit is a Python script included in the skill, which reads a specific data file path that you must edit for your repository.

### Is a merge conflict a sign that this problem is happening?

No. The skill says silent reverts usually produce no conflict and a green, mergeable PR, so conflicts are not the signal to watch.

### Why is merging origin/main before a PR not enough?

The skill notes that against a stale tree a merge is a no-op, so it counts as hygiene rather than as the check that prevents a revert.

### How do I install Check a stale branch is not undoing newer main work in Claude Code?

Copy the skill folder from GitHub to ~/.claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work to use it in all your projects, or to .claude/skills/check-a-stale-branch-is-not-undoing-newer-main-work in one project. Or install the agent-traffic-control plugin, which includes it: /plugin marketplace add wan-huiyan/agent-traffic-control, then /plugin install agent-traffic-control@wan-huiyan-agent-traffic-control.

### Does Check a stale branch is not undoing newer main work run scripts?

No. It is instructions only, with no scripts. This comes from a static check of the files on GitHub; nothing was run. Read the files before you install it.

### Which AI agents can use Check a stale branch is not undoing newer main work?

Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf and Goose. Each reads skills in the SKILL.md format from its own folder; the install steps on this page list them.

### What are the best alternatives to Check a stale branch is not undoing newer main work?

The closest alternatives to Check a stale branch is not undoing newer main work are Git diff 2dot vs 3dot merge safety, Git branch cleanup, Fix merge conflicts, Git post merge cleanup and Git clean worktrees.

## Where this comes from

- Description: from the skill's own SKILL.md.

## Alternatives

- [Git diff 2dot vs 3dot merge safety](https://ai-powered.com/skills/git-diff-2dot-vs-3dot-merge-safety): Git diff 2dot vs 3dot merge safety is an open-source agent skill for developer tools.
- [Git branch cleanup](https://ai-powered.com/skills/git-branch-cleanup): Git branch cleanup is an open-source agent skill for developer tools.
- [Fix merge conflicts](https://ai-powered.com/skills/fix-merge-conflicts): Fix merge conflicts is an open-source agent skill for developer tools.
- [Git post merge cleanup](https://ai-powered.com/skills/git-post-merge-cleanup): Git post merge cleanup is an open-source agent skill for developer tools.
- [Git clean worktrees](https://ai-powered.com/skills/git-clean-worktrees): Git clean worktrees is an open-source agent skill for developer tools.
- [Gh PR merge worktree checkout trap](https://ai-powered.com/skills/gh-pr-merge-worktree-checkout-trap): Gh PR merge worktree checkout trap is an open-source agent skill for developer tools.
- [Resolve merge conflicts](https://ai-powered.com/skills/resolve-merge-conflicts): Resolve merge conflicts is an open-source agent skill for developer tools.
- [Git merge](https://ai-powered.com/skills/git-merge): Git merge is an open-source agent skill for developer tools.

---
Source: https://ai-powered.com/skills/check-a-stale-branch-is-not-undoing-newer-main-work
