Use caffeinate to keep Claude Code and Codex running on Mac MacOS ships with a built-in command-line tool called caffeinate that prevents the Mac from sleeping during long-running terminal tasks, making it especially useful for AI coding tools like Claude Code and Codex when connected to a VPN. By running caffeinate alongside these tools, users can avoid network disconnections and task interruptions caused by idle sleep. Use caffeinate to keep Claude Code and Codex running on Mac macOS ships with a small command called caffeinate that keeps your Mac awake during long-running terminal tasks. It is especially useful for Claude Code and Codex sessions over office VPN, where sleep can disconnect the network session and interrupt the work. AI coding tools are becoming part of my regular terminal workflow. Tools like Claude Code and Codex are useful when I want to explore a codebase, ask for a refactor, run tests, or let an agent work through a task. But there is one very boring problem that can interrupt this flow: The Mac goes to sleep. This becomes more painful when I am connected to an office VPN. Slightly longer-running tasks need the network connection to stay alive. If the laptop sleeps, the VPN can disconnect, and the task may pause, fail, or need manual attention again. Earlier, I had written about No Sleep Page https://www.narendravardi.com/sleep-page/ , which is a simple webpage that prevents the laptop from sleeping. That works well when you want a browser-based solution. One drawback is that No Sleep Page needs the browser tab to stay in the foreground. The page itself says: This can only keep your computer awake if this tab is kept in the foreground. But if you are already working inside the terminal, macOS has an even cleaner option. It is called caffeinate . What is caffeinate ? caffeinate is a macOS command-line tool that prevents your Mac from sleeping. It is already available on macOS, so there is nothing new to install. For this workflow, you only need a few options: -i : prevent idle sleep. This is the one I use most often for terminal commands. -d : prevent the display from sleeping. -t