Metadata-Version: 2.4
Name: nodehop
Version: 0.2.0
Summary: Close your laptop, your agents keep working: hand off Claude Code sessions and training jobs between your machines.
License: MIT
Project-URL: Homepage, https://github.com/BuildRunnerFr/NodeHop
Project-URL: Issues, https://github.com/BuildRunnerFr/NodeHop/issues
Project-URL: Changelog, https://github.com/BuildRunnerFr/NodeHop/blob/main/CHANGELOG.md
Keywords: claude-code,ai-agents,handoff,tmux,ssh,tailscale,machine-learning,checkpoint
Classifier: Development Status :: 3 - Alpha
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3 :: Only
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Software Development
Classifier: Topic :: System :: Distributed Computing
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
Dynamic: license-file

<p align="center">
  <img src="https://raw.githubusercontent.com/BuildRunnerFr/NodeHop/main/docs/logo.png" width="112" alt="NodeHop logo">
</p>

<h1 align="center">NodeHop</h1>

<p align="center">
  <b>Close your laptop. Your agents keep working.</b><br>
  <sub>Hands Claude Code and Codex sessions from your laptop to an always-on Mac or Linux box, and back.</sub>
</p>

<p align="center">
  <a href="https://github.com/BuildRunnerFr/NodeHop/actions/workflows/tests.yml"><img src="https://github.com/BuildRunnerFr/NodeHop/actions/workflows/tests.yml/badge.svg" alt="Tests"></a>
  <img src="https://img.shields.io/badge/python-3.9%2B-blue" alt="Python 3.9+">
  <img src="https://img.shields.io/badge/platform-macOS%20%7C%20Linux-lightgrey" alt="macOS | Linux">
  <img src="https://img.shields.io/badge/dependencies-none-brightgreen" alt="No dependencies">
  <a href="LICENSE"><img src="https://img.shields.io/badge/license-MIT-green" alt="MIT license"></a>
</p>

---

NodeHop hands running work from your laptop to an always-on machine, and back.
Close the lid while Claude Code or Codex is in the middle of a task: the
session is stopped, copied to your Mac mini or Linux box, and resumed there with
the same conversation. Open the lid: your laptop takes it back. Training jobs work the
same way, resuming from their last checkpoint at the other machine's pace.

```
 laptop (primary)                              always-on machine (server)
 ────────────────                              ──────────────────────────
 lid closes ─► stop the agent
               copy project + conversation ──────► resume it, same conversation
 lid opens  ─► ask the server to stop
               copy everything back ◄─────────────
               resume it here
```

## Highlights

- **Your agents never stop** — Claude Code and Codex sessions (conversation
  included) and long commands such as training jobs move between machines and
  resume.
- **Set up by an agent, from one machine** — it asks you a few questions and
  installs NodeHop on the other machine over SSH. No agent needed over there.
- **The laptop needs no SSH server** — it pushes work when it sleeps and pulls it
  back when it wakes; only the always-on machine accepts connections.
- **Safe on slow networks** — transfers are all-or-nothing; if the newest state
  cannot be sent before sleep, the server resumes from its last complete copy.
- **Fallback** — if the laptop dies without going to sleep, the server resumes
  the work in progress after 2 minutes.
- **You decide conflicts** — if two agents worked in parallel, a native window
  shows what each one did and lets you pick (the other version is kept).
- **A Mac mini or a Linux server takes over** — the always-on machine can be a
  Mac or a Linux box, with or without a screen.
- **Paths may differ** — different user names and folders on each machine.
- **Zero dependencies** — Python 3.9+ standard library, `ssh`, `rsync`, `tmux`.

## Before you start

NodeHop does almost everything itself. You only prepare three things, once,
on **both machines**:

1. **Your agent, installed and signed in.** NodeHop is built for Claude Code
   first, and Codex works the same way: use either, or both. Install it on each
   machine, sign in with your account, and open it once (`claude`, then its
   first screens). NodeHop never moves your login from one machine to the other.
2. **SSH on the always-on machine.** macOS: System Settings › General › Sharing ›
   Remote Login. Linux: `sudo apt install -y openssh-server`. The laptop needs no
   SSH server. When asked, you type that machine's password once into
   `ssh-copy-id`.
3. **[Tailscale](https://tailscale.com) on both machines**, signed in to the
   same account, so they find each other at home and away (recommended; a
   local network works too).

That's all. Installing NodeHop on the other machine, pairing both machines and
hooking into sleep and wake are done for you.

## Get started

### With an agent (recommended)

Ask your coding agent (Claude Code or any other), on your laptop:

> Install NodeHop from https://github.com/BuildRunnerFr/NodeHop by following its AGENT_SETUP.md.

It installs NodeHop, asks you whether this is the laptop or the always-on
machine, which machine is the other one (your Tailscale machines are offered),
and which project to protect, then sets up both machines. All you may have to
do: type the other machine's password once into `ssh-copy-id`, and run anything
that needs `sudo`. Details for agents: [AGENT_SETUP.md](AGENT_SETUP.md).

### By hand

```sh
pipx install git+https://github.com/BuildRunnerFr/NodeHop
nodehop onboard          # the same questions, with arrow-key menus
```

## Daily use

```sh
cd ~/code/my-app
nodehop on               # protect this project (Claude Code; --agent codex for Codex)
nodehop start my-app     # run its agent, inside NodeHop's tmux
nodehop attach my-app    # open its terminal (detach: Ctrl-b d)
nodehop status           # where each project runs right now
```

Then just close the lid. A few more:

```sh
nodehop handoff --to server   # hand off now, without closing the lid
nodehop pull my-app           # bring a project back here
nodehop resolve               # two agents worked in parallel: choose
nodehop doctor                # check everything, with fixes
nodehop -n handoff            # dry run: print every command, change nothing
```

## Training jobs

```sh
nodehop on ~/code/my-model --command ".venv/bin/python train.py"
nodehop start my-model
```

With `from nodehop import train` (standard library, PyTorch optional) a script
saves a checkpoint and exits cleanly when NodeHop stops it, resumes from it on
the other machine, and picks a micro-batch that fits that machine's memory —
gradient accumulation keeps the effective batch, and so the training, identical.
A 40,000-step run moved between a MacBook (128 × 4) and a Mac mini (64 × 8)
with the same loss curve. See [examples/train_relay.py](examples/train_relay.py).

## How it works

| When | What NodeHop does |
| --- | --- |
| Every 30 s | The laptop tells the server it is alive; every 5 min it also copies the active projects there. |
| Lid closes | Stop the agent (Claude Code quits in ~1 s; a training job saves a checkpoint), copy what changed, resume it on the server. Budget: ~22 s, because macOS sleeps soon after. |
| Lid opens | Ask the server to stop, copy everything back, resume here. Retries while the network comes back. |
| Laptop silent 2 min without sleeping | The server resumes, from the last copy, the work that was in progress. |
| Laptop back, both agents worked | The server's agent is paused and you choose which version to keep. |

Agents run in NodeHop's own tmux server, so they keep running with no terminal
open and can be stopped cleanly. A resumed Claude Code gets a short "carry on"
message only if it was in the middle of something; an idle one is just reopened.

## Requirements

| | The machine you work on (primary) | The always-on machine (server) |
| --- | --- | --- |
| System | a Mac, usually a laptop | a Mac (e.g. a Mac mini) or a Linux server, headless is fine |
| Needs | Python 3.9+ (the system one works), `rsync`, `tmux`, and your agent (Claude Code and/or Codex) signed in | the same, plus an SSH server (Remote Login on macOS; `openssh-server` on Linux) |
| Notes | [SleepWatcher](https://www.bernhard-baehr.de/), installed for you by `nodehop onboard` | Mac: keep a user session open (automatic login) so agents can read the login keychain. Linux: `loginctl enable-linger` so agents keep running with nobody logged in |

- **[Tailscale](https://tailscale.com)** recommended, so it also works away
  from home.

A Linux machine can also be the primary (a systemd sleep hook replaces
SleepWatcher), but that setup is less tested.

## Configuration

`nodehop config get` shows everything; `nodehop config set <key> <value>`
changes it. The useful ones:

| Key | Default | Meaning |
| --- | --- | --- |
| `presync_seconds` | `300` | how often active projects are copied to the server |
| `failover_minutes` | `2` | server: resume the laptop's work after this much silence (`0` = off) |
| `sleep_budget_seconds` | `22` | time allowed to hand off when the lid closes |
| `unattended` | unset (asked) | how a resumed agent handles permission prompts with nobody there: `auto` (Claude Code's auto mode; Codex sandboxed to the project), `acceptEdits`, or `default` |
| `remote_control` | `false` | show NodeHop's Claude Code sessions in the Claude app, to follow and answer them from anywhere |
| `backups_keep` | `5` | versions set aside after a fallback or conflict, kept per project |
| `excludes` | `node_modules`, `.venv`, … | never copied (rebuild them on each machine) |
| `workspace` | unset | where received projects go (unset: same place relative to the home folder) |
| `claude_args` / `codex_args` | `[]` | extra flags for Claude Code / Codex (e.g. `["-c", "model=\"…\""]`) |

## FAQ

**Does the other machine need an agent to be set up?** No. The agent on your
laptop installs and configures NodeHop over there through SSH. Claude Code (or
Codex) must simply be installed and signed in there too, since that machine
runs your agent while the laptop sleeps.

**Does it work on battery?** Yes. Closing the lid hands off on battery as on
power: NodeHop finishes before macOS goes to sleep (a few seconds, within a
22-second budget).

**What does NodeHop do with my passwords?** Nothing: it never asks for, types or
stores one, and agents' logins never leave their machine. It uses its own SSH
key, restricted on the server; see [SECURITY.md](SECURITY.md).

**What if the resumed agent needs a permission with nobody there?** Set
`unattended` to `auto` (the onboarding suggests it): Claude Code's auto mode
decides by itself, so work does not stall. With `remote_control` on, you can
also follow and answer it from the Claude app.

**My network is slow; will a big checkpoint make me lose work?** A transfer cut
by sleep changes nothing on the other side, and the server resumes from the
last complete copy (at most `presync_seconds` old).

**What if I edit the project on both machines?** Don't: the receiving copy is
made identical to the sender's. If two agents ever worked in parallel, NodeHop
asks you which version to keep and saves the other.

**Which agents?** Claude Code (the main target) and Codex, each with its
conversation, as long as it is signed in on both machines; anything
else as a plain command (`nodehop on --command "…"`), restarted on the other
machine. Adding another agent is one module: see [CONTRIBUTING.md](CONTRIBUTING.md).

**Does it rely on agents' internals?** Yes: session files (`~/.claude/projects`,
`~/.codex/sessions`) are not public APIs and may change. NodeHop keeps each
agent's details in its own module.

## Uninstall

```sh
nodehop uninstall --everywhere   # from the laptop: this machine and the paired ones
```

It removes NodeHop's background jobs, app, keys, config, backups and logs, then
the program itself. Your projects, your agents and their conversations stay.

## Contributing

Issues and pull requests are welcome: see [CONTRIBUTING.md](CONTRIBUTING.md)
and the design notes in [CLAUDE.md](CLAUDE.md). Changes are listed in
[CHANGELOG.md](CHANGELOG.md).

## License

[MIT](LICENSE)
