S

Slack Error Notifications Check

Production-ready hook that handles send, slack, notifications, claude. Includes structured workflows, validation checks, and reusable patterns for automation.

HookClipticsautomationv1.0.0MIT
0 views0 copies

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

AspectDetails
Duration TrackingPreToolUse saves timestamp, PostToolUse calculates elapsed time
Alert Threshold30 seconds default before a long-operation alert is triggered
Notification EventsFires when Claude Code enters a waiting-for-input state
Message FormatSlack Block Kit with header and structured field sections
Temp File~/.claude/bash_start.tmp for timing calculations
ScopeMonitors 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

ParameterTypeDefaultDescription
SLACK_WEBHOOK_URLstring(required)Slack webhook URL for delivering alert messages
duration_thresholdinteger30Minimum command execution seconds before triggering a long-operation alert
include_commandbooleanfalseWhether to include the actual Bash command text in the Slack alert
alert_channelstring(webhook default)Override channel for error alerts, separate from general notifications
quiet_hoursstring(none)Time range in HH:MM-HH:MM format during which alerts are suppressed

Best Practices

  1. 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.

  2. 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.

  3. 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.

  4. 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.

  5. 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

  1. Every Bash command triggers an alert - A stale bash_start.tmp file from a previous crashed session contains an old timestamp that makes every subsequent command appear to exceed the threshold. Delete ~/.claude/bash_start.tmp manually to reset the timing baseline.

  2. 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.

  3. 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.

Community

Reviews

Write a review

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

Similar Templates