Five patterns for building a Python CLI background daemon that auto-starts, upgrades transparently, and shuts down in under a second — from the daemon behind cocoindex-code, an AST-based semantic code search tool for Claude Code, Codex, and Cursor.