4 Hooks That Let Claude Code Run Autonomously (With Zero Babysitting)
Source: Dev.to
The Problem
Claude Code is powerful, but it stops every few minutes to ask “should I continue?” or “which approach?” In unattended sessions, that means your AI sits idle until you come back.
The Solution
Claude Code Ops Starter – 4 production‑tested Bash hooks that enforce autonomous decision‑making.
What’s Inside
1. Context Monitor (context-monitor.sh)
Counts tool calls as a proxy for context‑window usage. Warns at three thresholds:
- Soft (80) – “Consider deferring large tasks”
- Hard (120) – “Wrap up and hand off”
- Critical (150) – Auto‑generates a checkpoint file for session handoff
# Configurable thresholds
SOFT_WARNING=80
HARD_WARNING=120
CRITICAL=150
2. No‑Ask‑Human (no-ask-human.sh)
Blocks all AskUserQuestion tool calls. Instead of stopping to ask, the AI:
- Decides on its own
- Logs uncertainty to
~/pending_for_human.md - Moves to the next task
Override with CC_ALLOW_QUESTIONS=1 when you want questions back.
3. Syntax Check (syntax-check.sh)
Auto‑runs verification after every file edit:
- Python:
python -m py_compile - Shell:
bash -n - JSON:
jq empty
Catches errors immediately instead of 50 tool calls later. Gracefully skips if jq or python aren’t installed.
4. Decision Warn (decision-warn.sh)
Flags risky commands such as rm -rf, git reset --hard, and DROP TABLE before execution. It warns but doesn’t block – uncomment a line in the script for hard blocking.
Install
git clone https://github.com/yurukusa/claude-code-ops-starter.git
cd claude-code-ops-starter
bash install.sh
No dependencies besides Bash. jq and python are optional (hooks skip gracefully without them).
How It Works
Claude Code has a hooks system that runs shell scripts at specific lifecycle points:
- PreToolUse – runs before a tool call (can block it with
exit 1) - PostToolUse – runs after a tool call (for monitoring and validation)
The starter kit uses both:
| Hook | Trigger | Effect |
|---|---|---|
no-ask-human.sh | PreToolUse (AskUserQuestion) | Blocks with exit 1 |
decision-warn.sh | PreToolUse (Bash) | Warns (returns exit 0) |
syntax-check.sh | PostToolUse (Edit/Write) | Validates (returns exit 0) |
context-monitor.sh | PostToolUse (all) | Monitors (returns exit 0) |
Background
These hooks stem from 200+ hours of real autonomous Claude Code operation. Each solved a concrete problem:
- Context monitor – sessions ran out of context without warning.
- No‑ask‑human – overnight sessions left the AI idle for hours waiting for a human answer.
- Syntax check – errors were discovered 50 tool calls after they were introduced.
- Decision warn – a
git reset --hardwiped an afternoon of work.
The full setup (multi‑agent orchestration, stall detection, watchdog, task queue, 20+ hooks) is available as the CC‑Codex Ops Kit.