Skip to content

Add configurable duration threshold for notifications#2

Open
ashmitb95 wants to merge 3 commits intomainfrom
feat/duration-threshold
Open

Add configurable duration threshold for notifications#2
ashmitb95 wants to merge 3 commits intomainfrom
feat/duration-threshold

Conversation

@ashmitb95
Copy link
Owner

@ashmitb95 ashmitb95 commented Mar 1, 2026

Summary

Closes #1

Adds a new claudeNotifier.durationThreshold VS Code setting (number, in seconds, default 0). When set to a value > 0, all notification sounds (task completed, permission, and question) are suppressed until Claude has been working for at least that many seconds. If you're still watching the IDE, you don't need audio alerts.

How it works

  1. The PreToolUse hook fires on every tool invocation and writes a Date.now() timestamp to a marker file (~/.claude/hooks/claude-notifier-taskstart) — only on the first tool call per task (preserves the earliest timestamp)
  2. All hooks (stop, permission, question) read the marker and compute elapsed = now - startTime
  3. If elapsed < threshold, the sound and OS notification are skipped
  4. The Stop hook cleans up the marker file after each task

Caveat

Duration is measured from the first tool use, not from when the user submits a prompt. This means:

  • For tasks where Claude uses tools (the vast majority), the threshold works as expected
  • For pure text-only responses (no tool use at all), no marker is written and no sound plays when threshold > 0 — this is intentional since text-only responses are typically instant

Changes

  • package.json — new durationThreshold setting, version 2.2.0
  • src/extension.ts — syncs threshold to config, cleans up marker file, shows threshold in status bar tooltip, PreToolUse hook fires for all tools (no matcher)
  • hook/claude-notifier-on-stop.js/.ps1 — reads marker, checks threshold, cleans up
  • hook/claude-notifier-on-permission.js/.ps1 — writes marker, checks threshold before sound
  • hook/claude-notifier-on-question.js/.ps1 — writes marker for all tools, checks threshold before sound (only plays sound for AskUserQuestion)
  • README.md — documents the new setting

Status bar

The existing mute toggle addresses the "quick toggle" part of the original request. The tooltip now also shows the configured threshold when > 0.

Test plan

  • Set threshold to 10, ask Claude a quick question (< 10s) → no sound
  • Set threshold to 10, give Claude a long task (> 10s) → sound plays
  • Set threshold to 0 → all notifications fire as before
  • Verify auto-approved tools (no permission prompt) still write the marker correctly
  • npm run compile passes with no errors

Adds a new `claudeNotifier.durationThreshold` setting (seconds, default 0).
When set, the "task completed" sound only plays if Claude worked for at
least that many seconds — preventing noisy alerts for quick responses.

Permission and question notifications always fire immediately since they
require user input regardless of elapsed time.

Duration is tracked via a marker file written by mid-task hooks
(permission, question) and checked by the stop hook.

Fixes #1
ashmitb95 added 2 commits March 1, 2026 09:53
- Threshold now suppresses ALL sounds (completion, permission, question)
  when Claude has been working for less than the configured duration
- PreToolUse hook fires for all tools (not just AskUserQuestion) to
  reliably record task start time via marker file
- Text-only responses (no tool use) produce no sound when threshold > 0
- Force re-registration for users upgrading from matcher-based config
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.

Could we add a configurable duration threshold so that the sound only plays if it exceeds that time?

1 participant