Remediation script
Goal: a change that a guard blocked still gets made, by the person the guard exists for, through a script they can read, dry-run and undo. The agent writes the script and verifies the result. It does not route round the guard.
Critical
- Never run the script yourself when a guard blocked you. Running it is the same write by another route. Write it, hand it over, and wait for the report.
- The script defaults to a dry run. The person passes
--applyonly after reading the dry-run output. - Never test the script against the real tree. Test it against inert fixtures in a temporary directory (
references/checklist.md). - No secrets, tokens, credentials or personal data in the script, its output or its filename.
- A refusal of one tool is not answered by another tool reaching the same target. Report the refusal and stop.
Situation to reference
| Situation | Load |
|---|---|
| Writing the script | references/script-template.md (the contract is in this file) |
| Before the hand-off, or after the person reports it has run | references/checklist.md |
Asked how bash behaves, for example what set -e does | the shell-guru skill, not this one |
The contract
Every remediation script meets all twelve points. A script that misses one is not handed over.
- Location.
docs/05-operations/YYYY-MM-DD-<verb>-<object>.sh, or the path the repository's CLAUDE.md names. The date is the day the script is written. - Interpreter. Starts with
#!/usr/bin/env bashandset -Eeuo pipefail. The person runs it asbash <script>. Their login shell may be zsh, whereset -edoes not stop a failing command in the same way, so the explicitbashremoves that difference. - Dry run by default. With no arguments it prints every action as
would ...and changes nothing.--applyperforms them.-hor--helpprints the header comment. - Every action printed. Each line names the action and both paths, or the single path for a delete.
- Idempotent. Each action checks its own precondition first. When the end state already holds it prints
skipand counts it. A second--applychanges nothing and says so. - Never overwrites. A destination that exists is a failure, not a silent replacement.
mv -nandcp -nsit behind an explicit existence check; they are not the only guard. - Verify before delete. A file is deleted only when its sha256 matches the value recorded in the script. No globs, no
rm -rf, no deletion of a directory. - Hashes for moves and copies. Record the sha256 before the operation and compare after. A mismatch is a failure.
- Counts at the end. One summary line:
summary: changed=N skipped=N failed=N mode=dry-runormode=apply. - Exit status. Exit 0 only when
failed=0, in dry-run mode too. A dry run that finds a refused destination must not look clean. - Local only. No network, no sudo, no writes outside the repository, no package installs.
- Shellcheck clean.
shellcheck <script>reports nothing. If shellcheck is not installed, say so in the handover. Do not install it globally.
The script works from the repository root whatever the current directory is: ROOT="$(git rev-parse --show-toplevel)" then cd "$ROOT". Where the repository is not under git, use the root the CLAUDE.md names.
Procedure
- Confirm the block. Quote the refusal message verbatim and name the guard: hook, sandbox, permission rule or protected path. If the guard is a permission prompt, the owner answers it, not you.
- Inventory the change. List every source, destination and expected hash. Record the hashes now, before any move: ``
bash sha256sum -- docs/notes/draft.md`On macOS, useshasum -a 256 -- <path>. The script'ssha` helper already picks whichever exists.
- Write the script from
references/script-template.md. Name it by the contract, put one action per line inmain, and record every expected hash in the script.
- Test it on a fixture. Follow the fixture pattern in
references/checklist.md. The test must show four things: a dry run changes nothing,--applymakes the change, a second run reportschanged=0, and a planted conflict exits 1 without overwriting anything.
- Lint.
shellcheck <script>. Fix every finding, or justify a suppression in a comment next to it.
- Commit the script on its own, following the repository's git rules, so the person runs a reviewed, committed file. Say which commit it is.
- Hand off. Give the exact commands, in order, and what to reply with. Example:
``text From the repository root, run these in order: bash docs/05-operations/2026-11-19-move-drafts.sh bash docs/05-operations/2026-11-19-move-drafts.sh --apply Reply "ran" with the summary line from each run, and any FAIL line. Do not paste file contents. ``
- Wait. Do not run
--apply. Re-author the script only if the person reports a failure, and then diff the new script against the old one before handing it over again.
After the person reports "ran"
Verify the end state yourself. The reported summary is evidence of what the script printed, not of the state of the tree.
- Re-run the dry run. It must print
changed=0. Any other number means some of the work did not apply. - Check each destination's hash and that each source is gone: ``
bash sha256sum -- <destination> test ! -e <source> && echo "source gone"`` - Check nothing else moved:
git status --porcelain=v1must list only the paths the script touched, plus any paths already dirty before the work started. - Record the outcome in the same folder as the script, as
<script-name-without-.sh>.outcome.md: the date, the summary lines the person reported, your verification commands, and their results. Commit it under the repository's git rules. - Tell the person the result in one line: verified, or not verified and why.