MCPcopy Create free account
hub / github.com/anthropics/claude-code / main

Function main

examples/hooks/bash_command_validator_example.py:56–79  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

54
55
56def 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
82if __name__ == "__main__":

Calls 1

_validate_commandFunction · 0.85

Tested by

no test coverage detected