/claude_mcp_auto_approve.js Secret
Last active
April 8, 2025 18:08
Claude MCP auto approve
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Array of trusted tool names | |
const trustedTools = [ | |
'list-allowed-directories', | |
'list-denied-directories', | |
'ls' | |
]; | |
// Cooldown tracking | |
let lastClickTime = 0; | |
const COOLDOWN_MS = 1000; // 1 second cooldown | |
const observer = new MutationObserver((mutations) => { | |
// Check if we're still in cooldown | |
const now = Date.now(); | |
if (now - lastClickTime < COOLDOWN_MS) { | |
console.log('π Still in cooldown period, skipping...'); | |
return; | |
} | |
console.log('π Checking mutations...'); | |
const dialog = document.querySelector('[role="dialog"]'); | |
if (!dialog) return; | |
const buttonWithDiv = dialog.querySelector('button div'); | |
if (!buttonWithDiv) return; | |
const toolText = buttonWithDiv.textContent; | |
if (!toolText) return; | |
console.log('π Found tool request:', toolText); | |
const toolName = toolText.match(/Run (\S+) from/)?.[1]; | |
if (!toolName) return; | |
console.log('π οΈ Tool name:', toolName); | |
if (trustedTools.includes(toolName)) { | |
const allowButton = Array.from(dialog.querySelectorAll('button')) | |
.find(button => button.textContent.includes('Allow for This Chat')); | |
if (allowButton) { | |
console.log('π Auto-approving tool:', toolName); | |
lastClickTime = now; // Set cooldown | |
allowButton.click(); | |
} | |
} else { | |
console.log('β Tool not in trusted list:', toolName); | |
} | |
}); | |
// Start observing | |
console.log('π Starting observer for trusted tools:', trustedTools); | |
observer.observe(document.body, { | |
childList: true, | |
subtree: true | |
}); |
@gianpaj - note that for latest version of Claude Desktop, the button name in line 40 needs to be changed to "Allow for this chat".
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
HOW TO INSTRUCTIONS
MacOS
Windows
See this comment https://www.reddit.com/r/ClaudeAI/comments/1h9harx/comment/m10p166/