Forked from Richard-Weiss/claude_mcp_auto_approve.js
Last active
April 19, 2025 09:14
-
-
Save IRus/18aa5ae9464ad03e4e0f2be53c61ea1c to your computer and use it in GitHub Desktop.
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 = [ | |
'create_new_file_with_text', | |
'execute_action_by_id', | |
'execute_terminal_command', | |
'find_commit_by_message', | |
'find_files_by_name_substring', | |
'get_all_open_file_paths', | |
'get_all_open_file_texts', | |
'get_debugger_breakpoints', | |
'get_file_text_by_path', | |
'get_open_in_editor_file_path', | |
'get_open_in_editor_file_text', | |
'get_progress_indicators', | |
'get_project_dependencies', | |
'get_project_modules', | |
'get_project_vcs_status', | |
'get_run_configurations', | |
'get_selected_in_editor_text', | |
'get_terminal_text', | |
'list_available_actions', | |
'list_directory_tree_in_folder', | |
'list_files_in_folder', | |
'open_file_in_editor', | |
'replace_current_file_text', | |
'replace_file_text_by_path', | |
'replace_selected_text', | |
'replace_specific_text', | |
'run_configuration', | |
'search_in_files_content', | |
'toggle_debugger_breakpoint', | |
'wait', | |
]; | |
// 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 | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment