Dev Investigation Notes
A background process launched from Claude Code disappears seconds later — on Windows, it wasn't a bug but the agent shell cleaning up its processes
This is a translated article. Read the original in Korean ↗
On Windows, I had an AI coding agent (Claude Code) try launching a program in the background, and every time, the launched process vanished after about 20 seconds. It looked like a bug where the program starts and immediately dies — but when the same program was launched from outside the agent shell, it stayed alive for the full 30 seconds. The program was a local voice assistant (voice-assistant): say "Hey Jarvis," and it transcribes what you say, hands it to Claude Code, and reads the answer back aloud. After a reboot the assistant wasn't running, and I was trying to figure out why.
Conclusion
Don't conclude the program crashed just because a process launched from the agent shell disappeared. The agent's command execution environment may be cleaning up the child processes it spawned when the call ends. In this case, the same program disappeared when launched from the agent shell, but when launched from outside the shell (via WMI) it stayed alive for the full 30 seconds and kept writing to its log .
Here's the order for telling whether the execution environment is to blame:
- First, launch it from outside the shell. If it survives, the problem is the execution environment, not the code . Note that the first WMI launch attempt disappeared after 18 seconds; only the attempt that launched
cmd /c batvia WMI survived for 30 seconds . The record doesn't say exactly what command the first attempt used, but you can only trust the result if you reproduce the real launch path (the bat) as-is. - Split the launching call from the checking call. The point is to see whether the process gets cleaned up when the launching command finishes. In this case it disappeared even with the calls split, so this step alone didn't settle it .
- Don't just look at the process list — check whether the log is growing. Whether "ready" got logged before the process vanished separates "never started" from "started, then got cleaned up." The session reportedly tracked log size and process appearance/disappearance closely within a single call, but the exact commands and intervals aren't in the record .
- If
Start-Processthrows an error, suspect your quoting first. Theunrecognized arguments: USB Audioseen during testing wasn't the program's fault — it was a quoting problem in the PowerShellStart-Processcommand used for the test .
Here's step 1 in PowerShell. What the session confirmed is only that "launching cmd /c bat via WMI survives"; the code below is a generic example of that approach, not the session's actual command. start_assistant.bat is the startup script that runs the assistant with pythonw and redirects its output to a log file — substitute your own startup script.
# WMI (CIM) creates the new process, not as a child of the agent shell
Invoke-CimMethod -ClassName Win32_Process -MethodName Create `
-Arguments @{ CommandLine = 'cmd /c "C:\path\to\start_assistant.bat"' }
# Check separately in the next call: does the process exist, and is the log growing?
Get-Process pythonw -ErrorAction SilentlyContinue
(Get-Item C:\path\to\data\main_log.txt).Length
Exactly which mechanism (e.g., a Windows job object) cleaned up the process was not confirmed. That was the agent's guess .
Situation
- The voice assistant runs resident under the venv's
pythonw.exe(Python that runs without a console window) - Autostart works like this: the shortcut
VoiceAssistant.lnkin the Startup folder runsstart_assistant_hidden.vbs, that VBS launches a batch file (bat), and the batch file runspythonw - The dashboard server starts the same way, via
DashboardServer.lnk - The investigation was carried out by the AI coding agent running PowerShell commands in its own shell
Symptom
VoiceAssistant.lnkwas still in the Startup folder, but there wasn't a singlepythonw.exerunning. Neither the assistant nor the dashboard was up- The last entry in
main_log.txtwas from August 23, and the investigation took place on August 27 . The PC had rebooted at 00:19 that day, and the investigation started 7 minutes after boot - When the agent launched it directly to find the cause, there was no process and no new lines in the log . Launching via the bat/vbs path, it still hadn't come up after 25 seconds . Launched via the vbs, it disappeared after 20 seconds
Cause
The agent's execution environment used for diagnosis was cleaning up the processes it launched. That made a perfectly healthy program look like it was dying.
- Run with the console
python.exe, it didn't die even after 45 seconds and made it into the wake-word listening loop. Device detection and "ready" were also confirmed . The code was fine - Running the actual bat with
cmd /c, it blocked for over 40 seconds without finishing. That means cmd was waiting for pythonw to exit — so pythonw was alive . The log also showed "준비 완료. Hey Jarvis" ("Ready. Hey Jarvis") - But when that background task ended,
cmd /c batended along with it, with exit 255 - Even with the launching and checking calls split, there was no pythonw . The first WMI launch attempt also disappeared after 18 seconds . But when
cmd /c batwas launched via WMI, two pythonw processes stayed alive for the full 30 seconds and the log grew from 60615 to 60777 bytes
There are limits to this. The vbs path was never cleanly explained. In the same session, one vbs launch produced no log growth at all , while another logged a new "ready" and then disappeared after 20 seconds . The agent interpreted this as "cleaned up because wscript exits right away," and said it differs from the real situation where explorer launches it at boot . That interpretation hasn't been verified either.
Fix
- Without changing any configuration, the assistant and dashboard were brought back up by launching
pythonwdirectly, without a console window, from outside the agent shell. The exact command used isn't in the record. The assistant went into the listening state as pid 19652, and the dashboard returned HTTP 200 on local port 8787 - There was a side effect. Launching this way bypasses the bat's output redirect, so stdout doesn't accumulate in
main_log.txt. The conversation log (conversation_log.jsonl) is still written normally - The actual question — why autostart failed at boot — was not settled in this session. What was confirmed is that the shortcuts exist, they weren't disabled in Task Manager (neither entry was in the disabled list), and the code, scripts, and device detection were all fine . The agent wrote that "it's hard to say definitively since it couldn't be reproduced," and suggested moving to Task Scheduler if it fails to start again
Bonus — the reboot that same night is also unexplained
On the 22:33 reboot that same day, the assistant again failed to start . This time, the investigation ran the VBS via wscript four times, got four failures, and took that as "reproduced the boot failure" — but the very next run succeeded . In this investigation, pythonw launched from the agent shell survived several times, so it's hard to blame shell cleanup either . Autostart was switched to having Task Scheduler run the batch file directly, and it hasn't been verified with a reboot .
Reporter's Notes — the culprit was the magnifying glass in our own hands
pythonw. The log stopped on August 23 too VoiceAssistant.lnk is still there. It still points to the hidden-launch VBS too pythonw has no console window, you can't see the error.python.exe, which has a console window, settles that. If it dies, the error will print on screen.pythonw.pythonw with Start-Process and got unrecognized arguments: USB Audio cmd /c will tell us.cmd /c bat via WMI, two pythonw processes stayed alive the whole 30 seconds and the log grew from 60615 to 60777 bytes