Discord Error Trigger
Battle-tested hook for send, discord, notifications, claude. Includes structured workflows, validation checks, and reusable patterns for automation.
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
| Aspect | Details |
|---|---|
| Duration Tracking | PreToolUse saves start timestamp, PostToolUse calculates elapsed time |
| Alert Threshold | Commands exceeding 30 seconds trigger a Discord warning embed |
| Notification Events | Fires when Claude Code enters a waiting state for user action |
| Embed Colors | Yellow (16776960) for long operations, Teal (3066993) for notifications |
| Temp File | ~/.claude/bash_start.tmp stores command start timestamp |
| Cleanup | Temp 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
| Parameter | Type | Default | Description |
|---|---|---|---|
DISCORD_WEBHOOK_URL | string | (required) | Discord webhook URL for sending alert notifications |
duration_threshold | integer | 30 | Minimum seconds a command must run before triggering a long-operation alert |
embed_color_warning | integer | 16776960 | Decimal color code for long-operation warning embeds |
embed_color_info | integer | 3066993 | Decimal color code for notification event embeds |
temp_file | string | ~/.claude/bash_start.tmp | Path to temporary file for storing command start timestamps |
Best Practices
-
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.
-
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.
-
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.
-
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.
-
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
-
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.tmpmanually and verify the threshold is set to at least 30 seconds. -
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.
-
Temp file conflicts in concurrent sessions - If you run multiple Claude Code sessions simultaneously, they share the same
bash_start.tmpfile, causing incorrect duration calculations. Use session-specific temp file names by including the process ID in the file path to isolate concurrent sessions.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Pre-Commit Security Scanner
Pre-commit hook that scans staged files for hardcoded secrets, API keys, passwords, and sensitive data patterns before allowing commits.
Agents Md Watcher
Streamline your workflow with this automatically, loads, agents, configuration. Includes structured workflows, validation checks, and reusable patterns for automation.
Automated Build Inspector
Boost productivity using this automatically, trigger, build, processes. Includes structured workflows, validation checks, and reusable patterns for automation.