()
| 54 | |
| 55 | |
| 56 | def main(): |
| 57 | try: |
| 58 | input_data = json.load(sys.stdin) |
| 59 | except json.JSONDecodeError as e: |
| 60 | print(f"Error: Invalid JSON input: {e}", file=sys.stderr) |
| 61 | # Exit code 1 shows stderr to the user but not to Claude |
| 62 | sys.exit(1) |
| 63 | |
| 64 | tool_name = input_data.get("tool_name", "") |
| 65 | if tool_name != "Bash": |
| 66 | sys.exit(0) |
| 67 | |
| 68 | tool_input = input_data.get("tool_input", {}) |
| 69 | command = tool_input.get("command", "") |
| 70 | |
| 71 | if not command: |
| 72 | sys.exit(0) |
| 73 | |
| 74 | issues = _validate_command(command) |
| 75 | if issues: |
| 76 | for message in issues: |
| 77 | print(f"• {message}", file=sys.stderr) |
| 78 | # Exit code 2 blocks tool call and shows stderr to Claude |
| 79 | sys.exit(2) |
| 80 | |
| 81 | |
| 82 | if __name__ == "__main__": |
no test coverage detected