marathon-cli 0.1.2

Keep your Mac awake while AI agents and local models work. The `marathon` command.
<p align="center">
  <img src="docs/images/banner.png" width="100%" alt="Marathon for Mac. Built for the long run, the long-horizon agent run. Keeps your Mac awake while your agents work, then lets it sleep.">
</p>

<p align="center">
  <a href="https://marathon.abediaz.ai"><b>marathon.abediaz.ai</b></a> ยท
  <a href="https://github.com/abe238/marathon/releases/latest/download/Marathon.dmg">Download for Mac</a>
  <br><br>
  <a href="https://github.com/abe238/marathon/releases/latest"><img alt="Latest release" src="https://img.shields.io/github/v/release/abe238/marathon?color=c8322a"></a>
  <a href="LICENSE"><img alt="License: Apache 2.0" src="https://img.shields.io/badge/license-Apache%202.0-blue"></a>
  <img alt="macOS 14 or later, Apple Silicon" src="https://img.shields.io/badge/macOS-14%2B%20%C2%B7%20Apple%20Silicon-black">
</p>

# Marathon

You kicked off a four-hour agent run and went to get a $9 matcha. Your Mac went to sleep.
Your agent died at 61% context. The demo is at 3.

We are not [Tibo](https://x.com/thsottiaux), so we can't keep your weekly credits going, but
we'll keep your Mac running at least.

Marathon fixes that. It keeps your Mac awake while your agents cook and your local models run
hot, then lets it sleep when they're done. Menu bar app plus a command. Free. No waitlist.

```
marathon while claude          # awake for your whole Claude Code session
marathon while npm run build   # awake until the build finishes
marathon on 2h                 # or just: stay up for two hours
```

## Why Marathon

**1. It keeps running while your AI does.**
Tick **AI agents** and Marathon watches for Claude Code, Codex, Cursor, Gemini CLI, Grok,
opencode, pi, Aider and friends. Tick **Local AI** for models in Ollama, LM Studio, llama.cpp,
MLX, oMLX and vLLM. Each covers its whole list, including tools you install later. It stays
awake while they're actually working, not just open, and lets your Mac sleep after 15 quiet
minutes. Zero config, zero prompts. From the terminal: `marathon ai on`.
Just one run? Say `marathon while` and then the command: Claude Code, a 70B model download,
an eval, a build. Your Mac stays up until it's done.

**2. It's tiny and private.**
No telemetry, no "AI insights dashboard cloud subscription". No, we are not raising.

**3. It can't get stuck awake.**
A crash releases the hold, then Marathon is back in seconds with the same session and end time. More reliable than Gary's gbrain.

## The menu bar

Click the icon to turn it on or off. Right-click for the rest: timers, "let the screen
sleep", AI agents and Local AI, start at login, and triggers (pick apps straight from your
Applications folder).

<p align="center">
  <img src="docs/images/menu.png" width="337" alt="The Marathon menu: Mac and screen stay awake, no end time. Turn Off, Keep Awake, Awake While AI Agents Work (checked), Awake While Local AI Works (checked), Let Screen Turn Off, Clicking the Icon Turns On, Turn On When Marathon Opens (checked), Triggers, Open at Login (checked), About Marathon, Quit Marathon.">
</p>

<p align="center">
  <img src="docs/images/menu-bar-icons.png" width="708" alt="Menu bar icons: a shoe means off, a runner means on, a stopwatch with 1:05 means on with a timer.">
</p>

| Icon | Means |
|---|---|
| Shoe | Off. Your Mac sleeps like normal. |
| Runner | On. No finish line. |
| Stopwatch `1:05` | On with a timer. Time left sits beside it. |
| Checkered flag | On because a trigger or AI-aware mode said so. |

**Triggers** turn Marathon on for you: while certain apps are open, while you're plugged in,
while an external display is connected, or during hours you pick. On battery, it can bow out
below a charge you choose, so a forgotten session never runs you down to zero.

## The command

```
marathon on                    # stay awake until you turn it off
marathon on 2h                 # for 2 hours (also 45m, 1h30m, or 90 for minutes)
marathon on until 6pm          # until a time (also 17:30)
marathon off                   # done, sleep like normal
marathon status                # what Marathon is doing

marathon while ./backup.sh     # stay awake while this runs, then stop

marathon ai on                 # stay awake while AI agents or local models work
marathon ai off                # stop doing that
marathon ai check              # which AI tools are running, and how busy

marathon help                  # all of the above, in plain words
```

Add `--display-sleep-ok` to `on` or `while` to let the screen turn off while the Mac keeps
running. For scripts, `marathon status --json` prints the same as JSON, and
`marathon toggle` flips it on or off for a single keyboard shortcut.

The app and the command are the same switch. Turn it on in one, turn it off in the other.

## Install

Pick your favorite. Apple Silicon, macOS 14 or later.

```
curl -fsSL https://marathon.abediaz.ai/install.sh | sh   # menu bar app + command
brew install abe238/tap/marathon                         # Homebrew
npx marathon-mac on 2h                                   # npm, no install
uvx marathon-mac ai                                      # Python, no install
cargo install marathon-cli                               # build the command from source
```

The curl script puts Marathon in `~/Applications` and the command in `~/.local/bin`, after
checking the download's checksum. npm, uv/pipx and cargo give you the command only; the
menu bar app comes with curl and Homebrew.

Rather build it yourself? You need [Rust](https://rustup.rs), Apple's Command Line Tools
(`xcode-select --install`), and `brew install just librsvg`. Then:

```
git clone https://github.com/abe238/marathon
cd marathon
just install
```

## How it works (for the curious)

- Marathon asks macOS to stay awake once, and keeps that request open for the whole session.
  It doesn't re-ask every few seconds, so it never has a gap and never wakes up to check in.
  You can see it with `pmset -g` (look for "prevented by Marathon") or `pmset -g assertions` for the full list.
- Timers are set to a real clock time, so time spent asleep with the lid closed still counts.
- AI-aware mode checks every 15 seconds, only while it's on, and each check costs well under
  a millisecond. It counts an agent while it, or anything it started, is using the CPU, and a
  model runner while it computes or the GPU is busy. To teach it a new tool, add a line to
  `TOOLS` in `crates/core/src/ai.rs`.
- Quit Marathon and macOS drops the request right away, so a closed app never holds your Mac
  hostage. If it crashes, or the Mac restarts, it comes back exactly as it was: same session,
  same end time, same paused triggers. With Open at Login on, launchd restarts it within
  seconds. If Marathon itself keeps crashing, it starts fresh from your settings instead.
- The menu bar app and the command talk over a private local connection only your user
  account can open. With no app running, the command starts a tiny helper that leaves on its
  own when you're done.

| Folder | What's inside |
|---|---|
| `crates/core` | The rules: sessions, timers, triggers, parsing "2h" and "6pm". Plain Rust, tested anywhere. |
| `crates/power` | The one place that asks macOS to stay awake. |
| `crates/sensors` | Reads battery, charger and display state for triggers. |
| `crates/engine` | The part that runs: holds the request, keeps time, answers the command. |
| `crates/cli` | The `marathon` command. |
| `crates/app` | The menu bar app. Native AppKit, no web view. |

Only the three folders that talk to macOS (`power`, `sensors`, `app`) may use `unsafe` Rust.
Before sending a change, run `just gate`: formatting, lints, tests and dependency checks.
Design notes are in [docs/decisions.md](docs/decisions.md).

## License

[Apache 2.0](LICENSE). Fork it, ship it, put it in your agent's toolbelt.