Before I go to bed, I tell my agents:

Never wake up empty-handed.
gnhf is a ralph, autoresearch-style orchestrator that keeps your agents running while you sleep — each iteration makes one small, committed, documented change towards an objective. You wake up to a branch full of clean work and a log of everything that happened.
~ are estimates$ gnhf "reduce complexity of the codebase without changing functionality"
# have a good sleep
$ gnhf "reduce complexity of the codebase without changing functionality" \
--max-iterations 10 \
--max-tokens 5000000
# have a good nap
# Run multiple agents on the same repo simultaneously using worktrees
$ gnhf --worktree "implement feature X" &
$ gnhf --worktree "add tests for module Y" &
$ gnhf --worktree "refactor the API layer" &
# Commit directly on the current branch and push after each successful iteration
$ gnhf --current-branch --push "keep improving this app"
Run gnhf from inside a Git repository with a clean working tree. If you are starting from a plain directory, run git init first.
gnhf supports macOS, Linux, and Windows.
npm
npm install -g gnhf
From source
git clone https://github.com/kunchenguid/gnhf.git
cd gnhf
corepack enable
pnpm install
pnpm run build
pnpm link --global
The npm package includes an agent-facing skill at skills/gnhf/SKILL.md. Agents that support local skills can copy or reference this file to learn how to run GNHF in Hands-Off mode for bounded overnight work, or Companion mode when the outer agent should steer and review a long-running GNHF run.
After installing from npm, the skill is available under the installed package directory. From a source checkout, use skills/gnhf/SKILL.md directly.
┌─────────────┐
│ gnhf start │
└──────┬──────┘
▼
┌──────────────────────┐
│ validate clean git │
│ create or use branch │
│ write prompt.md │
└──────────┬───────────┘
▼
┌────────────────────────────┐
│ build iteration prompt │◄──────────────┐
│ (inject notes.md context) │ │
└────────────┬───────────────┘ │
▼ │
┌────────────────────────────┐ │
│ invoke your agent │ │
│ (non-interactive mode) │ │
└────────────┬───────────────┘ │
▼ │
┌─────────────┐ │
│ success? │ │
└──┬──────┬───┘ │
yes │ │ no │
▼ ▼ │
┌──────────┐ ┌───────────┐ │
│ commit │ │ reset or │ │
│ append │ │ repair │ │
│ notes.md │ │ maybe wait│ │
└────┬─────┘ └─────┬─────┘ │
│ │ │
│ ┌──────────┘ │
▼ ▼ │
┌────────────┐ yes ┌──────────┐ │
│ 3 consec. ├─────────►│ abort │ │
│ failures │ └────▲─────┘ │
│ or perm. ├───────────────┘ │
│ error? │ │
└─────┬──────┘ │
no │ │
└──────────────────────────────────────┘
git commit fails, gnhf preserves the uncommitted work and asks the next agent iteration to repair itgit reset --hard except commit failures, which preserve uncommitted work for repair; agent-reported failures proceed to the next iteration immediately, retryable hard agent errors use exponential backoff, and permanent agent errors such as Claude low credit balance abort immediately and print the run log path. Complete no-op iterations are reported as failures and count toward the consecutive-failure abort limit. If the run exits with a pending commit failure, the exit summary warns that uncommitted changes were left for repair.--max-iterations stops before the next iteration begins, --max-tokens can abort mid-iteration once reported usage reaches the cap, and --stop-when ends the loop after an iteration whose agent output reports the natural-language condition is met unless a commit failure needs repair first; resumed runs reuse the saved stop condition unless you pass a new value, or --stop-when "" to clear it; pending commit-failure repair work is preserved and other uncommitted work is rolled back, and in the interactive TUI the final state remains visible until you press Ctrl+C to exitSIGTERM also force-stops immediatelynotes.md (built up from prior iterations) to communicate across iterations.gnhf/runs/ and ignores it locally, so your branch only contains intentional workgnhf while on an existing gnhf/ branch to pick up where a previous run left off; if you provide a different prompt, gnhf asks whether to update the saved prompt and continue with the existing history, start a new branch, or quit. New runs whose generated branch already exists use a numeric suffix such as gnhf/<slug>-1.Pass --current-branch to run on the branch you are already on instead of creating a gnhf/ branch.
Pass --push to push the current branch after each successful iteration.
Together, --current-branch --push is useful for loose projects where you want a deployed or locally watched branch to update throughout the run.
--current-branch resumes the existing .gnhf/runs/<runId>/ history on a clean working tree and continues iteration numbering.--push also works with the default gnhf/ branch mode and sets origin as the upstream when needed.--current-branch with --worktree; gnhf exits with an error because those modes choose different working directories.Pass --worktree to run each agent in an isolated git worktree. This lets you launch multiple agents on the same repo simultaneously — each gets its own working directory and branch without interfering with the others or your main checkout.
<repo>/ ← your repo (unchanged)
<repo>-gnhf-worktrees/
├── <run-slug-1>/ ← worktree for agent 1
└── <run-slug-2>/ ← worktree for agent 2
--worktree resumes a preserved matching worktree when possible; otherwise gnhf creates a suffixed worktree such as <run-slug>-1 if the original name is unavailable.--worktree must be run from a non-gnhf branch (typically main).| Command | Description |
|---|---|
gnhf "<prompt>" |
Start a new run with the given objective |
gnhf |
Resume a run (when on an existing gnhf/ branch) |
echo "<prompt>" \| gnhf |
Pipe prompt via stdin |
cat prd.md \| gnhf |
Pipe a large spec or PRD via stdin |
If you run gnhf on an existing gnhf/ branch with a different prompt, gnhf asks whether to update prompt.md and continue the existing run history, start a new branch, or quit. When the prompt came from stdin, that confirmation is read from the controlling terminal, so it must be available.
| Flag | Description | Default |
|---|---|---|
--agent <agent> |
Agent to use (claude, codex, rovodev, opencode, copilot, pi, or acp:<target-or-command>) |
config file (claude) |
--max-iterations <n> |
Abort after n total iterations |
unlimited |
--max-tokens <n> |
Abort after n total input+output tokens |
unlimited |
--stop-when <cond> |
End when the agent reports this condition, after any commit-failure repair; persists across resume | unlimited |
--prevent-sleep <mode> |
Prevent system sleep during the run (on/off or true/false) |
config file (on) |
--worktree |
Run in a separate git worktree (enables multiple agents concurrently) | false |
--current-branch |
Run on the current branch instead of creating a gnhf/ branch |
false |
--push |
Push the current branch after each successful iteration | false |
--meteor-frequency <n> |
Set TUI meteor frequency from 0 to 5 (0 disables meteors) |
3 |
--version |
Show version |