home/roleplay/anti-hallucination-prompt-guard-readme

Anti Hallucination Prompt Guard.README

GPTClaudeGemini··976 copies·updated 2026-07-14
anti-hallucination-prompt-guard-readme.prompt
# anti-hallucination-prompt-guard

A tiny **Claude Code `UserPromptSubmit` hook** that nudges the AI to **search its own project context before answering** — instead of answering confidently from (often wrong) memory.

It's a coarse rule-based heuristic. **No LLM call, no tokens burned, never blocks.** A missed or over-eager match costs you nothing but a one-line nudge — and it stays out of your way until a pattern actually matches. (If `jq` isn't installed it tells you so once, instead of silently doing nothing.)

## Why

The most expensive failure mode of an AI coding agent isn't "it doesn't know" — it's **"it thinks it knows" and answers from memory**. You ask *"didn't we already set up X?"* and it cheerfully makes up an answer instead of grepping the repo.

This hook watches your prompt for two patterns and injects a one-line reminder:

| Trigger | Example | Reminder injected |
|---|---|---|
| **Past-tense / decision** | *"we decided…"*, *"last time…"*, *"didn't we build…"* | → read your decisions log + grep your memory **before** asserting |
| **Action imperative** | *"build me a…"*, *"write a…"*, *"go do X"* | → search your local SOPs / templates / examples **before** acting |

It fires **once per session per group** (no nagging).

## Install (3 steps)

1. Drop `anti-hallucination-prompt-guard.sh` somewhere (e.g. `~/.claude/hooks/`) and `chmod +x` it.
2. Open the **`CONFIG` block** at the top of the script and point the 3 variables at your project:
   ```bash
   DECISIONS_FILE="$HOME/your-project/DECISIONS.md"   # your "locked decisions" log
   MEMORY_GLOB="$HOME/.claude/projects/*/memory/*.md" # where your AI keeps memory
   SOP_DIR="$HOME/your-project/sops"                  # your how-to / playbook dir
   ```
   The triggers are bilingual (English + Chinese) — trim `TRIGGERS_PAST` / `TRIGGERS_ACTION` to your language.
3. Register it in your Claude Code `settings.json` (full file: [`examples/settings.json.example`](../examples/settings.json.example)):
   ```json
   { "hooks": { "UserPromptSubmit": [
     { "hooks": [ { "type": "command", "command": "~/.claude/hooks/anti-hallucination-prompt-guard.sh" } ] }
   ] } }
   ```

## Test it yourself

when to use it

Community prompt sourced from the open-source GitHub repo wutuobangai/wutuobangai-beyond-cc (MIT). A "Anti Hallucination Prompt Guard.README" style prompt — adapt the placeholders and specifics to your task. Imported as-is and not independently retested here, so check the output before relying on it.

tags

roleplaycommunitygeneral

source

wutuobangai/wutuobangai-beyond-cc · MIT