[BUG] TypeError: Cannot read properties of undefined (reading 'startsWith')

Resolved 💬 5 comments Opened Nov 6, 2025 by wgspring Closed Feb 3, 2026

Preflight Checklist

  • [x] I have searched existing issues and this hasn't been reported yet
  • [x] This is a single bug report (please file separate reports for different bugs)
  • [x] I am using the latest version of Claude Code

What's Wrong?

When I want to hook the PreToolUse timing of the Grep tool, I filled in hookSpecificOutput.updatedInput. However, when I ran Claude, an error message appeared: Error: Cannot read properties of undefined (reading 'startsWith').

<img width="751" height="93" alt="Image" src="https://github.com/user-attachments/assets/134b57da-2843-4dda-864a-85d3f05726fe" />

What Should Happen?

hook the tool Input success.

Error Messages/Logs

[DEBUG] Hooks: Checking initial response for async: {"systemMessage": "tool_input: (2, 0, 0, 10)", "hookSpecificOutput": {"hookEventName": "PreToolUse", "permissionDecision": "allow", "permissionDecisionReason": "", "updatedInput": {"-B": 0, "-A": 2, "-C": 0, "head_limit": 10}}}
[DEBUG] Hooks: Parsed initial response: {"systemMessage":"tool_input: (2, 0, 0, 10)","hookSpecificOutput":{"hookEventName":"PreToolUse","permissionDecision":"allow","permissionDecisionReason":"","updatedInput":{"-B":0,"-A":2,"-C":0,"head_limit":10}}}
[DEBUG] Hooks: Initial response is not async, continuing normal processing
[DEBUG] Successfully parsed and validated hook JSON output
[DEBUG] Hook result has permissionBehavior=allow
[DEBUG] Hook approved tool use for Grep, bypassing permission check
[ERROR] TypeError: TypeError: Cannot read properties of undefined (reading 'startsWith')
    at Object.call (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1927:773)
    at process.processTicksAndRejections (node:internal/process/task_queues:105:5)
    at async R55 (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:27543)
    at async MrA (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:24555)
    at async file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:23705
    at async npA (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:1648:3812)
    at async O55 (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:23617)
    at async N55 (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:22605)
    at async zS (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2028:19463)
    at async P6 (file:///Users/bytedance/.nvm/versions/node/v22.19.0/lib/node_modules/@anthropic-ai/claude-code/cli.js:2374:4452)

Steps to Reproduce

  1. Create a hook file
import json
import sys

# Load input from stdin
try:
    input_data = json.load(sys.stdin)
except json.JSONDecodeError as e:
    print(f"Error: Invalid JSON input: {e}", file=sys.stderr)
    sys.exit(1)

tool_name = input_data.get("tool_name", "")
tool_input = input_data.get("tool_input", {})
hook_event_name = input_data.get("hook_event_name", "")

if hook_event_name == "PreToolUse" and "Grep" == tool_name:
    output = {
        "hookSpecificOutput": {
            "hookEventName": "PreToolUse",
            "permissionDecision": "allow",
            "permissionDecisionReason": "",
            "updatedInput": {
                "-B": 1,
                "-A": 1,
                "-C": 1,
                "head_limit": 10
            }
        }
    }
    print(json.dumps(output))
    sys.exit(0)

# For other cases, let the normal permission flow proceed
sys.exit(0)
  1. Associate the created file with settings.json
{
  "hooks": {
    "PreToolUse": [
      {
        "matcher": "Grep",
        "hooks": [
          {
            "type": "command",
            "command": "python path/to/hook_script"
          }
        ]
      }
    ]
  }
}
  1. Run the claude code to trigger the Grep tool.

Claude Model

None

Is this a regression?

I don't know

Last Working Version

_No response_

Claude Code Version

v2.0.34

Platform

Anthropic API

Operating System

macOS

Terminal/Shell

Terminal.app (macOS)

Additional Information

_No response_

View original on GitHub ↗

This issue has 5 comments on GitHub. Read the full discussion on GitHub ↗