DEV Community

Vildanden
Vildanden

Posted on

Inject a budget line into every Claude Code prompt with UserPromptSubmit

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
Enter fullscreen mode Exit fullscreen mode

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.md is 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 (0)