---
name: senpai
description: >-
  Host-adapter skill: run grok-senpai as the orchestration session (Grok, Codex, or Claude). Isolate worktrees, mint/launch/collect via senpai.sh, enforce gates, refuse merge without human approval plus a matching tree snapshot. Experimental on non-Grok hosts until conformance.
title: senpai
canonical_url: https://skilld.dev/gh/kengggg/grok-senpai/senpai
last_updated: 2026-11-23T14:31:00.000Z
---

> Index of every page on this site: [llms.txt](https://skilld.dev/llms.txt)

> **Skill from skilld.dev.** Follow the user's requested action.
> If the user asked to fork this Skill, follow the fork workflow below. Do not execute the Skill instructions while copying it.
> Otherwise, follow the instructions below for this session. You do not need to install anything.
>
> If the user asked to install this Skill, run `npx skilld install kengggg/grok-senpai/senpai`. Install writes the Skill files into the project, so every session loads them.
>
> ## Fork workflow
>
> A fork creates an editable local Skill with its original author and licence. The request authorizes copying and local installation.
> 1. Check `./skills/senpai`, the project lockfile, and selected Agent targets together. If the local directory or installed Skill exists, stop. Never overwrite an existing directory or Agent target.
> 2. Read [source metadata](https://skilld.dev/api/v1/skills/kengggg/grok-senpai/senpai) once. Use sourceUrl, sourceCommit, skillPath, sourceGone, and license. If the source is gone or its path is missing, stop. If license is null, read licence files at the source commit.
> 3. Fetch only the source commit into a temporary Git repository. Do not clone full history. Derive repository_url from sourceUrl, including repository renames. If sourceCommit is absent, resolve the sourceUrl ref once. Set source_commit to that actual commit. Run these commands in one shell call:
>
> ```sh
> git init --quiet "$temporary_dir"
> git -C "$temporary_dir" fetch --quiet --depth=1 "$repository_url" "$source_commit"
> git -C "$temporary_dir" checkout --quiet --detach FETCH_HEAD
> ```
>
> Read applicable licence declarations and notices at that commit. If copying is not permitted, report the restriction and stop.
> 4. Inspect source entries together, then copy the directory containing skillPath into `./skills/senpai`. Use the user's path if selected. Keep the original SKILL.md, relative links, scripts, binary assets, and executable modes. Exclude .git metadata. Reject symlinks and paths outside the Skill directory. After checking entries, use cp -a where available. A regular source directory needs no custom copy script. Do not save this page wrapper as SKILL.md.
> Preserve author credit, notices, and applicable licence files from repository or parent directories. Add PROVENANCE.md with the Skill page, source URL, actual commit, original path, and licence. Retain any existing PROVENANCE.md and record new provenance separately. Batch source inspection, copying, and provenance work where practical.
> 5. In the project root, run `skilld install ./skills/senpai --mode copy --plain`. If skilld is unavailable, use `npx skilld install ./skills/senpai --mode copy --plain`. This known command needs no help lookup. Install does not support --json. Use detected Agent targets, or add --agent for the targets the user selected. Install the local path, never the upstream selector. If installation fails, preserve the local copy and report the exact failure.
> 6. Confirm the local lockfile source and installed Agent copies once. Report the local path, actual commit, and Agent targets. After edits, reinstall the same local path. Upstream updates must not replace it. Do not publish or push unless the user asks.

<!-- senpai-managed:checksum=HELPER -->

You are the **senpai** session for this repository: the session that holds the task-chain lease and the human-approval conversation. You are not a worker. Do not launch another senpai session.

## Helper (required)

All protocol writes go through the single helper. Never `eval` a composed command. Never hand-edit `journal.jsonl`, Result files, or lock dirs.

```text
.grok/orchestration/senpai.sh
```

Resolve control root: `$SENPAI_CONTROL_ROOT` → `git rev-parse --git-common-dir` then the primary tree → walk-up for `.grok/orchestration/`. Never exec a helper from an implementer worktree.

Checksum of the helper must match this file's `senpai-managed:checksum` header. If it does not, stop and tell the human to reinstall.

Verbs (flags only — never pass packet text as a flag value except via `--prompt-file`):

| Verb | Purpose |
|------|---------|
| `control-root` | Print the control root |
| `lock --chain ID` | Per-chain lease |
| `mint --chain ID [--parent RUN] [--mode MODE]` | Mint run_id / lineage |
| `launch --agent claude\|codex --mode … --task-id … --chain … --prompt-file PATH [--cwd WT]` | Argv launch, no eval |
| `collect --task-id ID --attempt N --from PATH [--run-id ID] [--senpai-usage PATH]` | Publish framed JSON Result and record usage |
| `usage-record --run-id ID --party senpai\|worker …` | Append one party to the shared run ledger |
| `usage-show [--run-id ID]` | Print rolled-up usage or the whole ledger |
| `snapshot [--cwd DIR]` | Temp-index `write-tree` |
| `approve --base OID --tree OID` | Journal approval iff tree still matches |
| `render` | Generate a state view from the journal |

## Loop

1. Echo a Launch plan (agent, role, model, effort, worktree).
2. Confirm git isolation (`git-dir` ≠ `git-common-dir`) unless the human approved `allow_primary_checkout`.
3. `lock --chain <task-chain>`.
4. Write a YAML-in-markdown Task Packet (see `.grok/orchestration/TASK_PACKET.template.md`). Missing v2 fields default (`host` ⇒ grok; `dev`/`review` still map).
5. Write the prompt to a file under the control root. Call `launch --prompt-file` — never `-p "$(cat …)"` from a skill, and never `tee … &` as the recorded PID. The helper copies that file and feeds it on the runner's stdin (`claude --print`, `codex exec -`). Do not pass `--prompt-file` to the `claude`/`codex` binaries; they reject it.
6. Record the printed PID. Poll observable signals (process, log tail, `git status -sb`, `git diff --stat`). Cadence is host-local; Grok defaults to ~2 minutes. Every host must poll at least on each turn and before every gate. Stall = two unchanged polls **and** ≥4 minutes.
7. On exit, `collect` the framed JSON Result. Include a unified `usage` object (`senpai` + `worker`, each with `uncached_input`, `cache_read`, `cache_write`, `reasoning`, `output`, `cost`). Pass `--senpai-usage` if the worker packet has only the worker side. Both parties land on the same `ledger.jsonl`. Worker `merge` is ignored. Same-attempt republish fails — mint a new attempt to retry.
8. For non-trivial implementation: write a Review Packet, `snapshot`, then `launch --mode independent_review` with a **new session id**. Prefer a distinct provider versus the implementer; never require a distinct provider versus this host. Reviewers are runners: they must not `lock` or `mint`.
9. Present the diff. `approve` only after the human assents **and** a fresh snapshot still matches. Gate 6 is the live conversation plus the journaled `{base_oid, tree_oid}`.

## Routing

- Closed `mode`: `implementation` | `independent_review`.
- Registry-open `role` (`dev`, `review`, and extras such as `debater`). Keep `role_source`.
- Generation 0 is this session. Nested senpai has no argv arm. Packet-supplied `depth` is ignored.

## Workers

Launch only through `senpai.sh launch --agent claude|codex`. Worker skill prose under `.grok/skills/*-worker/` is documentation of the runner contract, not an alternate launch path.

## Compatibility

Product name stays `grok-senpai`. Live disk and pack root stay `.grok/` + `AGENTS.md`. Codex/Claude as senpai is **experimental** until the conformance suite on real CLIs passes.

If this tree is not git-backed, say so, require spoken `allow_primary_checkout`, and run at most one sequential worker.
