Slack Error Notifications Check
Production-ready hook that handles send, slack, notifications, claude. Includes structured workflows, validation checks, and reusable patterns for automation.
Slack Error Notifications Check
Monitors Bash command execution times and sends Slack alerts for long-running operations and user input waiting states.
When to Use This Hook
Attach this hook when you need to:
- Receive Slack alerts when Bash commands exceed a 30-second threshold to identify potential hangs, infinite loops, or unexpectedly slow operations
- Get notified in Slack when Claude Code pauses for user input so you can return to the session promptly
- Track operational performance patterns across your team by centralizing long-running command alerts in a shared Slack channel
Consider alternatives when:
- You prefer desktop notifications for personal monitoring without involving team communication channels
- Your development workflow frequently involves intentionally long-running processes where constant Slack alerts would create excessive noise
Quick Start
Configuration
name: slack-error-notifications-check type: hook trigger: PreToolUse, PostToolUse, Notification category: automation
Example Trigger
npm run build # If build takes > 30 seconds: # Slack alert: "Long Bash Operation - 1m 47s"
Example Output
Slack Alert Sent:
Header: Long Bash Operation
Fields:
Duration: 1m 47s
Project: my-web-app
Time: 14:45:22
[On notification event]
Slack Alert Sent:
Header: Claude Code Notification
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 timestamp, PostToolUse calculates elapsed time |
| Alert Threshold | 30 seconds default before a long-operation alert is triggered |
| Notification Events | Fires when Claude Code enters a waiting-for-input state |
| Message Format | Slack Block Kit with header and structured field sections |
| Temp File | ~/.claude/bash_start.tmp for timing calculations |
| Scope | Monitors only Bash tool operations; other tools are excluded |
Alert Detection Workflow
PreToolUse (Bash matcher)
|
v
[Record start timestamp to bash_start.tmp]
|
... (Bash command executes) ...
|
PostToolUse (Bash matcher)
|
v
[Calculate: end_time - start_time]
|
v
[Duration > 30 seconds?]
| |
No Yes
| |
v v
[Delete tmp] [Build Slack Block Kit message]
|
v
[POST to SLACK_WEBHOOK_URL]
|
v
[Delete tmp file]
Notification Event (any matcher)
|
v
[Build waiting-state Block Kit message]
|
v
[POST to SLACK_WEBHOOK_URL]
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
SLACK_WEBHOOK_URL | string | (required) | Slack webhook URL for delivering alert messages |
duration_threshold | integer | 30 | Minimum command execution seconds before triggering a long-operation alert |
include_command | boolean | false | Whether to include the actual Bash command text in the Slack alert |
alert_channel | string | (webhook default) | Override channel for error alerts, separate from general notifications |
quiet_hours | string | (none) | Time range in HH:MM-HH:MM format during which alerts are suppressed |
Best Practices
-
Separate error alerts from session notifications - Use a different Slack channel or webhook for error alerts than for session lifecycle notifications. This ensures critical operational warnings are not buried among routine session start and stop messages.
-
Adjust threshold per project type - Frontend projects with fast build tools may warrant a 15-second threshold, while backend projects with compilation steps may need 60 seconds or more. Configure the threshold based on your project's typical command execution profile.
-
Enable command text inclusion carefully - Including the actual Bash command in Slack alerts provides valuable debugging context but may expose sensitive information like API keys or file paths. Enable this option only in private channels with restricted membership.
-
Use quiet hours for overnight builds - If you schedule long-running operations during off-hours, configure quiet hours to suppress alerts during those periods. This prevents a flood of expected alerts from filling the channel overnight.
-
Create Slack workflows from alert patterns - Use Slack Workflow Builder to create automated responses to recurring alert patterns. For example, if a specific build command consistently triggers alerts, create a workflow that posts troubleshooting steps automatically.
Common Issues
-
Every Bash command triggers an alert - A stale
bash_start.tmpfile from a previous crashed session contains an old timestamp that makes every subsequent command appear to exceed the threshold. Delete~/.claude/bash_start.tmpmanually to reset the timing baseline. -
Notification events never fire - The Notification hook event only triggers when Claude Code explicitly enters a user-input-waiting state. If your sessions run autonomously without permission prompts, these events may never occur. This is expected behavior, not a configuration error.
-
Slack rate limiting causes missed alerts - Slack webhooks have rate limits that may be exceeded during intense development sessions with many rapid Bash operations. If you see HTTP 429 errors, increase the duration threshold to reduce alert frequency or batch alerts using a queueing wrapper script.
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.