Four Alarm Slots, Three Failur... Note

Four Alarm Slots, Three Failure Modes: Building a Nightly Drain That Survives Sleep, Races, and Timeouts

Claude Code conversations, by design, lack persistent memory, forcing users to re-explain context repeatedly. This absence of a long-term memory hinders productivity, especially when managing multiple projects. To combat this, the author developed a nightly script that exports Claude Code logs into an Obsidian vault. This automated process eliminates the need for manual summaries, ensuring knowledge is preserved regardless of user willpower. Obsidian was chosen for its local Markdown files, Git version control, and linking capabilities, creating an effective external brain.The script's development encountered three critical failures that necessitated a robust, triple-layered design. A sleep freeze issue occurred when the Mac slept mid-script execution, leaving processing incomplete. A double-execution race happened when a scheduled script run overlapped with a manual one, causing Git conflicts. Finally, a timeout failure occurred when processing extensive logs exceeded the script's time limit.These failures led to the implementation of a multi-slot re-firing system, caffeinate for sleep prevention, and idempotent retries using step markers. This design ensures that processing resumes from where it left off, even if interrupted. The system now features a four-layer architecture, starting with Claude session logs and progressing through raw conversation files, an Obsidian vault, and finally a private Git repository.Multiple scheduled slots for the script provide redundancy, allowing subsequent runs to pick up any unfinished tasks. Caffeinate is used to prevent system sleep, and a lock directory prevents concurrent script executions. Idempotent retries are achieved by marking completed steps, allowing the script to skip already processed segments. This ensures that the daily ingestion process, even with failures, will eventually complete.The launchd plist configuration and PATH adjustments, including nvm node discovery, ensure the script runs reliably in its minimal execution environment. Full Disk Access for /bin/bash is checked early to prevent silent failures due to macOS privacy protections. The script utilizes a run_to function with GNU coreutils' timeout for guaranteed process termination, even if initial signals are ignored. This comprehensive setup creates a resilient external memory for Claude Code conversations.