Skip to content

About

Mission Kit recipe: an unattended night of plan ticks across several repos, with budget caps, an env-only API key and a morning report that only shows what is still open.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Repository files navigation

Night Shift

Mission Kit logo

A Mission Kit recipe. An unattended night of plan ticks across several repos: one fire at a time, in the order you choose, inside a time window and a budget, with a morning report that shows only what is still open when you read it.

<angle-bracket> names in this README are placeholders you fill in for your own setup. Every repo name in the examples (acme-app, acme-api, acme/*) is fake.

Problem

Mission Kit's agent-kit countdown runs one headless plan tick per invocation and exits. That is the right primitive, but one fire per timer per repo does not make a night. A night of six hours over five repos wants a loop that keeps a repo going while it does work, moves on when it hits a gate or asks a question, and stops at the window end or when the money runs out.

Everyone who wants that writes the same glue: the loop, a way to keep an API key out of logs and unit files, a nightly and monthly ceiling, a choice of model per kind of work, and a morning summary that is already stale by the time you read it. Night Shift is that glue, written once, on top of the kit's own exit codes, result line and cost ledger.

What a night looks like

23:00  timer starts bin/night-shift            window 23:00-06:00, budget 20 USD tonight / 200 this month
23:00  acme-api   exit 0  ok               1.85   tick did work, same repo again
23:31  acme-api   exit 0  ok               2.10
00:04  acme-api   exit 5  needs-operator   0.40   "agent requested stop: which queue backend?"  -> next repo
00:07  acme-app   exit 2  needs-operator   -      gate exit pending from yesterday               -> next repo
00:08  acme-docs  exit 0  ok               0.60
00:21  acme-docs  exit 0  ok               0.20   "plan exhausted"                               -> next repo
00:23  acme-inbox exit 3  broken           0.05   Circuit's Dead: no stream event for 15 min     -> next repo
00:39  end: all repos visited; 7 fires
07:30  timer starts bin/night-shift-report     re-checks every open item, mails the result

Each line is one agent-kit countdown --cwd <repo> --backend claude ... fire. The kit does the plan work, the git work and the gate handling, under its own one-tick contract (it never runs /git-prod). Night Shift only decides which repo fires next and when to stop.

Requirements

  • Linux or macOS.
  • bash (3.2 or later), git, jq, and the usual coreutils. flock only for the cron example.
  • gh or glab, authenticated, in the environment the timer runs in: the kit's ticks use them to open pull or merge requests.
  • The claude CLI, logged in (subscription) or with an API key (see Guards).
  • The Mission Kit CLI, pinned: npm install -g @dadado/agent-kit-cli@6.25.0, installed in each repo with agent-kit install --claude, and an active plan in each repo (for example from /start-project) so the ticks have work.

Quick start

git clone https://github.com/mission-kit/night-shift.git ~/night-shift
cd ~/night-shift
bash tests/run.sh                      # no network, no agent: a fake agent-kit stands in

mkdir -p ~/.config/night-shift
cp config.env.example ~/.config/night-shift/config.env && chmod 600 ~/.config/night-shift/config.env
cp repos.example ~/.config/night-shift/repos            # then list your own clones
  1. Give the loop its own clones. For each repo, a dedicated clone that nobody edits by hand (countdown refuses a dirty tree, and you must not race the agent): git clone <your-repo-url> <user-home>/night/acme-api, then mark it: git -C <user-home>/night/acme-api config night-shift.owned true. Prefer clones to worktrees: in a worktree, plain git config writes the shared repo config, so your own checkout would read as owned too (see docs/config.md for the worktree variant).
  2. Set the window and the budget in config.env (NS_WINDOW_START, NS_WINDOW_END, NS_NIGHT_BUDGET_USD, NS_MONTH_BUDGET_USD, NS_TICK_BUDGET_USD). Every key: docs/config.md.
  3. Check: bin/night-shift --check validates the config, the pinned kit version, each repo and the budget left, and fires nothing.
  4. Install the timers from units/: systemd user units on Linux, launchd agents on macOS, or the cron example. The operating system fires the recipe; neither Night Shift nor the kit schedules anything.
  5. Watch the first night (see plan-template.md, last step) before you trust it unattended.

The same steps, as a Mission Kit plan with its decision points, are in plan-template.md.

Configuration

Two files, both outside any repo:

  • ~/.config/night-shift/config.env (from config.env.example, chmod 600): the window, the caps, billing and budgets, the model per task class, the pinned kit version and the report delivery hook. It is sourced as shell; the scripts refuse it when group or others can write it.
  • ~/.config/night-shift/repos (from repos.example): one owned clone per line, in firing order, with optional class=, model= and max_fires=.

Every key, its default, the files the scripts write and the exit codes are in docs/config.md.

Local model

Status: experimental. One supervised fire has completed a tick on a local model; no full night has run yet. Use it supervised.

Tested on 2026-11-29: Qwen3.8 27B (Q4 quantization, 256k context) on an integrated GPU, behind an Anthropic-compatible server. The fire took a trivial to-do from pending to completed: 27 turns, 58 minutes, file written, commit merged into the pre-production branch by /git-staging, HANDOFF updated, correct result line. claude reported 5.10 USD for it; local mode counted 0.

NS_BILLING=local points every fire at a model server on your own machine that speaks the Anthropic Messages API (Ollama does, at http://127.0.0.1:11434). A night then costs no API spend:

NS_BILLING=local
ANTHROPIC_BASE_URL=http://127.0.0.1:11434
ANTHROPIC_AUTH_TOKEN=local                 # whatever the server expects; Ollama accepts calls without one
NS_MODEL_CODE=my-local-model               # the server's own model names, for each class you use
ANTHROPIC_DEFAULT_HAIKU_MODEL=my-local-model
ANTHROPIC_DEFAULT_SONNET_MODEL=my-local-model
ANTHROPIC_DEFAULT_OPUS_MODEL=my-local-model
CLAUDE_CODE_SUBAGENT_MODEL=my-local-model

What local mode changes:

  • Fail closed. The loop refuses to start without ANTHROPIC_BASE_URL, or when it is not on 127.0.0.1, localhost or [::1] (NS_LOCAL_REMOTE_OK=1 allows a model server on another machine that bills nothing). The host must be exactly one of those three, with an optional numeric port: a URL with a user name or @ in its host part counts as remote. Fires run without ANTHROPIC_API_KEY.
  • No budgets. claude does not know a local model's price, so it prints a made-up one: a one-word reply from an 8B model came back as about 0.017 USD. That figure lands in the kit's cost ledger. Local mode passes no --budget-remaining, sets no per-tick cap, ignores the three budgets, logs no cost per fire, and lists its fires in local-fires.tsv so every spend sum (the loop, --check, the morning report) counts them as 0. The caps that still hold are the window, the fire caps and the kill switch. Outside local mode the sums fail closed instead: a fire on a model claude cannot price (kit 6.26.0 and later record cost_usd: null with cost_usd_reported and cost_basis: "unknown") counts at the figure claude reported.
  • Model names. NS_MODEL_TRIAGE, NS_MODEL_SYNTHESIS, NS_MODEL_CODE and model= take the names the server lists (ollama list). claude resolves its own aliases (haiku, sonnet, opus) and subagent model through ANTHROPIC_DEFAULT_*_MODEL and CLAUDE_CODE_SUBAGENT_MODEL; set them to a local model so no call asks the server for a Claude model it does not serve.

Coming next: the kit's own local backend (in development, not in a release yet) drives a local model without claude in between and reports no cost by construction. Early runs of the same tick on the same model took minutes instead of an hour. Once it ships in a kit version this recipe pins, it should replace the gateway route described here.

Known limits, from the first tests:

  • Small models cannot do a tick. On a real fire (2026-11-28, Ollama, llama3.1:8b with a 32k context), the model answered the tick in one turn with no tool call: it described the steps, printed LOOP_TICK_RESULT: continue and changed nothing. The 27B model above did the same to-do with 26 tool calls.
  • An ok fire is not proof of work. The kit recorded that empty fire as ok / completed, so the loop would fire the same repo again up to its cap. On a local model, check in the morning that the to-dos actually moved before trusting the Done section.
  • Context length. The claude system prompt and tool list are large. Ollama picks a default context from the memory it sees (its runner started at 4096 tokens here, with context shift on, which drops the start of a longer prompt). Raise it with OLLAMA_CONTEXT_LENGTH or a model with PARAMETER num_ctx. claude reported a 1M-token window for the unknown model, so do not count on its own compaction to stay under the server's limit.
  • Protocol. The server must speak the Anthropic Messages API, tool use included. A server that only offers the OpenAI chat API needs a translating proxy in front of it; Night Shift does not ship one.
  • Speed. A local tick is much slower than a hosted one (58 minutes for a one-line file above). Raise NS_FIRE_WINDOW_MIN and NS_STALL_MIN so a slow tick is not taken for a stall.

What runs

Piece What it does
bin/night-shift The linear loop. Started by the timer at the window start. Fires agent-kit countdown in each listed repo, in order; exit 0 fires the same repo again (up to its cap), an exhausted plan, exit 2, 3 or 5 move to the next repo. Ends at the window end, the night cap, an exhausted budget or the kill switch. Before each fire it sums the cost ledgers and passes --budget-remaining. One instance at a time (a lock directory). Writes one run-log line per fire.
bin/night-shift-key Env-only API-key wrapper: reads the key from a mode-600 file (or the existing environment) and execs the fire with ANTHROPIC_API_KEY set for that process only. Honors the kill switch.
bin/night-shift-report The morning report: done, needs you, broken, spend. Collected when it runs, not when the night ended, and drops items you resolved in between.
units/ systemd user service and timer pairs for the loop and the report, an OnFailure= example, launchd agents and a cron example. All templates with placeholders.

Model per task

The kit picks a model per role (roles.worker in .cursor/context/config.json) or per plan (worker_model in the plan front matter), and --model on a fire overrides both. Night Shift adds a default by kind of work, set per repo in the repos list:

Class (repos list) Kind of work Model Config key How it reaches the kit
class=triage triage, classification, inbox sorting small (for example haiku) NS_MODEL_TRIAGE countdown --model <value>
class=synthesis reports, summaries, docs mid (for example sonnet) NS_MODEL_SYNTHESIS countdown --model <value>
class=code code with tests top (for example opus) NS_MODEL_CODE countdown --model <value>
model=<id> on the line anything the one you name - countdown --model <id>
no class, no model per plan the plan decides - no --model: plan worker_model, else roles.worker.model

Because --model beats the plan's worker_model, a repo whose plans each choose their own model should have no class=: the loop then passes no --model and the kit's precedence (flag, then plan, then config) applies. There is no per-plan key in Night Shift; per plan is the plan's own worker_model.

Guards

  • The kit never schedules, and Night Shift never pushes. The timer you install starts the loop. Every git action happens inside a kit tick under its contract: /git-staging on a diff, never /git-prod.
  • One fire at a time. A lock directory under ~/.local/state/night-shift/ stops a second loop; a lock whose process is gone is taken over. Countdown itself refuses a pending gate exit and a dirty tree.
  • Only clones the loop owns. A repo must be marked with git config night-shift.owned true, or it is skipped and reported. Lock, logs and reports live outside every repo, so the loop never dirties a tree.
  • Budget before every fire. Night and month spend are summed from the kit's cost ledgers across all listed repos and passed as --budget-remaining; the kit refuses a fire it cannot cover, and the night ends. NS_TICK_BUDGET_USD caps each tick (AGENT_KIT_CLAUDE_MAX_BUDGET_USD). With API-key billing the loop refuses to start without a ceiling.
  • The API key lives in one process. night-shift-key reads it from a file that must be yours and mode 600 (or from the environment a secret manager prepared), exports it only into the process that becomes the fire, and never prints it. It is not in argv, the run log, a unit file or a repo. The kit redacts it from its own logs as well.
  • Subscription stays subscription. With NS_BILLING=subscription, fires run with ANTHROPIC_API_KEY removed, so a key left in your shell does not turn a night into API spend.
  • Local stays local. With NS_BILLING=local, the loop refuses an endpoint that is not on this machine unless you vouch for it, and fires run without a key (see Local model).
  • Kill switch. touch ~/.config/night-shift/STOP: no further fire starts, and the key wrapper runs nothing. Remove the file to resume.
  • A window that holds. A fire starts only when its whole --window-min fits before the window end, so the night never kills a tick halfway.
  • Headless permissions. The kit runs claude -p ticks with permissions bypassed and prompts denied (its documented headless mode). Only list repos whose plans and code you have reviewed.

How it fails, and how you are told

The morning report (bin/night-shift-report, from its own timer) has four sections:

Section What lands there What to do
Done Every fire of the night that exited 0, with plan, to-do and cost. Review the pull or merge requests the ticks opened.
Needs you Repos whose last fire exited 5 (the agent asked a question) or 2 (a gate exit is pending). Answer in the plan or HANDOFF, or triage the gate with agent-kit ground-control. A pending gate makes the next night's fire in that repo refuse at once (no agent, no cost). A question leaves no gate behind: until you answer it, the next night's first fire there will likely stop on the same question and cost one tick.
Broken Exit 3 (Circuit's Dead: failure, stall, dirty tree, fetch failed), a fire with no result line, a repo that is not owned or not a repo. Read the fire output in ~/.local/state/night-shift/fires/ and the kit's .cursor/loop-logs/countdown-*.log.
Spend Tonight and this month from the cost ledgers, against your budgets, per repo; budget refusals. Compare with your provider's usage page.

The report re-checks each open item when it runs and drops it when the to-do is now completed or cancelled, HANDOFF has a DONE/DECIDED line naming it, the gate exit was triaged, or every branch it cites is merged into your pre-production branch. These checks read local files and local refs only (NS_REPORT_FETCH=1 adds one git fetch). A squash merge is not visible to git branch --merged; the to-do and HANDOFF checks usually cover it.

Delivery is yours: NS_REPORT_HOOK runs any command with the report file (mail, a desktop notice, a chat webhook script). The loop's own unit can also call an OnFailure= unit when a night ends broken (exit 3) or misconfigured (exit 1); exit 5, a repo waiting for you, is declared a success with SuccessExitStatus=5.

Known debt

  • Written before the kit's recurring-plan contract. Mission Kit has an open design for recurring plans (routines r2). Night Shift predates it and drives plain countdown fires from an OS timer. When that contract lands, the recipe will move onto it.
  • Path claims are parked. Two workers in different worktrees of the same repo can still edit overlapping paths. The kit's lease covers one checkout. Night Shift avoids the problem by being linear (one fire at a time across all repos); a claim mechanism waits for the loop pattern to settle.
  • Cost comes from the backend. The ledger holds what claude reports; other backends record no cost, and the budget then counts them as 0. For a model it does not know, claude reports a made-up price; local mode skips those lines, while under subscription or api-key they count at that figure, which can be above or below the real bill.
  • Spend outside the listed repos is invisible. Daytime runs in other clones do not count against the night or month budget unless you list those clones.
  • Daylight-saving nights shift the window by an hour.
  • A question can cost one tick per night. Exit 5 lands no gate, so a repo whose question you have not answered stops on it again the next night. Answer before the next window, or take the repo off the list.
  • Not yet soaked. The scripts are covered by tests against a fake agent-kit; a run of real nights on the public version is still to come.

How Mission Kit fits

Mission Kit is the agent harness this recipe drives: each fire is agent-kit countdown, and the plans, gates, HANDOFF and cost ledger are the kit's. Install it at the pinned version:

npm install -g @dadado/agent-kit-cli@6.25.0
agent-kit install --claude      # in each repo the loop owns

The version is pinned on purpose; nothing from the kit is vendored or forked here. Mission Kit is installed under its own license and is not redistributed by this repo. If the recipe hits a gap in the kit, file it as a kit Backlog item instead of patching the kit. To adopt the recipe with an agent walking you through the decisions, run /start-project with plan-template.md as the payload.

Trademark

  • The code in this repo is MIT-licensed (see LICENSE): use it, fork it, ship it.
  • The Mission Kit name and the Mission Kit logo (assets/logo.svg) are marks of Mission Kit and are not covered by the MIT license. Forks and redistributions must not use them in a way that suggests endorsement.
  • The mark in assets/logo.svg is the Mission Kit mark (a white stroke), not the older Agent Kit / Startup Kit logo.
  • To use your own image: replace assets/logo.svg with any SVG (square works best). Nothing in the scripts reads it; it is shown at the top of this README (the <img> tag under the title). The product name appears in this README and in the report heading (render() in bin/night-shift-report).

Repository layout

bin/             night-shift (loop), night-shift-key (API-key wrapper), night-shift-report (morning report)
lib/common.sh    config, repos list, window and ledger helpers shared by the three scripts
units/           systemd/, launchd/, cron/ templates
docs/config.md   every config key, the repos list format, files written, exit codes
tests/           shell tests with a fake agent-kit (tests/run.sh)
scripts/         hygiene-scan.sh
assets/logo.svg  the Mission Kit logo (see Trademark)
plan-template.md adopting the recipe as a Mission Kit plan for /start-project

Contributing and security

Run bash tests/run.sh and bash scripts/hygiene-scan.sh before you push. To also check for your own host, account and project names without committing them, list them in a file outside the repo and run HYGIENE_DENYLIST=/path/to/denylist.txt bash scripts/hygiene-scan.sh. See SECURITY.md for how to report a problem.

License

MIT, see LICENSE. The Mission Kit name and logo are excluded (see Trademark).

About

Mission Kit recipe: an unattended night of plan ticks across several repos, with budget caps, an env-only API key and a morning report that only shows what is still open.

Topics

Resources

Security policy

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages