Shell and process gotchas for agent sessions on the desktop
bashpkillpythongjshttp-serverbackground-jobs
Small traps hit repeatedly by Claude sessions working in ~/dev/justinahampton on the desktop (VictusPop). Each one cost a failed run or a misleading result.
Killing processes
pkill -f "<pattern>"kills the shell running it when the pattern appears in that shell's own command line (exit code 144); this happened at least five times withpkill -f http.server. Kill by port instead: find the PID withss -ltnp 'sport = :8762'(orfuser 8762/tcp), or keep the PID from$!andkillit, or use a trap. See also Driving a desktop from a headless agent shell (DISPLAY, clipboard, sudo hand-off).
Background jobs
- A job started as
( cmd & )inside one tool call dies when the call returns. Use a proper detached launch (Running long jobs so they survive the AI session that started them). - To wait for a background batch from a foreground call, loop on a condition:
until [ -f done ]; do sleep 5; done. - bash re-reads a script while it runs, so editing a running batch script changes what it does next (it cost the tail of a 15-core level search). Copy it, or never edit while running.
Local web servers
- Before starting
python3 -m http.server PORT, check the port is free. A stale server on the same port, rooted elsewhere, made every screenshot a 404 page while a "is it already listening?" guard skipped starting the right one. Always pass--directory. - Something else (often Justin's own preview) may hold a port you used before; the 3d harness is run as
PORT=8744 tests/3d/run.shbecause 8733 is taken.
Python
python3 -I(isolated mode, recommended for scripts that read untrusted files) drops user site-packages, so PIL (installed withpip --user) is missing under it. Run trusted image scripts without-I, or put dependencies in a venv.- Heavy dependencies (manifold3d, numpy) go in a venv:
python3 -m venv V && V/bin/pip install manifold3d numpy.
JavaScript without Node
Node is not on PATH in headless sessions (it lives under nvm: ~/.nvm/versions/node/v24.19.0/bin), and some runs found no Node at all. gjs -m file.mjs (GNOME JavaScript, always installed) is a working ES-module runtime: print(), ARGV, imports.gi.GLib / gi://GLib for file I/O. Good for running a page's DOM-free model in batch jobs on all cores. Quick syntax check of a browser file: gjs -c "new Function(<file text>)".
PATH in headless sessions
php, ffmpeg, ffprobe live in ~/bin and Node under nvm; a headless run must export PATH=$HOME/bin:$HOME/.nvm/versions/node/v24.19.0/bin:$PATH itself.
Display
The X display number is not fixed (:1, :2 and :3 have all been seen); check echo $DISPLAY or ps -C Xorg -o args= before relying on one.
See also
- Running long jobs so they survive the AI session that started them
- Driving a desktop from a headless agent shell (DISPLAY, clipboard, sudo hand-off)