Skip to content

Fix Windows sounds not playing - #1

Open
zarvox32 wants to merge 1 commit into
newink:mainfrom
zarvox32:main
Open

Fix Windows sounds not playing#1
zarvox32 wants to merge 1 commit into
newink:mainfrom
zarvox32:main

Conversation

@zarvox32

Copy link
Copy Markdown

Bug: No sounds play on Windows

Summary

The plugin was completely non-functional on Windows. No sounds were ever heard despite hooks firing correctly.

Root Cause

In hooks/play_sound.py, winsound.PlaySound was called with the SND_ASYNC flag:

winsound.PlaySound(str(sound_file), winsound.SND_FILENAME | winsound.SND_ASYNC)

SND_ASYNC starts sound playback on a background thread and returns immediately. Since the script has nothing left to do after this call, the Python process exits — terminating the background thread and killing the sound before any audio is heard.

This affected all sound events: question, complete, error, and permission.

Fix

Spawn a detached Python process that plays the sound synchronously within itself — the same pattern macOS/Linux already use with start_new_session=True:

if system == "Windows":
    subprocess.Popen(
        [sys.executable, "-c",
         f"import winsound; winsound.PlaySound(r'{sound_file}', winsound.SND_FILENAME)"],
        stdout=subprocess.DEVNULL,
        stderr=subprocess.DEVNULL,
        creationflags=subprocess.DETACHED_PROCESS | subprocess.CREATE_NO_WINDOW,
    )

The parent hook process exits immediately (so the hook timeout is irrelevant), and the detached child plays the sound to completion in the background.

Impact

  • Platform: Windows only (macOS and Linux already used detached subprocesses via start_new_session=True)
  • Severity: All sounds silently failed — the plugin's entire purpose was broken on Windows
  • Status: Fixed

🤖 Generated with Claude Code

…back

winsound.PlaySound with SND_ASYNC starts playback on a background thread
and returns immediately, but the Python process then exits — killing the
thread before any audio is heard. Fix by spawning a detached child process
that plays the sound synchronously within itself, matching the pattern
macOS/Linux already use with start_new_session=True.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
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