gnhf README

The project's README from github.com/kunchenguid/gnhf. As one markdown file: README.md.

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.

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│  │ maybe wait│                  │
              └────┬─────┘  └─────┬─────┘                  │
                   │              │                        │
                   │   ┌──────────┘                        │
                   ▼   ▼                                   │
              ┌────────────┐    yes   ┌──────────┐         │
              │ 3 consec.  ├─────────►│  abort   │         │
              │ failures   │          └────▲─────┘         │
              │ or perm.   ├───────────────┘               │
              │ error?     │                               │
              └─────┬──────┘                               │
                 no │                                      │
                    └──────────────────────────────────────┘

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.

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

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: a native agent name or acp:<target-or-command>; see Agents config file (claude)
--model <model> Model for the agent; overrides agentModel.<agent> from the config file config file
--max-iterations <n> Abort after n total iterations unlimited
--max-tokens <n> Abort after n total input+output+cache tokens unlimited
--max-rate-limit-wait <duration> Abort after this much total Claude usage-limit wait (30m, 2h, or 0) 24h safety cap
--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

Config lives at ~/.gnhf/config.yml. If the file does not exist yet, gnhf creates it on first run with its defaults. A supplied --agent is written as the default agent. With the default configuration, it has this exact content:

# Agent to use by default: native agent name or acp:<target-or-command>
agent: claude

# Custom paths to native agent binaries (optional)
# Paths may be absolute, bare executable names on PATH,
# ~-prefixed, or relative to this config directory.
# Note: rovodev overrides must point to an acli-compatible binary.
# agentPathOverride:
#   claude: /path/to/custom-claude
#   codex: /path/to/custom-codex
#   copilot: /path/to/custom-copilot
#   pi: /path/to/custom-pi
#   cursor: /path/to/custom-cursor-agent

# Native agent CLI arg overrides (optional)
# ACP targets do not support path or arg overrides.
# agentArgsOverride:
#   codex:
#     - -m
#     - gpt-5.4
#     - -c
#     - model_reasoning_effort="high"
#     - --full-auto
#   copilot:
#     - --model
#     - gpt-5.4
#   pi:
#     - --provider
#     - openai-codex
#     - --model
#     - gpt-5.5
#     - --thinking
#     - high
#   cursor:
#     - --model
#     - composer-2.5

# Models for supported native agents (optional)
# Values are forwarded to the CLI except opencode, which receives
# its model in the request body.
# agentModel:
#   claude: sonnet
#   codex: gpt-5.4
#   opencode: fireworks-ai/accounts/fireworks/models/qwen3p6-plus

# Custom ACP target commands (optional)
# Maps acp:<target> names to spawn commands. Useful for naming a
# local or beta build of an ACP agent.
# acpRegistryOverrides:
#   my-fork: "/usr/local/bin/my-claude-code-fork --acp"
#   staging: "node /opt/staging/agent.mjs"

# Commit message convention (optional)
# Defaults to: gnhf <iteration>: <summary>
# Use Conventional Commits semantic-release headers:
# commitMessage:
#   preset: conventional

# Abort after this many consecutive failures
maxConsecutiveFailures: 3

# Prevent the machine from sleeping during a run
preventSleep: true

CLI flags override config file values. --prevent-sleep accepts on/off as well as true/false; the config file always uses a boolean. The iteration, token, and rate-limit-wait caps are runtime-only flags and are not persisted in config.yml; --stop-when is persisted per run for resume, but not in config.

`

gnhf (kunchenguid/gnhf)

Searching Database…

4.2K ·GitHub
这是什么?gnhf 是一个面向 AI 编程代理的通宵编排工具:睡前给它一个目标,它就会自主循环运行,每一轮迭代都朝目标做出一个小的、已提交、有记录的改动。早上醒来,你会得到一个干净的工作分支和一份记录了全部过程的日志。
那这是个终端工具、后台服务,还是个库?是终端工具:用 npm 安装,在你的仓库里用一条命令启动。运行时会在交互式 TUI 里实时显示状态、token 总数和提交数,每次运行结束还会给出一份永久保存的退出摘要,包括耗时、迭代次数、token 用量和 diff 统计。
怎么启动一次运行?先从 npm 安装这个包,然后在一个工作区干净的 Git 仓库里运行 gnhf,比如 gnhf 'fix all failing tests'。如果是普通目录,需要先 git init;较大的需求说明可以用 cat prd.md | gnhf 管道传入。
我需要自己准备 AI 编程代理吗?需要——gnhf 是驱动编程代理的 CLI,本身不带模型。默认使用 Claude,其他常用的编程代理 CLI 以及任何 ACP 目标也都可以,另外还需要 Node.js 20 或更高版本以及 Git。
让它跑一整晚之前,有什么要注意的坑?要从干净的工作区开始,另外提交是刻意不加签名的,这样 GPG 或 SSH 的提示永远不会卡住循环。在 Linux 上有一个已知 bug:systemd-inhibit 重新执行后可能留下一个空的 worktree——用 git worktree remove 手动删掉即可。
它能在 Windows 上跑吗,还是只有 Mac 和 Linux 能用?三大桌面系统都支持:gnhf 支持 macOS、Linux 和 Windows。它还会在运行期间尽量用 --prevent-sleep 防止电脑休眠,这个选项默认开启。
一次迭代具体会做什么?成功的迭代会作为一次独立的未签名 Git 提交保存下来;失败的迭代会用 git reset --hard 回滚。代理通过 notes.md 传递上下文,每轮迭代都会读取并追加这个文件,所以后面的迭代能记住前面的工作。
如果代理半夜用完了额度怎么办?它会等待而不是报错:gnhf 会从代理的限流事件里读取重置时间,睡到窗口刚刚重置之后,然后自动重试同一轮迭代。--fallback-model 还可以让被拒绝的迭代换一个模型重试。
怎么防止它一整晚烧 token?有三个运行时上限:--max-iterations 会在下一轮迭代开始前停下,--max-tokens 会在迭代中途一旦上报的用量超过上限就中止,--stop-then 则在代理确认你用自然语言写的条件已满足时结束循环。
能在同一个仓库上同时跑多个代理吗?可以——加上 --worktree,每个代理都会得到一个带独立分支的隔离 Git worktree,不会碰你的主检出目录。事后,包含提交的 worktree 会被保留下来,方便审查或 cherry-picking;请从 main 这样的普通分支启动。
Size
4.4 MB
Stars
4.2K
Age
6mo
Commits · 90 Days