Bug
mgrep_watch.py (SessionStart hook) crashes on startup when read_hook_input() returns None.
Error
Displayed in Claude Code CLI header:
SessionStart:startup hook error Failed with non-blocking status code: Traceback (most recent call last):
Root cause
In hooks/mgrep_watch.py, lines 34-35:
payload = read_hook_input()
cwd = payload.get("cwd") # AttributeError if payload is None
read_hook_input() returns None when stdin is empty or JSON parsing fails (lines 22-29):
def read_hook_input():
raw = sys.stdin.read()
if not raw.strip():
return None # ← returns None, not {}
try:
return json.loads(raw)
except json.JSONDecodeError as exc:
debug_log(f"Failed to decode JSON: {exc}")
return None # ← returns None, not {}
Line 35 then calls payload.get("cwd") on None, raising AttributeError: 'NoneType' object has no attribute 'get'.
Suggested fix
Either guard against None:
payload = read_hook_input() or {}
Or have read_hook_input() return {} instead of None as the fallback.
Environment
- Claude Code v2.1.104
- macOS (Darwin 24.6.0)
- Python 3 (system)
- mgrep plugin version 0.0.0
Bug
mgrep_watch.py(SessionStart hook) crashes on startup whenread_hook_input()returnsNone.Error
Displayed in Claude Code CLI header:
Root cause
In
hooks/mgrep_watch.py, lines 34-35:read_hook_input()returnsNonewhen stdin is empty or JSON parsing fails (lines 22-29):Line 35 then calls
payload.get("cwd")onNone, raisingAttributeError: 'NoneType' object has no attribute 'get'.Suggested fix
Either guard against
None:Or have
read_hook_input()return{}instead ofNoneas the fallback.Environment