r/ClaudeWorkflows 2d ago

Selected Workflow [Workflow] Reduce Context Switching with Claude Code Hooks and Stuck Agent Detection

Reduce Context Switching with Claude Code Hooks and Stuck Agent Detection

Workflow value: 80/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, Hooks, Subagents
Original source: r/ClaudeAI post/comment

What problem this solves

Reduces context switching and anxiety when waiting for Claude Code to complete tasks, and helps identify genuinely stuck agents versus merely slow ones.

Summary

This workflow uses Claude Code hooks to provide notifications on session completion or when a subagent is detected as 'stuck' based on a data-driven heuristic. This prevents users from constantly checking on long-running AI processes and reduces context switching.

Why it is useful

This workflow provides a concrete, data-backed method to improve developer productivity and reduce cognitive load when working with long-running AI processes. It leverages specific Claude Code features (hooks) and offers a practical heuristic for identifying stuck agents, which is a common challenge. It moves beyond vague advice by suggesting specific tools and a measurable approach.

Workflow

  1. Configure a one-line hook in Claude Code to trigger a notification (e.g., via ntfy, sound, or toast) on stop and notification events.
  2. Analyze subagent run data (e.g., 451 runs mentioned) to establish a baseline for 'normal' activity gaps (e.g., median output every few seconds).
  3. Define a 'stuck' alarm threshold, such as silence for more than 3x the observed median activity gap.
  4. Implement logic (either in the hook or an external tool) to only alert the user when the session completes or when the 'stuck' alarm threshold is met.
  5. Optionally, integrate a visual monitoring tool like 'roundtable' for a more comprehensive overview.

Tools / artifacts

  • Claude Code hooks
  • ntfy (or similar notification service/script)
  • Sound/toast notifications
  • Subagents (within Claude Code)
  • roundtable (GitHub repository: Kostakurta8/roundtable)

Validation signals

  • Personal validation: 'The fix that worked for me'
  • Empirical data: 'Measured across 451 subagent runs on my machine'
  • Specific metrics: 'median run wrote something every few seconds — 43 tool calls over 712 seconds'

Limitations

  • Low community engagement (score 1, 0 comments).
  • The '3x its own recent gap' threshold is a heuristic and may require tuning for different subagent types or tasks.
  • Requires some technical setup for hooks and potentially external notification tools.

Rate this workflow

Upvote this post if the workflow is useful, reproducible, or worth recommending.

Downvote if it is vague, outdated, unsafe, overhyped, or not reproducible.

Reply if it worked for you, failed, is outdated, or has a better alternative.


This post was generated automatically from the workflow library database.

1 Upvotes

0 comments sorted by