Skip to content
Back to skills

Patch Upstream Hook Durably

ASecurity

Make a local fix to a hook or script owned by an upstream installer (e.g. claude-guardrails scan-commit.sh) survive reinstalls. Use an idempotent repo fix script with --check, wire it into the install script, and test against an upstream baseline.

  • 4 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added November 22, 2026
ai-agentsgorailssecurity

Security analysis

A100/100

Scanned November 22, 2026

npx -y skills add williamblair333/Uncle-J-s-Refinery --skill patch-upstream-hook-durably --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Patch Upstream Hook Durably?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Patch Upstream Hook Durably
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/williamblair333-patch-upstream-hook-durably/badge)](https://www.skillsdirectory.com/skills/williamblair333-patch-upstream-hook-durably)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: patch-upstream-hook-durably
description: Make a local fix to a hook or script owned by an upstream installer (e.g. claude-guardrails scan-commit.sh) survive reinstalls. Use an idempotent repo fix script with --check, wire it into the install script, and test against an upstream baseline.
---

# Patch an upstream-owned hook durably

## When to use
- A global hook installed from upstream (e.g. `~/.claude/hooks/scan-commit/scan-commit.sh` from dwarvesf/claude-guardrails) misbehaves, for example by flagging `sha256:<digest>` as a secret.
- The file is re-copied by an install script (e.g. `install-guardrails.sh`), so a hand edit would be silently dropped on the next reinstall.
- Earlier fixes of the same shape exist (`fix-guardrails-grep`, `fix-guardrails-defender`). Follow their pattern.

Don't use it for one-off edits to files the repo itself owns. Edit those directly.

## Steps

1. **Pre-mortem first.** The change touches hooks, the install script and main, so run the pre-mortem skill before you begin.
   - Expect UPGRADE DURABILITY to flag MEDIUM. Reinstall overwrites the patch, and the fix script is the mitigation.
   - Name the SECURITY tradeoff of any carve-out explicitly. For the digest fix, a 64-hex secret written as `sha256:<secret>` would pass. Keep the carve-out narrow so other patterns still fire.
   - List the exact files in the token scope: the fix script, the install script, the test, and the live hook path.

2. **Write the fix script** at `scripts/fix-guardrails-<name>.sh`:
   - **Idempotent.** Detect a marker comment and do nothing if the patch is already present.
   - **`--check` mode.** Report whether the patch is present and change nothing. This is the observability hook.
   - **Narrow edit.** Use `sed -E`, or whatever tools the hook already uses, so no new dependency is added. Mask only the specific case. For the digest fix, that's the hex-64 text after `sha256:`.
   - **Safe write.** Keep a `.bak`, write to a tmp file, then `mv` atomically. A failed sed must leave the original untouched.
   - **Marker comment.** Insert a comment in the patched hook that names the fix script, so a human reading the hook knows where the change came from.

3. **Wire it into the installer.** Call the fix script from `install-guardrails.sh` after the upstream copy, so every reinstall re-applies the patch.

4. **Write tests** in `tests/test_fix_guardrails_<name>.py` covering three cases:
   - **Baseline:** the unpatched upstream hook blocks the false-positive case. This proves the bug is real.
   - **After the fix:** the false-positive case passes.
   - **No regression:** the true-positive case is still blocked. For the digest fix, that's a bare 64-hex string.
   - Also check that `--check` reports correctly and that a second run is a no-op.

5. **Apply live, then ship.**
   - Run the fix script against the live hook on this host and confirm with `--check`.
   - Unblock any session that was waiting on the fix.
   - Go branch → PR → merge → back to main.

6. **Note the upstream report.** Record that the bug is worth reporting upstream, but don't file it unless asked.

## Recovery
- Restore the hook from `scan-commit.sh.bak`, or rerun `install-guardrails.sh`, which re-applies the fix.

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

View all in ai-agents →

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.