After 6+ hours, Claude Code sessions degrade: more errors, ignored instructions, and even destructive actions. Users report the model "going rogue" in long sessions.
Real reports:
#32963 — "Claude Code degrades severely after ~6 hours: autonomous destructive actions, ignores instructions, corrupts data"
#40383 — "Agent ignored spec across 6 sessions (9 days), repeatedly broke codebase"
A PostToolUse hook that tracks the error rate over a rolling window. When errors spike, it warns you to restart the session.
session-error-rate-monitor.sh:
#!/bin/bash
# TRIGGER: PostToolUse | MATCHER: "Bash"
INPUT=$(cat)
EXIT_CODE=$(echo "$INPUT" | jq -r '.tool_result.exit_code // "0"')
[[ "$(echo "$INPUT" | jq -r '.tool_name')" != "Bash" ]] && exit 0
STATE="$HOME/.claude/state/error-rate.log"
mkdir -p "$(dirname "$STATE")"
[ "$EXIT_CODE" = "0" ] && echo "0" >> "$STATE" || echo "1" >> "$STATE"
# Keep last 20 entries
tail -n 20 "$STATE" > "$STATE.tmp" && mv "$STATE.tmp" "$STATE"
TOTAL=$(wc -l < "$STATE")
if [ "$TOTAL" -ge 20 ]; then
ERRORS=$(grep -c "^1$" "$STATE")
RATE=$(( ERRORS * 100 / 20 ))
[ "$RATE" -ge 40 ] && echo "Warning: ${RATE}% error rate. Consider /compact or new session." >&2
fi
exit 0
/compact every 2-3 hours to refresh contextpre-compact-checkpoint.sh to save work before compactionconsecutive-failure-circuit-breaker.sh to auto-stop after N consecutive errorsnpx cc-safe-setup
591 hooks including session monitoring. 8,872 tests.
cc-safe-setup · GitHub