Hooks are not only for blocking bad tool calls. UserPromptSubmit runs when you send a message, before the model sees it — so you can inject a short context block every turn without bloating CLAUDE.md.
Use it for a standing budget reminder: context window, spend ceiling, or “prefer local tools over network.”
Minimal hook
Put this under .claude/hooks/ (exact registration path can vary by Claude Code version — confirm against your installed docs):
#!/usr/bin/env bash
# user-prompt-submit.sh — stdout is appended into the turn context
set -euo pipefail
cat <<'CTX'
[session budget]
- Prefer tools already in the repo; do not install packages unless asked.
- Keep diffs small; one concern per turn.
- If the task needs secrets or spend, stop and ask.
CTX
Wire it so Claude Code runs the script on UserPromptSubmit. Keep the injected text short (a few lines). Long dumps here fight the same context limit you are trying to protect.
Why not put this in CLAUDE.md?
-
CLAUDE.mdis loaded once and drifts into a novel. A hook stays one focused reminder. - You can change the budget file without rewriting house rules.
- Pair with a short stack map in
CLAUDE.md(under ~80 lines) and put deny/ask policy in.claude/settings.json.
I keep the hooks, settings, and short house-rules file together in Vildanden Agent Config. The free sample is enough to try the pattern.
Top comments (2)
You do say "wire it", and that step deserves the full block. A script in
.claude/hooks/does nothing until a settings file (or a plugin) declares it: an entry underhooks.UserPromptSubmitwhose innerhooksarray holds{"type": "command", "command": "..."}pointing at the script. Readers who only copy the heredoc will miss that. On "stdout is appended into the turn context": correct for plain-text stdout on exit 0. The JSON form,hookSpecificOutput.additionalContext, is stricter, not looser. Claude Code parses stdout as JSON only when the whole output is one JSON object, so a stray echo turns it back into plain text or a parse error. For a fixed budget block, your plain heredoc is the simpler choice. You mention changing "the budget file" without touching house rules, but the script prints a fixed heredoc. Does your real version cat a file on every prompt, so an edit applies on the next message?While building Tokenade, I keep coming back to the same gap: a budget line shows the spend, but the history it counts is sent again on the next request, so the line should show tokens re-read as well as the total.