Loading page...Загружаем страницу...正在加载页面...
AtlasRepo

5 Verbal Corrections Didn't Stick, So a 46-Line Stop Hook Made the Mistake Physically Impossible

Description and use

A 46‑line Stop hook script blocks ! handoff commands containing &&, preventing session freezes in Claude Code.

Problem

Claude Code repeatedly generated handoff commands using &&, causing session freezes; verbal corrections never persisted across sessions.

Outcome

The Stop hook prevented the recurring && mistake, eliminating session freezes and ensuring consistent, correct handoff commands without manual verbal corrections.

Workflow

  • Register Stop hook in ~/.claude/settings.json under "hooks" → "Stop" with empty matcher.
  • Place the 46‑line script ~/.claude/hooks/bang_handoff_amp_guard.sh and make it executable.
  • When Claude finishes a response, the hook runs, parses the transcript JSON, extracts the last assistant message, strips code fences, and checks for lines starting with ! that contain &&.
  • If such a line is found, the script outputs an error message and exits with code 2, blocking the response.
  • Claude then re‑issues the response with corrected syntax (using & instead of &&).

Evidence

I corrected the same Claude Code mistake more than five times. It never stuck. Then I replaced the correction with a 46-line shell script, and the mistake has not come back once.

Source

Claude Code’s ! command launches a shell and runs the command. If you chain a blocking, process-occupying command using &&, the first command never returns, it sits waiting, and the following commands never execute.

Source

  • Record date: 2026-09-15T16:15:55.235Z