Skip to content

Instantly share code, notes, and snippets.

@Richard-Weiss
Last active April 8, 2025 18:08
Claude MCP auto approve
// 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
Copy link

gianpaj commented Mar 20, 2025

HOW TO INSTRUCTIONS

MacOS

  1. Open Claude Desktop
  2. Go to Help -> Enable Developer Mode
  3. Run in the command line
    echo '{"allowDevTools": true}' > ~/Library/Application\ Support/Claude/developer_settings.json
    
  4. Close and re-open Claude
  5. Press ⌘ Command + βŒ₯ Option + ⇧ Shift + I
  6. Type "allow pasting" and hit Enter
  7. Paste this snippet πŸŽ‰

Windows

See this comment https://www.reddit.com/r/ClaudeAI/comments/1h9harx/comment/m10p166/

@yahalomran
Copy link

@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