Hold space, start talking to Claude, and I’m shouting over whatever is in my headphones.

Claude Code has a voice mode in the terminal. Hold the spacebar, say what you want, let go, and the words land in the prompt. I almost always have music or an audiobook playing, so every time I use it I’m either talking over a song or reaching for the pause key with my other hand. Then I let go, Claude gets to work, and the music stays paused because I forgot about it. An audiobook is worse, because by the time I notice I’ve lost my place.

Music should pause the moment Claude starts listening and come back the moment it stops. Nothing for me to remember.

Watch the Microphone, Not the Spacebar

My first instinct was to hook the spacebar. That’s the wrong place to do it. Space is a key I press a thousand times a day, the binding could change, and a keyboard hook has no idea whether Claude actually opened the microphone or I just typed a space in a sentence.

What matters is whether Claude is recording, and on a modern Linux desktop the audio system already knows that. PipeWire, through its PulseAudio compatibility layer, creates a source-output every time an application starts capturing from a microphone and removes it when the application stops. pactl subscribe prints an event for both:

Event 'new' on source-output #2307
Event 'remove' on source-output #2307

The script listens for those events, checks whether each new stream belongs to Claude, and pauses or resumes media to match. It doesn’t care which key started the recording, or whether Claude captured audio in-process or through arecord. If Claude has the mic, the music stops.

Working Out Who Is Recording

Every source-output carries properties, including the process ID of the application that opened it:

pactl -f json list source-outputs | jq '.[].properties["application.process.id"]'

Claude Code sometimes records in-process and sometimes spawns arecord as a child. To cover both, the script takes that PID and walks up the process tree, checking each ancestor’s name and executable for claude:

def is_claude_pid(pid):
    pid = int(pid)
    for _ in range(10):
        if pid <= 1:
            return False
        with open(f"/proc/{pid}/comm") as f:
            comm = f.read().strip()
        with open(f"/proc/{pid}/stat") as f:
            ppid = int(f.read().rsplit(")", 1)[1].split()[1])
        exe = os.path.realpath(f"/proc/{pid}/exe")
        if "claude" in comm.lower() or "claude" in exe.lower():
            return True
        pid = ppid
    return False

(The real version wraps the /proc reads in try blocks, because processes vanish mid-check.)

I run an rnnoise noise-cancelling filter on my microphone, and it holds a permanent capture stream open. It has no Claude ancestor, so the script ignores it. A video call in the browser gets ignored for the same reason.

Pausing the Right Things

Linux media players expose a D-Bus interface called MPRIS, and playerctl drives it from the command line. My music player, Chromium and Firefox all show up:

$ playerctl -a -f '|' status
Supersonic|Playing
chromium.instance3612244|Paused
firefox.instance_1_62|Paused

When a Claude stream appears, the script pauses everything that is Playing and remembers which players it paused. When the last Claude stream goes away, it resumes only those players, and only if they are still Paused:

def _resume(self):
    with self.lock:
        if self.claude_streams:
            return
        current = players_with_status()
        for player in self.paused_by_us:
            # Don't restart something the user stopped or changed meanwhile.
            if current.get(player) == "Paused":
                playerctl(player, "play")
        self.paused_by_us.clear()

If I stop something by hand while Claude is listening, it stays stopped. A YouTube tab that was already paused before I started talking stays paused too.

Resuming waits 0.4 seconds. Push-to-talk comes in quick bursts, and without the delay a fast release and re-press makes the music stutter on and off between them.

My first version had a bug that cost me a test run. It built player names as ., which produced Supersonic.Supersonic. playerctl -p Supersonic.Supersonic pause printed “No players found” and exited non-zero, and my script swallowed both and logged “paused” anyway while the music played on. `` is already the full name, so use it on its own. The current version also checks the return code before it claims to have paused anything.

Installing It

The whole thing is one Python file with no dependencies outside the standard library. You need python3, playerctl, and a pactl new enough to support -f json. That means PulseAudio 16 or later, or any recent pipewire-pulse. On an older pactl the JSON call fails and nothing ever gets detected.

Download the script and the systemd unit, then:

install -m 755 claude-mic-media-pause ~/.local/bin/
install -m 644 claude-mic-media-pause.service ~/.config/systemd/user/
systemctl --user daemon-reload
systemctl --user enable --now claude-mic-media-pause

The unit is short:

[Unit]
Description=Pause media while Claude Code is using the microphone
After=pipewire-pulse.service
Wants=pipewire-pulse.service

[Service]
ExecStart=%h/.local/bin/claude-mic-media-pause
Restart=always
RestartSec=2

[Install]
WantedBy=default.target

It starts at login once the audio stack is up. If PipeWire is slow and pactl subscribe can’t connect, the script exits and Restart=always tries again two seconds later. There’s nothing to start by hand after a reboot.

If you haven’t turned voice mode on yet, mine lives in ~/.claude/settings.json:

"voice": {
  "enabled": true,
  "mode": "hold"
}

Testing It Without Talking

prctl lets a process rename itself, so a one-liner can pretend to be Claude and record two seconds of silence:

python3 -c "import ctypes,subprocess; ctypes.CDLL(None).prctl(15, b'claude-test', 0, 0, 0); subprocess.run(['arecord','-q','-d','2','-f','cd','/dev/null'])"

15 is PR_SET_NAME. The arecord child has a parent called claude-test, the ancestry check matches, and whatever is playing pauses for the two seconds plus the resume delay. Watch it in the log:

journalctl --user -fu claude-mic-media-pause

You should see claude mic stream #N started, paused <player>, and resumed <player> once the recording ends. Setting CLAUDE_MIC_DEBUG=1 in the unit’s environment also logs the full properties of every new capture stream, which helps when something isn’t detected and is too noisy to leave on.

What It Doesn’t Do

It only controls players that speak MPRIS. Spotify, Chromium and Firefox all do, and mpv does once you install mpv-mpris. Anything without MPRIS keeps playing.

It pauses everything that’s playing, including video. Hold space with a browser tab running and the video stops as well, which suits me.

It can’t tell Claude’s voice mode apart from anything else Claude starts. Every process under a claude ancestor counts, so if Claude runs arecord from its Bash tool, or launches anything else that records, your music pauses for that too. The same goes for any unrelated process with “claude” in its name.

Audiobooks don’t rewind on resume. You lose whatever played in the gap before the pause landed, usually a fraction of a second.

It is Linux and PipeWire only. On macOS the same idea would need a different way to spot microphone use and something other than MPRIS to pause players. I haven’t built that.

Why Bother

It saves maybe a second and a half each time I talk to Claude. Voice mode only works if starting it costs nothing, and reaching for a second key costs something. The only key now is the spacebar, and the music takes care of itself.


Feel free to subscribe to my newsletter, chat to me on mastodon or follow my blog in your favourite RSS reader.