#!/usr/bin/env python3 """Deny a headless agent CLI (`codex exec`, `claude -p`) whose stdin is left open. Why: both read stdin when it is not a tty. In an agent's shell stdin can be a pipe that never closes, so the call prints "Reading additional input from stdin..." and waits forever. A prose rule ("always add = len(tokens): return False tool, rest = os.path.basename(tokens[i]), tokens[i + 1:i + 8] return (tool == 'codex' and 'exec' in rest) or (tool == 'claude' and ('-p' in rest or '--print' in rest)) def unsafe(tokens, piped): if not headless(tokens) or any(t in SAFE_FLAGS for t in tokens): return False return not (piped or any(t.startswith('<') for t in tokens)) def triage(raw, event): return 'codex' in raw or 'claude' in raw def body(event): command = (event.get('tool_input') or {}).get('command') if not isinstance(command, str): raise ValueError('command is not a string') if 'codex' not in command and 'claude' not in command: return 0 stripped = HEREDOC.sub(lambda m: m.group(1).rstrip('\n') + '