KUN // FIELD MAP
← the map
RUNNING MANY AGENTS · PAGE 07 OF 11gnhf · firstmate · compact-adviser

gnhf and firstmate: overnight loops and a crew with one liaison

Two answers to "how do I keep agents working when I am not watching": a loop that runs alone, and a supervisor you talk to instead of the workers.
TL;DR — gnhf ("good night, have fun") points one agent at an objective and loops: each pass makes one small change, commits it if it worked and rolls it back if it did not, until a cap or a stop condition ends the run with a summary. firstmate goes the other way: you talk to a single agent, the first mate, and it spawns crewmates into their own worktrees and terminal tabs, watches them without spending tokens, and brings back PRs, merges or reports. Both treat your attention as the scarce resource. compact-adviser is a small plugin that judges when a session is at a safe point to compact.

One coding agent in one terminal is easy. Three in parallel is where most people stall: you end up switching tabs, re-pasting context, and forgetting which session had the failing test. Kun's tools for this arc attack that from two ends. gnhf removes you from the loop for a bounded stretch of time. firstmate keeps you in the loop but shrinks it to one conversation.

gnhf: a bounded loop of small commits

The idea behind gnhf comes from the "ralph loop", a technique named by Geoffrey Huntley: run a coding agent in a plain loop with the same objective each time, and let the repository itself, not the agent's memory, carry progress from one pass to the next. Each pass starts fresh, looks at the code and some notes, does a bit of work, and exits. The README also names Andrej Karpathy's autoresearch as the other model for the style. The appeal is that no single agent session has to stay coherent for eight hours; it only has to make one good step.

each iteration makes one small, committed, documented change towards an objective.

gnhf wraps that loop in the discipline a raw shell loop lacks. It refuses to start unless the working tree is clean, then creates a gnhf/ branch. Every pass builds a prompt from the objective plus notes.md, a running log that earlier passes appended to, and calls your agent in non-interactive mode. A successful pass becomes its own commit, so any single change can be reverted or cherry-picked later. A failed pass is thrown away with git reset --hard. A pass that changes nothing also counts as a failure, and three failures in a row end the run. That rule stops an agent from burning the night on a task it cannot do.

objective prompt.md, clean tree build prompt objective + notes.md run agent non-interactive pass worked? commit append notes.md yes roll back git reset --hard no abort 3 failures in a row exit summary branch, diff, tokens next pass cap reached: iterations, tokens, run time, or stop-when
The gnhf loop, simplified from the README's flowchart. State lives in git commits and notes.md, not in any one agent session. Commit failures are a special case: the work is kept and the next pass is asked to repair it.

You bound the run with caps: a number of iterations, a token budget (counting input, output and cache tokens), a wall-clock time, or --stop-when, a plain-language condition the agent reports when it believes it is met. If a subscription's usage window runs out mid-night, gnhf reads the reset time and waits rather than failing or silently buying overage. When it stops, it prints a summary with the branch, iteration and token counts, diff stats and the commands to review the work.

npm install -g gnhf
gnhf "reduce complexity without changing functionality" \
  --max-iterations 10 --max-tokens 5000000
gnhf --worktree "add tests for module Y" &   # parallel runs, one worktree each

It works with Claude Code, Codex and several other agent CLIs, plus anything that speaks ACP (the Agent Client Protocol, a standard way for a tool to drive a coding agent). Limits: the loop only knows that a pass "worked" by what the agent and your checks report, so a weak test suite lets weak commits through; one small step at a time suits cleanup, coverage and incremental features better than a large redesign. The README is candid about rough edges, such as a Linux sleep-prevention path that can leave an empty worktree behind for you to remove.

firstmate: an agent distro, not an app

firstmate takes the opposite stance. Instead of leaving the agent alone, you talk to it all day, but only to one of them. The first mate is your single liaison. It reads your projects, writes briefs, and dispatches crewmates to do the actual work, so it is always free to take the next request.

firstmate is not a model, not a harness, not a skill, not an MCP server, and not a CLI.

What it is, in Kun's term, is an agent distro: a directory of instructions (AGENTS.md), skills, helper scripts and conventions for where state lives on disk. The analogy is a Linux distribution, which turns a generic kernel into a particular system. There is nothing to install; you clone the repo and launch a supported harness inside it (Claude Code, Grok and Pi are the co-primary recommendations; Codex, OpenCode and others are also listed). The instructions turn that general-purpose agent into the first mate, and you become the captain.

you, the captain first mate (one agent session) briefs, backlog, state on disk; zero-token watcher secondmate own home, own crew crewmate: ship own tab + worktree crewmate: ship own tab + worktree crewmate: scout investigates only PR or local merge PR or local merge report.md plain outcomes back to you
firstmate's shape, after the README's own diagram. You never talk to a crewmate directly unless you want to; each runs in a visible tab you can open and watch. Secondmates are optional first mates of their own, for larger fleets.

How the crew runs

Each crewmate gets a clean git worktree (a second checkout of the same repository on its own branch) from treehouse, and its own window in a "session backend", the terminal multiplexer that hosts it: tmux by default, Herdr, or one of several backends the README marks as experimental. Because every worker is a real, visible terminal session, you can step into one at any time, but you do not have to.

Work comes in two shapes. Ship tasks change code and end, per project, through one of three modes: the no-mistakes validation pipeline, a direct PR, or a local merge, with an optional +yolo flag that lets the first mate merge on its own judgment. Scout tasks only investigate and leave a written report. Supervision is a bash watcher that sleeps on the fleet and wakes the first mate only when something needs attention, so idle waiting costs no model tokens. All state lives on disk, which is why a restarted first mate can reconcile where everything stood. For large fleets you can add secondmates: full firstmate homes, locally or on another machine over SSH, that each own a domain and run their own crew.

In his September video on high-throughput agentic engineering Kun shows the routine: he keeps one session open, dictates ideas to it by voice, and lets it pick which model and harness each crewmate gets based on a rules file and how much quota each subscription has left. His stated point is that the first mate never does the work itself, so it stays available to talk while seven or more crewmates run.

Asking what is left: /ahoy and /bearings

Running many tasks creates a second problem: decisions get discussed and then lost. firstmate ships slash-command skills for that. /bearings produces a short four-part digest of fleet state, and can write a dated report. /ahoy recaps what happened since your last message, lists the decisions still waiting on you, and walks you through them one at a time, most important first. Others cover stepping away (/afk), muting routine wake-ups (/quiet), and sweeping a session for knowledge worth saving before a reset (/stow).

In use: Larry's setup borrowed one idea from firstmate: a single command that asks what is still left to handle.

Limits: firstmate runs on macOS and Linux, needs Git and an authenticated GitHub CLI, and its supervision guarantees differ by harness; the README spells out which harnesses have a verified "no turn ends blind" guard and which carry more trade-offs. The first mate is read-only over your projects by design, so every change goes through a crewmate and the merge rules you set. Many backends are labelled experimental.

compact-adviser: is now a safe time to compact?

is an agent plugin that answers a single question: should I /compact now?

Compacting replaces a long conversation with a summary to free up the context window. Do it mid-task and the agent loses details it still needs; never do it and every turn gets slower and more expensive. compact-adviser waits for a settled final answer, asks a small external classifier two one-sentence questions (is the unit of work finished, and is this hands-on work or coordination), and turns the answers into a score. The bar for a hint is strict when the context is nearly empty and relaxes as it fills. On Pi and Claude Code you can opt in to letting it run /compact for you; on Codex and Grok it can only show a hint.

Caveats: it needs a third-party API key, from TypeSafe, whose Jev model does the judging, and the README states that installing it is consent to send bounded excerpts of session context to that service. On Claude Code it depends on an experimental hooks flag. In the same September video Kun's general advice is simpler still: set a fixed auto-compact threshold and spend your attention on what to build rather than on managing the context window.

Why these sit together

gnhf and firstmate look like opposites, one autonomous and one conversational, but they share a premise: the bottleneck is no longer typing code, it is the human's attention. gnhf spends none of it during the run and asks for review at the end. firstmate spends a little of it, all in one place, and keeps the noise of tool calls and tabs out of view. Both lean on the same safety rails: small changes, git as the record, worktrees to keep parallel work apart, and explicit caps or merge rules instead of trust.

Next: backpass and the distilled self · Back to the map.