Skip to content

SessionStart hook crashes with AttributeError when stdin payload is None #144

@hahnpierre

Description

@hahnpierre

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions