Auto-approves read-only MCP tools to eliminate constant permission dialogs.
This hook is now officially integrated into the MCP Memory Service project as of v8.73.0!
For production use, we recommend installing from the official repository:
git clone https://github.com/doobidoo/mcp-memory-service.git
cd mcp-memory-service/claude-hooks
python install_hooks.py # Installs all hooks including permission-requestThe repository version offers significant advantages:
- Integrated Ecosystem - Works seamlessly with memory awareness hooks, natural triggers, and session management
- Unified Configuration - Single
config.jsonfor all Claude Code hooks with intelligent defaults - Automated Installation - One command installs and configures everything correctly
- Version Control - Track updates alongside the MCP Memory Service
- Extensible Configuration - Add custom safe/destructive patterns via config without editing code
- Community Support - Issues, PRs, and discussions in active repository
- Production Tested - Tested with complete MCP Memory Service stack across platforms
- Repository: https://github.com/doobidoo/mcp-memory-service
- Release v8.73.0: doobidoo/mcp-memory-service#336
- Documentation: claude-hooks/README-PERMISSION-REQUEST.md
- Configuration Guide: claude-hooks/CONFIGURATION.md
- Changelog: CHANGELOG.md v8.73.0
This gist remains useful for:
- Quick evaluation - Test the hook concept without full repository setup
- Standalone deployment - Use only the permission hook without memory service
- Learning reference - Study the implementation in isolation
- Custom modifications - Fork and modify for specific needs
If you installed from this gist, migrate to benefit from integrated features:
# Backup your custom configuration (if any)
cp ~/.claude/hooks/config.json ~/claude-hooks-config.backup.json
# Install from repository
git clone https://github.com/doobidoo/mcp-memory-service.git
cd mcp-memory-service/claude-hooks
python install_hooks.py
# Restore custom patterns if needed
# Edit ~/.claude/hooks/config.json and merge your customSafePatterns/customDestructivePatternsClaude Code asks for permission on every MCP tool call - even harmless read operations like retrieve_memory, search_code, or list_memories. This breaks your flow when you're just retrieving context.
A PermissionRequest hook with pattern-based auto-approval that:
- ✅ Auto-approves safe read-only operations
⚠️ Still prompts for destructive operations- 🌐 Works with ALL MCP servers (not just one)
- 🔒 Safe-by-default: unknown patterns require confirmation
-
Copy the hook:
mkdir -p ~/.claude/hooks/core curl -o ~/.claude/hooks/core/permission-request.js https://gist.githubusercontent.com/doobidoo/fa84d31c0819a9faace345ca227b268f/raw/permission-request.js chmod +x ~/.claude/hooks/core/permission-request.js
-
Enable in config: Add to
~/.claude/hooks/config.json:{ "hooks": { "permissionRequest": { "enabled": true, "timeout": 2000, "priority": "high" } } } -
Restart Claude Code or reconnect MCP servers
get,list,read,retrieve,fetchsearch,find,query,recallcheck,status,health,stats,analyzeview,show,describe,inspect
delete,remove,destroy,drop,clear,wipe,purge,forget,erasereset,update,modify,edit,changewrite,create,deploy,publishexecute,run,eval,consolidate
Auto-approved (no dialog):
mcp__memory__retrieve_memory→ ✅ Allowedmcp__shodh-cloudflare__recall→ ✅ Allowedmcp__code-context__search_code→ ✅ Allowed
Requires confirmation (shows dialog):
mcp__memory__store_memory→⚠️ Promptmcp__memory__delete_memory→⚠️ Promptmcp__memory__update_memory→⚠️ Prompt
- Language: Node.js
- Input: JSON via stdin (from Claude Code)
- Output: Decision via stdout (
allow,prompt, ordeny) - Pattern Matching: Regex-based tool name extraction
- Safe-by-default: Unknown patterns require confirmation
Strips MCP prefix automatically:
mcp__memory__retrieve_memory → retrieve_memory
mcp__shodh-cloudflare__recall → recall
Then checks against safe/destructive patterns.
The hook uses two pattern lists (configurable in the source):
const DESTRUCTIVE_PATTERNS = [
'delete', 'remove', 'update', 'write', 'create', ...
];
const SAFE_PATTERNS = [
'get', 'list', 'read', 'retrieve', 'search', ...
];Customize these arrays to match your security requirements.
- Claude Code: All versions with hook support
- MCP Servers: Universal (works with any MCP server)
- OS: macOS, Linux, Windows (with Node.js)
This hook uses a safe-by-default approach:
- First checks for destructive patterns → blocks if found
- Then checks for safe patterns → allows if found
- Unknown patterns → prompts user (safer)
You can audit the allowed operations by reviewing the SAFE_PATTERNS list.
Hook not triggering:
- Ensure
chmod +xwas run on the hook file - Check
~/.claude/hooks/config.jsonhas"enabled": true - Restart Claude Code after installation
- Check hook logs:
tail -f ~/.claude/hooks/claude-hooks.log
Still getting prompts for safe tools:
- Verify tool name matches a safe pattern
- Check if tool name contains destructive pattern (takes precedence)
- Enable debug logging to see decision reasoning
Hook failing silently:
- Test manually:
echo '{"tool_name":"test_retrieve","server_name":"test"}' | node ~/.claude/hooks/core/permission-request.js - Expected output:
{"hookSpecificOutput":{...}}
Found a tool that should be auto-approved? Submit an issue with:
- Tool name
- Server name
- Why it's safe (read-only, no side effects)
MIT - Feel free to use, modify, and distribute.
Henry Krupp - @y_c_t_y_e
Senior Technical Consultant | DevOps Engineer | AI Systems Developer
- MCP Memory Service - Semantic memory for Claude
- SHODH Cloudflare - Memory backend on Cloudflare
- MCP Context Provider - Persistent tool context
Star ⭐ this gist if it helped you!