Skip to content

feat(hooks): add status-hook.sh for real-time session status tracking#16

Open
MuLinForest wants to merge 2 commits into
kayhaowu:mainfrom
MuLinForest:feat/session-status-hook
Open

feat(hooks): add status-hook.sh for real-time session status tracking#16
MuLinForest wants to merge 2 commits into
kayhaowu:mainfrom
MuLinForest:feat/session-status-hook

Conversation

@MuLinForest
Copy link
Copy Markdown

Summary

Implement the status-hook slot that was already planned in install.sh (Step 7 ordering) and referenced in notify-on-stop.sh comments, but never provided.

  • hooks/status-hook.sh — writes <status> <epoch> to ~/.claude/sessions/<pid>.status on three events:
    • working on UserPromptSubmit
    • waiting on PermissionRequest
    • idle on Stop — preserves the working epoch so notify-on-stop.sh can compute elapsed working time accurately
  • hooks/install.sh — registers all three hook events in the recommended section, before notify-on-stop (which depends on the .status file)
  • hooks/README.md + hooks/README.zh-TW.md — document the hook, its .status file format, and the idle epoch-preservation behavior

Why this matters

notify-on-stop.sh already reads ~/.claude/sessions/<pid>.status and expects idle <working_epoch> format. Without status-hook.sh, the .status file is never written and the elapsed-time calculation in notify-on-stop.sh always fails silently (exits early at the _status_epoch check).

The dashboard (statusline/dashboard.sh) also reads .status files to show real-time status without polling the session JSON on every render.

Test plan

  • Run bash hooks/install.sh and verify three new hook entries appear in ~/.claude/settings.json
  • Submit a prompt, verify ~/.claude/sessions/<pid>.status contains working <epoch>
  • Wait for Claude to finish, verify status changes to idle <working_epoch>
  • Trigger a tool permission, verify status shows waiting <epoch>
  • Confirm notify-on-stop.sh fires after responses longer than 30 seconds

🤖 Generated with Claude Code

MuLinForest and others added 2 commits March 25, 2026 22:25
Implement the status-hook slot that was already planned in install.sh
and notify-on-stop.sh but never provided.

- Add hooks/status-hook.sh:
  - Writes "<status> <epoch>" to ~/.claude/sessions/<pid>.status
  - Supports working (UserPromptSubmit), idle (Stop), waiting (PermissionRequest)
  - On "idle", preserves the epoch from the last "working" state so that
    notify-on-stop.sh can compute elapsed working time accurately
  - Walks up the process tree to find the claude PID (hooks run as direct
    children of claude, so this resolves in 1-2 iterations)

- Update hooks/install.sh:
  - Install status-hook for UserPromptSubmit, Stop, and PermissionRequest
    in the recommended section (before notify-on-stop, which depends on it)
  - Step 7 ordering already enforces status-hook first in the Stop array

- Update hooks/README.md and hooks/README.zh-TW.md:
  - Add status-hook.sh to quick reference table and layered defaults
  - Add detailed section explaining the .status file format and idle
    epoch-preservation behavior

Co-Authored-By: Claude Code <claude-core@mulin.date>
PermissionRequest fires on every tool call (including auto-approved ones),
so writing "waiting" caused the dashboard to show WAITING throughout the
entire working period rather than just when the user is genuinely blocking.

Map PermissionRequest to "working" so the status stays WORKING for the
full response cycle (thinking + tool execution + reply). WAITING remains
available for future use cases that require true user-blocking distinction.

Update README docs accordingly.

Co-Authored-By: Claude Code <claude-core@mulin.date>
MuLinForest added a commit to MuLinForest/claude-code-toolkit that referenced this pull request Mar 26, 2026
…session_title in single jq call

Resolve dashboard.sh conflict: add session_title to PR kayhaowu#17's consolidated
jq read, removing the redundant individual jq calls from PR kayhaowu#15.

Co-Authored-By: Claude Sonnet 4.6 <claude-code@mulin.date>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant