MCPcopy
hub / github.com/kunchenguid/gnhf

github.com/kunchenguid/gnhf @gnhf-v0.1.42 sqlite

repository ↗ · DeepWiki ↗ · release gnhf-v0.1.42 ↗
634 symbols 1,649 edges 81 files 3 documented · 0%
README

Before I go to bed, I tell my agents:

good night, have fun

npm CI Release Platform X Discord

gnhf — Good Night, Have Fun

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.

  • Dead simple — one command starts an autonomous loop that runs until you request stop or a configured runtime cap is reached
  • Long running — each iteration is committed on success, rolled back on failure except commit failures preserved for repair, with sensible retries; retryable hard agent errors back off exponentially while agent-reported failures continue immediately
  • Live terminal title — interactive runs keep your terminal title updated with live status, token totals, and commit count, then clear or restore it on exit depending on terminal support; token totals prefixed with ~ are estimates
  • Exit summary: every run ends with a permanent summary covering elapsed time, branch, iterations, tokens, branch diff stats, local notes/log paths, and review commands
  • Agent-agnostic: works with Claude Code, Codex, Rovo Dev, OpenCode, GitHub Copilot CLI, Pi, or ACP targets out of the box

Quick Start

$ 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.

Install

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

Agent Skill

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.

How It Works

                    ┌─────────────┐
                    │  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 │                                      │
                    └──────────────────────────────────────┘
  • Incremental commits - each successful iteration is a separate unsigned git commit, so you can cherry-pick or revert individual changes without GPG or SSH signing prompts blocking the run; if git commit fails, gnhf preserves the uncommitted work and asks the next agent iteration to repair it
  • Failure handling - failed iterations are rolled back with git 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.
  • Runtime caps - --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 exit
  • Iteration finalization - agents are expected to finish validation, stop any background processes they started, and only then emit the final JSON result for the iteration
  • Graceful interrupts - in the interactive TUI, the first Ctrl+C requests a graceful stop and lets the current iteration finish (or ends backoff early), the second Ctrl+C force-stops immediately, and SIGTERM also force-stops immediately
  • Exit summary - after shutdown cleanup, gnhf prints a permanent stdout summary with the final branch, elapsed time, iteration and token totals, branch diff stats, notes/debug-log paths, and review commands
  • Shared memory — the agent reads notes.md (built up from prior iterations) to communicate across iterations
  • Local run metadata — gnhf stores prompt, notes, stop conditions, and commit-message convention metadata under .gnhf/runs/ and ignores it locally, so your branch only contains intentional work
  • Resume support — run gnhf 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.

Live Branch Mode

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.

  • Re-running the same prompt with --current-branch resumes the existing .gnhf/runs/<runId>/ history on a clean working tree and continues iteration numbering.
  • Push failures abort the run after preserving the successful local commit.
  • gnhf never force-pushes or auto-pulls for this mode.
  • --push also works with the default gnhf/ branch mode and sets origin as the upstream when needed.
  • Do not combine --current-branch with --worktree; gnhf exits with an error because those modes choose different working directories.

Worktree Mode

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
  • Worktrees with commits are preserved after the run so you can review, merge, or cherry-pick the work. gnhf prints the path and cleanup command.
  • Re-running the same prompt with --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.
  • Worktrees with no commits are automatically removed on exit unless a pending commit failure left uncommitted work to inspect or repair.
  • --worktree must be run from a non-gnhf branch (typically main).

CLI Reference

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.

Flags

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

Configuration

Extension points exported contracts — how you extend this code

Agent (Interface)
(no doc) [10 implementers]
src/core/agents/types.ts
RendererOptions (Interface)
(no doc)
src/renderer.ts
Cell (Interface)
(no doc)
src/renderer-diff.ts
CliMockOverrides (Interface)
(no doc)
src/cli.test.ts
WorktreeRunResult (Interface)
(no doc)
src/cli.ts
Star (Interface)
(no doc)
src/utils/stars.ts
RunResult (Interface)
(no doc)
e2e/e2e-acp.test.ts
RunResult (Interface)
(no doc)
e2e/e2e.test.ts

Core symbols most depended-on inside this repo

run
called by 137
src/core/agents/types.ts
appendDebugLog
called by 128
src/core/debug-log.ts
getState
called by 46
src/core/orchestrator.ts
textToCells
called by 43
src/renderer-diff.ts
serializeError
called by 41
src/core/debug-log.ts
start
called by 34
src/core/orchestrator.ts
close
called by 29
src/core/agents/types.ts
git
called by 25
src/core/git.ts

Shape

Function 394
Method 126
Interface 70
Class 44

Languages

TypeScript100%

Modules by API surface

src/core/agents/opencode.ts53 symbols
src/renderer.ts45 symbols
src/cli.ts42 symbols
src/core/agents/rovodev.ts36 symbols
src/core/orchestrator.ts32 symbols
src/core/telemetry.ts31 symbols
src/core/git.ts27 symbols
src/core/config.ts24 symbols
src/core/agents/pi.ts22 symbols
src/core/run.ts20 symbols
src/core/exit-summary.ts19 symbols
src/core/agents/acp.ts18 symbols

Dependencies from manifests, versioned

@eslint/js9.0.0 · 1×
@types/js-yaml4.0.9 · 1×
@types/node22.0.0 · 1×
@vitest/coverage-v84.1.2 · 1×
acp-mock1.1.0 · 1×
acpx0.6.1 · 1×
commander14.0.3 · 1×
eslint9.0.0 · 1×
eslint-config-prettier10.0.0 · 1×
js-yaml4.1.1 · 1×
prettier3.0.0 · 1×
tsdown0.21.7 · 1×

For agents

$ claude mcp add gnhf \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact