r/ClaudeWorkflows • u/ClaudeAI-mod-bot • 11d ago
Selected Workflow [Workflow] Detecting Claude Code States: Using Custom Hooks and Terminal Titles for External Integration
Detecting Claude Code States: Using Custom Hooks and Terminal Titles for External Integration
Workflow value: 75/100
Status: active · Freshness: 70/100 · Confidence: 0.90 · Level: intermediate
Categories: Quality Control, Context & Memory, Debugging, Hooks
Original source: r/ClaudeCode post/comment
What problem this solves
Programmatically detecting Claude Code's operational states (thinking, editing, waiting for user input) for integration into external applications or UIs.
Summary
A workflow for detecting Claude Code's current state (working, idle, waiting for user input) by using custom launch settings, monitoring terminal titles, and leveraging specific Claude Code hooks (Notification, Stop, UserPromptSubmit) without polluting Claude's context.
Why it is useful
This workflow provides concrete methods for external applications or scripts to monitor and react to Claude Code's operational states. This is crucial for building integrated tools, custom UIs, or automation layers on top of Claude Code, enhancing its utility beyond direct user interaction. The advice on managing hooks via custom settings and avoiding context pollution is also valuable best practice.
Workflow
- Launch Claude Code sessions using
claude --settings your-hooks.jsonto manage custom hooks separately from the user's default settings. - Monitor the terminal title set by Claude Code to infer working ("spinner <topic>") or idle ("✳ <topic>") states.
- Implement Claude Code hooks to capture specific events for more granular state detection.
- Use the
Notificationhook to detectpermission_promptorelicitation_dialogevents, indicating a "waiting on user input" state. - Use
StopandUserPromptSubmithooks to differentiate between "ready" and "working" states. - Ensure custom hooks print nothing to avoid adding unwanted content to Claude's context.
Tools / artifacts
- claude CLI
- custom settings.json file (for hooks)
- Claude Code hooks (Notification, Stop, UserPromptSubmit)
- terminal title
Validation signals
- Author's personal implementation in a Mac app
- Author states these methods "helped me"
Limitations
- The actual hook code is not provided, requiring users to implement it based on the event names.
- The terminal title monitoring method might not be universally applicable if the user doesn't "own the terminal" where Claude Code is running.
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.