Bounces vague prompts before Claude sees them, and suggests the project's own term

A Claude Code mod that stops vague prompts before Claude sees them. When a prompt says "the thing" or "the payments page" and the project calls it something else, the mod drops it, tells you why, and suggests the project's own word.

A vague prompt costs a whole turn of Claude guessing, and a wrong guess stays in the context and sometimes in your files. This mod checks every prompt at prompt.submit, the moment you press Enter. A bounced prompt never reaches the model, costs no tokens, and goes back in the prompt box for you to fix.
In -p / SDK sessions the drop still applies, but no status line or bounce toast is drawn.
CLAUDE.md, docs/glossary.md, decision records, specs) and asks Haiku whether the prompt is specific and uses the project's terms. If not, the toast suggests the right one: "This project calls that the Billing Panel. Is the wrong price in the plan display or an invoice?"/force <prompt> sends anything past it. Slash commands always pass.It never sends anything to Claude itself. The reason and the suggestion are for you only.


claude plugin marketplace add ray-amjad/claude-code-mods
claude plugin install prompt-bouncer@claude-code-mods
Or inside Claude Code: /plugin marketplace add ray-amjad/claude-code-mods, then /plugin install prompt-bouncer@claude-code-mods.
A line under the prompt shows the mode it's in: ⚠ prompt-bouncer: quick mode.
Prompt dropped by a hook line in the transcript, and comes back in the prompt box./force <prompt> sends the prompt as your own words, unchecked./bouncer shows the mode and which docs it found. /bouncer quick, /bouncer project or /bouncer off switch it for this session.claude -p, a prompt starting with ! passes too (the ! is removed). In the interactive prompt box ! is shell mode, so use /force there.The example/ folder is a tiny invoicing app with a glossary (Billing Panel, Plan Switcher, Dunning Run, Seat Ledger), each term with a "Not" column of loose words people use for it:
cd example
claude
/bouncer project
Then try the payments page shows the wrong price, fix it, add a CSV export to the members table or make the retry thing run more often, and compare with The Billing Panel shows the wrong plan price.
| Option | Default | What it does | | :- | :- | :- | | mode | quick | quick or project. Set it with /plugin configure prompt-bouncer@claude-code-mods. | | docs | CLAUDE.md,docs/glossary.md,docs/decisions/*.md,specs/*.md,docs/specs/*.md | The files project mode reads, comma-separated, from the folder Claude Code runs in. A * matches file names inside one folder. | | maxDocChars | 20000 | Docs past this many characters are cut, so the check stays cheap | | PROMPT_BOUNCER_MODE (env) | unset | Overrides mode for one session: PROMPT_BOUNCER_MODE=project claude |
prompt.submit judges prompts a person typed. Notifications, scheduled prompts and messages from other sessions pass.CamelCase, snake_case, a Capitalized Name). Prompts over 15 words pass.$.fs on every prompt, then makes one $.model.complete call to Haiku with the docs as a cached prefix and the prompt after them. Haiku answers JSON: { "pass": true } or a reason and a suggestion. A glossary with a "Not" column of loose words works best, because it tells Haiku exactly what to catch. Nothing is extracted or stored.{ drop: reason }, so the prompt never enters the session. Claude Code puts the prompt back in the box itself./force can't submit from inside its own command (it would wait on its own turn), so a timer submits it a moment later with $.prompt.submit({ asUser: true })./force is there for that.docs patterns support * inside one folder (docs/decisions/*.md), not **./bouncer mode switches last for the session and reset if the mod reloads.claude --plugin-dir ./prompt-bouncer
claude plugin validate .
claude plugin test .
Tested with Claude Code 2.1.296.
hooks/register.js 170 lines1// prompt-bouncer: guard what you can't undo, guarding against the user.
2// A vague prompt costs a whole turn of Claude guessing. This mod checks each
3// prompt at prompt.submit and drops the vague ones before Claude sees them.
4//
5// quick : instant rules, no model ("fix the thing", "it's broken")
6// project : a Haiku gate that reads the project's own docs and asks
7// "is this specific, and does it use this project's words?"
8//
9// Escape hatch: run /force <prompt> (or start a claude -p prompt with !). Slash commands always pass.
10
11// Words that point at something without naming it
12const VAGUE_NOUNS = /\b(the|that|this|some|those|these)\s+(thing|things|stuff|bug|bugs|issue|issues|problem|error|page|screen|button|function|file|part|bit|one)\b|\b(fix|do|change|update|clean)\s+(stuff|things|everything)\b|\bstuff\b|\bwhatever\b/i
13// Pronouns with nothing before them to point back at (first prompt only)
14const BARE_PRONOUN = /\b(it|that|this|them|those)\b/i
15// Something concrete: a file, a path, code, a name in quotes, CamelCase, snake_case,
16// or a Capitalized Name past the first word ("the Billing Panel")
17const ANCHOR = /[\w-]+\.[a-z]{1,5}\b|\/[\w.-]+|`[^`]+`|"[^"]+"|\b[A-Z][a-z]+[A-Z]\w*|\b\w+_\w+\b|\s[A-Z][a-z]{2,}/
18
19// Session overrides, set by /bouncer (they reset when the mod reloads)
20let modeOverride = null
21let bounces = 0
22let forceNext = null
23// Set at each session.start. In -p / SDK sessions there is no status line or toast to draw
24let headless = false
25
26export function register(on, options) {
27 on('session.start', async ($, e, next) => {
28 headless = e.isInteractive === false
29 if (!headless) $.ui.status((await currentMode($, options)) + ' mode')
30 try {
31 await $.command.register({ name: 'bouncer', description: 'Show prompt-bouncer, or switch it: /bouncer quick|project|off', argumentHint: '[quick|project|off]' })
32 await $.command.register({ name: 'force', description: 'Send a prompt past prompt-bouncer', argumentHint: '<prompt>' })
33 } catch (err) {
34 $.ui.log('could not register commands: ' + err.message)
35 }
36 return next(e)
37 })
38
39 // The guard. It returns { drop } to stop a prompt, or next(e) to let it in.
40 on('prompt.submit', async ($, e, next) => {
41 const text = e.text.trim()
42
43 // Only judge what a person typed, never a notification or a peer's message
44 const kind = e.origin && e.origin.kind
45 if (kind !== 'composer' && kind !== 'sdk' && kind !== 'bridge' && kind !== undefined) return next(e)
46
47 // Escape hatches: /force sent this one, or it starts with !
48 if (forceNext !== null && text === forceNext) { forceNext = null; return next(e) }
49 if (text.startsWith('!')) return next({ ...e, text: text.slice(1).trim() })
50 if (text.startsWith('/')) return next(e)
51
52 const m = await currentMode($, options)
53 if (m === 'off' || text === '') return next(e)
54
55 // Was there a conversation before this prompt? Then "it" can point back at something
56 const isFirst = (await $.session.messages()).length === 0
57
58 const verdict = m === 'project'
59 ? await projectGate($, text, isFirst, await loadDocs($, options))
60 : quickRules(text, isFirst)
61 if (verdict.pass) return next(e)
62
63 // Bounce: tell the user why (Claude Code puts the prompt back in the box to fix)
64 bounces += 1
65 // The toast shows the fix when there is one, else the reason
66 if (!headless) $.ui.toast('Bounced. ' + (verdict.suggestion || verdict.reason), { timeoutMs: 8000 })
67 // One line: a drop reason with newlines in it is mangled
68 return { drop: 'prompt-bouncer: ' + verdict.reason + (verdict.suggestion ? ' Try: ' + verdict.suggestion : '') + ' (Send it anyway: /force <prompt>)' }
69 }).catch(($, e, next) => next(e))
70 // A bouncer that breaks lets prompts through: it should never lock you out
71
72 // /bouncer shows the mode and the docs it reads; /bouncer quick|project|off switches
73 on('command.run', { command: 'bouncer' }, async ($, e) => {
74 const arg = e.args.trim()
75 if (arg === 'quick' || arg === 'project' || arg === 'off') {
76 modeOverride = arg
77 if (!headless) $.ui.status(arg + ' mode')
78 }
79 const docs = await loadDocs($, options)
80 return { text: 'mode ' + (await currentMode($, options)) + ', ' + bounces + ' bounced this session. Project docs: ' + (docs.files.join(', ') || 'none found') + ' (' + docs.text.length + ' chars)' }
81 })
82
83 // /force <prompt> sends the prompt as your own words, past the bouncer
84 on('command.run', { command: 'force' }, async ($, e) => {
85 const text = e.args.trim()
86 if (!text) return { text: 'Usage: /force <prompt>' }
87 forceNext = text
88 // A command can't submit a prompt itself (it would wait on its own turn),
89 // so a timer submits it a moment later, once the command has finished
90 $.clock.after(50, () => $.prompt.submit({ text, asUser: true }).catch((err) => $.ui.log('force failed: ' + err.message)))
91 return {}
92 })
93}
94
95// The mode: /bouncer override, then PROMPT_BOUNCER_MODE, then /config
96async function currentMode($, options) {
97 return modeOverride || (await $.env.get('PROMPT_BOUNCER_MODE')) || options.mode || 'quick'
98}
99
100// Quick mode: no model, just patterns. Short + vague + nothing named = bounce.
101function quickRules(text, isFirst) {
102 const words = text.split(/\s+/).length
103 if (words > 15 || ANCHOR.test(text)) return { pass: true }
104 const noun = text.match(VAGUE_NOUNS)
105 if (noun) {
106 return { pass: false, reason: '"' + noun[0] + '" doesn\'t say which one. Name the file, feature or component.' }
107 }
108 const pronoun = text.match(BARE_PRONOUN)
109 if (isFirst && pronoun) {
110 return { pass: false, reason: '"' + pronoun[0] + '" has nothing to point back to yet. Say what you mean.' }
111 }
112 return { pass: true }
113}
114
115// Project mode: Haiku reads the project's docs and judges the prompt
116async function projectGate($, text, isFirst, docs) {
117 const r = await $.model.complete({
118 model: 'haiku',
119 maxTokens: 300,
120 timeoutMs: 20000,
121 system: 'You are a gatekeeper for a coding agent. Reply with JSON only, no prose.',
122 prompt: [
123 // The docs are the same every prompt, so they form the cached prefix
124 { text: 'PROJECT DOCS (the project\'s own language):\n\n' + docs.text, cache: true },
125 {
126 text: 'A developer is about to send this prompt to a coding agent' +
127 (isFirst ? ' as the FIRST message of a new session (so "it" or "that" points at nothing)' : ' mid-conversation (short follow-ups like "yes" or "do it" are fine)') +
128 ':\n\n<prompt>\n' + text + '\n</prompt>\n\n' +
129 'Bounce it if EITHER is true: (1) it uses a loose word where the docs define a precise term ' +
130 '(any word in the glossary\'s "Not" column, or a close paraphrase of one, always bounces), or ' +
131 '(2) the agent would have to guess what it refers to, because it names no file, feature or component. ' +
132 'A prompt that already names a project term or a file passes, even if other words in it are casual. ' +
133 'Ordinary verbs and words like "switch", "change" or "update" are not loose terms.\n\n' +
134 'Reply {"pass": true} or {"pass": false, "reason": "<one short sentence>", "suggestion": "<under 25 words: the prompt rewritten with the project\'s term; if it could mean two things, ask which one, e.g. this project calls that the billing panel, which one did you mean?>"}',
135 },
136 ],
137 })
138 // If Haiku is down or answers nonsense, let the prompt through
139 if (!r.isAnswered) return { pass: true }
140 try {
141 const json = JSON.parse(r.text.slice(r.text.indexOf('{'), r.text.lastIndexOf('}') + 1))
142 return json.pass === false ? { pass: false, reason: json.reason || 'too vague for this project', suggestion: json.suggestion } : { pass: true }
143 } catch {
144 return { pass: true }
145 }
146}
147
148// Read the project's docs with $.fs: plain paths, or folder/*.md for every match in one folder
149async function loadDocs($, options) {
150 const root = await $.session.cwd()
151 const max = options.maxDocChars || 20000
152 const files = []
153 let text = ''
154 for (const pattern of String(options.docs || '').split(',').map((p) => p.trim()).filter(Boolean)) {
155 let paths = [pattern]
156 if (pattern.includes('*')) {
157 const dir = pattern.slice(0, pattern.lastIndexOf('/') + 1)
158 const re = new RegExp('^' + pattern.slice(dir.length).replace(/[.]/g, '\\.').replace(/\*/g, '.*') + '$')
159 if (!(await $.fs.exists(root + '/' + dir))) continue
160 paths = (await $.fs.list(root + '/' + dir)).filter((f) => f.kind === 'file' && re.test(f.name)).map((f) => dir + f.name).sort()
161 }
162 for (const path of paths) {
163 if (text.length >= max || !(await $.fs.exists(root + '/' + path))) continue
164 text += '\n--- ' + path + ' ---\n' + (await $.fs.read(root + '/' + path)).slice(0, max - text.length)
165 files.push(path)
166 }
167 }
168 return { files, text }
169}
170