By the time the alert fired, the logs were useless. Output rotated. State lost. Threads dead. No one could tell what had happened—until a full forensic investigation began inside Zsh.
Forensic investigations in Zsh are not about generic command-line tricks. They’re about peeling back the layers of a live or post-mortem shell session to find truth in processes, environment variables, session histories, and transient file states. The shell is not just a command runner—it’s a living artifact that holds critical evidence. Your ability to capture, preserve, and analyze that evidence decides whether you find what broke, or watch the trail go cold.
The first step is always containment. When something suspicious happens, stop running new commands that overwrite history or mutate the environment. Lock down your current shell state with set -o histappend and disable history expansion to avoid accidental data loss.
Next is preservation. Zsh records far more than just recent commands. Use fc -l to dump the full in-memory history buffer. Capture typeset -p output to freeze the current environment. Save the contents of $ZSH_VERSION, $PATH, $PWD, and any session-specific variables. Don’t trust disk-based logs alone; volatile shell state often contains the missing link.