Feature Request: `OnPromptIsError` Hook for Automated Error Context Fetching

Resolved 💬 3 comments Opened Aug 2, 2025 by coygeek Closed Jan 3, 2026

Title: Feature Request: OnPromptIsError Hook for Automated Error Context Fetching

Labels: feature-request, hooks, integrations, agent-workflow, community-request

Is this a bug report or a feature request?
This is a feature request.

Summary
This is a consolidated feature request, combining input from five separate developers, all asking for a new hook to automate and streamline the debugging workflow in claude code.

Is your feature request related to a problem? Please describe.

A core use case for claude code is debugging. A common and powerful workflow involves pasting an error message, stack trace, or a link to an error report directly into the prompt. While Claude is excellent at analyzing this initial information, a robust fix often requires richer context that lives in external error tracking services like Sentry, DataDog, Bugsnag, or New Relic.

Currently, developers must manually bridge this context gap. The process looks like this:

  1. A developer copies an error or stack trace from their logs.
  2. They paste it into claude code.
  3. They must then manually context-switch to a browser, navigate to their error tracking service, and search for the corresponding issue.
  4. They copy relevant details (e.g., issue URL, user impact data, environmental tags, suspect commits, breadcrumbs) and paste this additional context back into the claude code session.

This multi-step, manual process is tedious, inefficient, and breaks the interactive flow. It prevents developers from leveraging the full agentic potential of claude code for one of its most critical tasks.

Describe the solution you'd like

We propose a new hook event: OnPromptIsError.

This hook would trigger automatically when claude code detects that a user's prompt contains an error message or stack trace. The hook would execute before Claude begins its analysis, allowing a user-defined script to fetch and inject rich, relevant context from external services.

This would turn a reactive, multi-step debugging session into a proactive, context-aware investigation from the very first turn.

Proposed Behavior:

  1. Detection & Trigger: Claude Code would use built-in heuristics (e.g., regex matching for common patterns like Exception:, Traceback (most recent call last):, panic:, etc.) to identify when a user's prompt is likely a bug report. Upon detection, it would trigger the OnPromptIsError hook.
  1. Configuration (settings.json): The hook would be configured within the existing hooks system.

``json
// in .claude/settings.json
{
"hooks": {
"OnPromptIsError": [
{
// The hook triggers based on content, not a specific tool.
"hooks": [
{
"type": "command",
"command": "$CLAUDE_PROJECT_DIR/.claude/hooks/fetch-sentry-context.py",
"timeout": 10 // Optional timeout in seconds
}
]
}
]
}
}
``

  1. Hook Input (stdin): The configured script would receive a JSON payload containing the prompt text.

``json
{
"session_id": "abc-123-xyz-789",
"transcript_path": "/path/to/session.jsonl",
"cwd": "/path/to/project",
"hook_event_name": "OnPromptIsError",
"prompt_text": "TypeError: Cannot read properties of undefined (reading 'map') in UserProfile.js:42"
}
``

  1. Hook Output (stdout): The script would query an external service and print the fetched context to stdout. Claude Code would then inject this output into the conversation as context for the model, similar to the additionalContext functionality of the UserPromptSubmit and SessionStart hooks. An exit code of 0 would signal success, while other codes could handle errors (e.g., API failure).

Detailed Workflow Example (Sentry Integration)

  1. A developer pastes a stack trace into claude code.
  2. The OnPromptIsError hook triggers the fetch-sentry-context.py script.
  3. The Python script receives the stack trace, calls the Sentry API, and finds the matching issue.
  4. The script prints formatted Markdown to stdout:

```markdown
Sentry Context Found:

  • Issue: PROJ-1234
  • Error: TypeError: Cannot read properties of undefined (reading 'map')
  • Last Seen: v2.5.1 (production)
  • Affected Users (24h): 152
  • Suspect Commit: a1b2c3d - "Refactor user profile data fetching"
  • Tags: browser:Chrome, os:Windows, plan:enterprise

```

  1. Claude Code prepends this block to the conversation history.
  2. Claude begins its analysis with a vastly richer context, enabling a much more insightful first response:

> "I see you're debugging the TypeError from Sentry issue PROJ-123, which seems related to commit a1b2c3d. Let's examine the changes to UserProfile.js in that commit..."

Describe alternatives you've considered

  • Using the UserPromptSubmit Hook: This is the closest existing feature, but it's too broad. It fires on every prompt, forcing the hook script to contain complex, inefficient logic to determine if the input is an error. A dedicated, targeted hook is a cleaner, more performant, and more explicit design.
  • Custom Slash Command (e.g., /debug): This is less ergonomic. It requires the user to remember and type a command before pasting, disrupting the natural workflow. The power of the proposed hook is its automatic, zero-effort invocation based on the content of the prompt.
  • MCP Server: While an MCP server could provide tools to query Sentry, it still requires Claude to be prompted to use the tool. This hook provides the critical context upfront, guiding Claude's initial thinking and planning phase far more effectively.

Additional Context

This feature aligns perfectly with Claude Code's philosophy as a flexible, scriptable, and "unopinionated" power tool. It builds upon the excellent existing hooks system by adding a new event type tailored to a very common and high-value developer workflow. By automating this crucial context-gathering step, the OnPromptIsError hook would significantly enhance Claude's agentic capabilities and provide a major productivity boost for developers.

View original on GitHub ↗

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