# Prompt Submit Hook

> The Prompt Submit Hook is an agent hook that runs when the user sends a prompt, before the agent processes it.

## Can I add context to every prompt automatically?

The hook that receives the user's prompt before the agent starts. Used to add context such as the current branch or ticket, or to block prompts that contain secrets.

- Topic: Agent Customization
- Type: concept

## Example

Wrong:

```bash
#!/bin/bash
git log -50
cat docs/*.md
```

Right:

```bash
#!/bin/bash
prompt=$(jq -r '.prompt')
if echo "$prompt" | grep -qE 'sk-[A-Za-z0-9]{20,}|AKIA[0-9A-Z]{16}'; then
  echo "Prompt blocked: it looks like it contains an API key." >&2
  exit 2
fi
echo "Current branch: $(git branch --show-current)"
```

The hook adds one short line of context and blocks prompts with keys, instead of dumping long logs into every request.

## Key points

- Context added by the hook is short, because it is added to every request.
- Prompts with secrets like API keys are blocked before they reach the model.

## Interview questions

### Does a prompt submit hook run on every message?

Yes, it runs each time the user sends a prompt, so anything it adds is paid for in tokens on every request.

### Can a prompt submit hook block a prompt?

Yes. It can stop the prompt before it reaches the model and show the user why, for example when it contains a secret.

### What context is useful to add to every prompt?

Small, changing facts like the current branch, ticket ID or date. Stable rules belong in the instructions file instead.

## Related cards

- [Agent Hooks](https://wonderium.dev/ai/agent-hooks.md)
- [Session Start Hook](https://wonderium.dev/ai/session-start-hook.md)
- [Context Engineering](https://wonderium.dev/ai/context-engineering.md)

---

- Level: [Artificial Intelligence](https://wonderium.dev/ai.md)
- HTML version: https://wonderium.dev/ai/prompt-submit-hook
- Last updated: 2026-11-25
