Store bad-session-state.json next to the statusline script in .claude/ so it persists reliably outside the sandbox-restricted temp directory. Gate-pre-continuation now reads from .claude/bad-session-state.json (relative to project root) — no setup-time path substitution required. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2.6 KiB
BAD Session-State Hook Setup
Executed during /bad setup (Step 3). Installs bad-statusline.sh as the Claude Code
statusLine script, automatically chaining any pre-existing statusLine command so the user
loses no existing functionality.
Step 1: Find the Effective Existing Command
Claude Code applies statusLine using this precedence (highest to lowest). Scan in order and
stop at the first file that has a statusLine.command. Skip any command already equal to
.claude/bad-statusline.sh (re-run guard).
| Priority | File | Writable by setup |
|---|---|---|
| 1 (highest) | /Library/Application Support/ClaudeCode/managed-settings.json |
No |
| 2 | {project-root}/.claude/settings.local.json |
Yes |
| 3 | {project-root}/.claude/settings.json |
No — local.json takes precedence |
| 4 (lowest) | ~/.claude/settings.json |
No — outside project scope |
- If found at priority 1 (managed): set
MANAGED_CONFLICT=true— go directly to the managed warning below and stop. Writing tosettings.local.jsonwould have no effect since managed settings override all user-writable files. - If found at priority 2–4: save the value as
CHAIN_COMMAND. - If not found anywhere:
CHAIN_COMMANDis empty.
Step 2: Write bad-statusline.sh
Copy ./assets/bad-statusline.sh to {project-root}/.claude/bad-statusline.sh.
Make it executable: chmod +x {project-root}/.claude/bad-statusline.sh.
If CHAIN_COMMAND is non-empty, rewrite the script body:
#!/bin/bash
# BAD session-state capture — auto-generated by /bad setup.
# Chains pre-existing statusLine command then writes Claude Code session JSON
# to .claude/bad-session-state.json for BAD Pre-Continuation Checks.
SESSION_JSON=$(cat)
echo "$SESSION_JSON" | <CHAIN_COMMAND>
SCRIPT_DIR=$(cd "$(dirname "$0")" && pwd)
echo "$SESSION_JSON" > "$SCRIPT_DIR/bad-session-state.json"
If CHAIN_COMMAND is empty, keep the script body as-is.
Step 3: Write statusLine to Project-Local Settings
Read {project-root}/.claude/settings.local.json (create {} if absent). Set:
"statusLine": {
"type": "command",
"command": ".claude/bad-statusline.sh"
}
Write the file back. No other settings files are modified.
Managed Settings Conflict
If MANAGED_CONFLICT=true, skip Steps 2–3 and print:
⚠️ A managed statusLine is configured and takes precedence over all user settings.
BAD session-state capture (rate-limit pausing, context compaction) will not function.
Ask your admin to chain .claude/bad-statusline.sh into the managed statusLine script.