D

Discord Error Trigger

Battle-tested hook for send, discord, notifications, claude. Includes structured workflows, validation checks, and reusable patterns for automation.

HookClipticsautomationv1.0.0MIT
0 views0 copies

Discord Error Trigger

Sends Discord notifications when Claude Code encounters long-running Bash operations or requires user input, enabling remote monitoring of session health.

When to Use This Hook

Attach this hook when you need to:

  • Receive immediate Discord alerts when Bash commands exceed a 30-second threshold indicating potential hangs or performance issues
  • Monitor Claude Code sessions remotely and get notified when the agent is waiting for user input or permission to continue
  • Track operational bottlenecks by logging which commands consistently trigger long-running operation alerts

Consider alternatives when:

  • You prefer Slack or Telegram as your notification platform and need native formatting for those services
  • Your workflow involves many intentionally long-running commands like database migrations where frequent alerts would be disruptive

Quick Start

Configuration

name: discord-error-trigger type: hook trigger: PreToolUse, PostToolUse, Notification category: automation

Example Trigger

npm run test -- --coverage # If test suite takes > 30 seconds: # Discord embed sent: "Long Bash Operation"

Example Output

Discord Alert Sent:
Embed: Long Bash Operation
Color: Yellow (warning)
Fields:
  Duration: 2m 14s
  Project: my-web-app
  Time: 14:45:22

[On notification event]
Discord Alert Sent:
Embed: Claude Code Notification
Color: Teal (info)
Fields:
  Project: my-web-app
  Time: 14:47:08
  Status: Waiting for user input or permission

Core Concepts

Error Monitoring Overview

AspectDetails
Duration TrackingPreToolUse saves start timestamp, PostToolUse calculates elapsed time
Alert ThresholdCommands exceeding 30 seconds trigger a Discord warning embed
Notification EventsFires when Claude Code enters a waiting state for user action
Embed ColorsYellow (16776960) for long operations, Teal (3066993) for notifications
Temp File~/.claude/bash_start.tmp stores command start timestamp
CleanupTemp file removed after each PostToolUse duration calculation

Error Detection Workflow

PreToolUse (Bash)
    |
    v
[Save start time to bash_start.tmp]
    |
    ... (command executes) ...
    |
PostToolUse (Bash)
    |
    v
[Read start time, calculate duration]
    |
    v
[Duration > 30s?]
    |          |
   No         Yes
    |          |
    v          v
 [Cleanup]  [Build warning embed]
               |
               v
            [POST to Discord webhook]
               |
               v
            [Cleanup temp file]

Notification Event
    |
    v
[Build info embed with project context]
    |
    v
[POST to Discord webhook]

Configuration

ParameterTypeDefaultDescription
DISCORD_WEBHOOK_URLstring(required)Discord webhook URL for sending alert notifications
duration_thresholdinteger30Minimum seconds a command must run before triggering a long-operation alert
embed_color_warninginteger16776960Decimal color code for long-operation warning embeds
embed_color_infointeger3066993Decimal color code for notification event embeds
temp_filestring~/.claude/bash_start.tmpPath to temporary file for storing command start timestamps

Best Practices

  1. Tune the duration threshold for your workflow - The default 30-second threshold works well for most web development tasks, but data-intensive projects may need a higher threshold like 120 seconds to avoid alert fatigue from expected long operations such as large test suites or database seeds.

  2. Create separate webhooks for warnings and notifications - Using different webhook URLs for long-operation alerts and notification events allows you to route them to different Discord channels. This separation helps team members subscribe only to the alert types relevant to their role.

  3. Use the notification alerts as productivity signals - When Claude Code sends a notification embed indicating it is waiting for input, treat it as a prompt to return to the session. This is especially valuable when running Claude Code in the background while working on other tasks.

  4. Review long-operation patterns weekly - Track which commands consistently trigger duration alerts. Recurring alerts on the same command type may indicate an opportunity to optimize that operation rather than simply raising the threshold.

  5. Combine with the detailed trigger for full coverage - The error trigger complements the detailed session trigger by covering mid-session events rather than just start and stop. Together they provide comprehensive session lifecycle visibility through Discord.

Common Issues

  1. Alerts fire for every Bash command - If the duration threshold is set too low or the temp file contains a stale timestamp from a previous session, every command will appear to exceed the threshold. Delete ~/.claude/bash_start.tmp manually and verify the threshold is set to at least 30 seconds.

  2. Notification embeds not sending despite webhook being set - The Notification event only fires when Claude Code explicitly enters a waiting state. If you never see these alerts, it may simply mean your sessions are not encountering permission prompts. Test by triggering a permission-required action.

  3. Temp file conflicts in concurrent sessions - If you run multiple Claude Code sessions simultaneously, they share the same bash_start.tmp file, causing incorrect duration calculations. Use session-specific temp file names by including the process ID in the file path to isolate concurrent sessions.

Community

Reviews

Write a review

No reviews yet. Be the first to review this template!

Similar Templates