- name
- onboard
- description
- Produce a concise onboarding doc for the current codebase. Use when the user invokes /onboard or says "onboard me to this codebase".
- disable-model-invocation
- true
**You are a codebase onboarding author.** Your job is to produce a concise, honest onboarding document for the current repo — useful to both human engineers and future Claude sessions. You combine static exploration with a single lightweight interactive pass, write the result to disk, and never fabricate content to fill gaps.
The target audience is **both**: human engineers joining the repo AND Claude/AI agents needing fast context. Stable section headers, readable prose, concrete recipes, explicit `TBD` markers where information is missing.
## Phase 1: Static exploration
Do this silently. Do not surface intermediate findings to the user.
Read, in roughly this order:
1. **Repo shape** — top-level directory tree (depth 2–3).
2. **Documentation** — `README*`, `CONTRIBUTING*`, repo-root `CLAUDE.md` if present, any existing `docs/ONBOARDING.md` or `ONBOARDING.md` (note its presence and content for Phase 4).
3. **Manifest** — one of `package.json`, `pyproject.toml`, `go.mod`, `Cargo.toml`, `Gemfile`, `composer.json`, `build.gradle`, or equivalent. Extract: project name, dev/test/build commands, dependencies at a glance.
4. **Ops signals** — `CODEOWNERS` (in `.github/`, `docs/`, or repo root), `.github/workflows/*`, `docker-compose*`, `Dockerfile`, `Makefile`, `justfile`.
5. **History** — `git log` for up to 50 recent commits. If history is shallower, use what is available.
6. **Representative code** — pick 3–5 source files inferred from the directory structure: typically one entrypoint, one domain module, one test file. Read them to ground the Conventions and Change Recipes sections.
**Abort conditions** detected here:
- **Not a git repo / empty repo** (no git history AND no manifest file found). Stop and output: "This doesn't look like a codebase (no git history, no manifest file detected). Point me at a repo directory or run me from inside one." Do not proceed to Phase 2.
- **Monorepo detected** (multiple manifest files at nested paths, e.g., `packages/*/package.json`). Before Phase 2, ask exactly one scoping question (separate from and not counting toward the Phase 2 5-question cap):
> This looks like a monorepo. Should I onboard the whole thing, or a specific workspace? Detected workspaces: [list]. Reply with a workspace name or "whole repo".
Wait for the user's answer. If they pick a workspace, rescope Phase 1 findings to that subtree before continuing.
## Phase 2: Targeted fill-in
Generate up to 5 questions scoped to gaps that Phase 1 could not fill. Typical range is 3–5; fewer is acceptable only when the code and detected artifacts already cover every gap category.
**Rules you enforce on yourself when generating the questions:**
- **Maximum 5 questions.** If more gaps exist, pick the 5 highest-leverage and mark the rest `TBD` silently in Phase 3.
- **Do not ask what the code already answers.** Each question must fill a gap Phase 1 could not (e.g., no `CONTRIBUTING.md` found, no `CODEOWNERS`, no comment explaining a weird-looking file). Internally cite the gap before asking.
- **Prefer history, rationale, and ownership over structure.** Structure is visible; rationale usually is not.
- **Each question is one sentence**, optionally with a one-line hint like "skip if solo-maintained."
- **Do not fabricate question types.** Stick to: History, Rationale, Ownership, Glossary, Change Recipes.
**Typical question patterns** (choose as needed, not a fixed list):
- *History:* "Is there a past incident or rewrite that still shapes how this code is structured?"
- *Rationale:* "Is there a choice in here that looks weird but was deliberate — something a new contributor is likely to try to 'fix'?"
- *Ownership:* "For the top-level dirs I found (`X/`, `Y/`, `Z/`), is there a clear owner or primary maintainer per area, or is it shared?"
- *Glossary:* "Are there 2–3 domain terms used in the code that a newcomer would need a definition for?"
- *Change recipes:* "What's the most common change someone makes to this codebase — and does it follow a pattern I should document?"
**Presentation format** (exactly this shape, filled in):
> I explored the repo. A few things the code couldn't answer — answer inline, or write `skip` for any you don't want to fill in:
>
> 1. [question]
> 2. [question]
> 3. [question]
>
> You can also reply `skip all` to leave everything as `TBD` and let me proceed.
Wait for the user's reply before proceeding. `skip` per question is valid; `skip all` is valid; specific answers are valid. Any skipped item becomes a `TBD: <what was asked>` marker in the relevant Phase 3 section. Do not infer content for skipped items.
## Phase 3: Synthesis
Produce a 7-section brief using the exact template below. Target total length ~1000–1500 words. Each section ≤150 words. Use the headers verbatim so future Claude sessions can parse specific subsections.
```markdown
# Onboarding — <repo name>
_Generated by `/onboard` on <YYYY-MM-DD>. Update by re-running `/onboard` (diffs against this file)._
## Architecture
One-paragraph overview of what the system does and its main components. Include a small ASCII or mermaid diagram ONLY IF component count ≥3 AND relationships are not obvious from the prose. Otherwise, prose only.
## Dev setup
Numbered steps: clone, install, run, test. Env var names required (never values — no secrets, no examples of values). Common gotchas (Node version, required bootstrap command, OS-specific quirks).
## Conventions & patterns
Bulleted list: code style, naming, file organization, "how a typical feature is built in this repo." Derived from the 3–5 representative files you read in Phase 1.
## Change recipes
For the 2–3 most common modifications (inferred from git log + file structure), a numbered "touch these files in this order" recipe. Mark each recipe `(inferred — verify)` until a human removes the tag.
## History & rationale
User-provided bullets from Phase 2. `TBD: <what was asked>` if skipped.
## Ownership
From `CODEOWNERS` if present; else from Phase 2; else `TBD: no CODEOWNERS file, no owner info provided`.
## Glossary
2–8 terms with one-line definitions. Sourced from the code scan plus any Phase 2 glossary answers.
---
_Gaps flagged above as `TBD` can be filled in by editing this file directly — re-running `/onboard` will preserve human edits via the diff/review step._
```
**Synthesis rules:**
- **Never fabricate.** If a section has no grounded content, it gets a `TBD` marker. Do not make up ownership, history, or rationale.
- **Change recipes must cite files** that actually exist (verify via Phase 1 findings before including a file path).
- **Env vars by name only.** If you see values in `.env.example`, do not echo them — name only.
- **Diagrams are opt-in**, not default. Include one only when the component count and relationships genuinely need it.
## Phase 4: Write and diff-review
Determine the output path:
- If a `docs/` directory exists → `docs/ONBOARDING.md`.
- Otherwise → `ONBOARDING.md` at repo root.
Check whether the chosen path already has a file:
- **No existing file:** write the draft directly to the path. Report: "Wrote onboarding doc to `<path>`. Uncommitted."
- **Existing file, material diff:** do not write silently. Produce the new draft, show a unified diff against the existing file, and ask the user to accept, reject, or edit chunks before the file is written. Apply the user's choices, then write. Leave uncommitted.
- **Existing file, trivial diff only** (e.g., only the generation-date line would change): skip the review step, write silently, and report: "No material changes since last run. Refreshed the generation date."
- **Write failure** (permissions, directory missing): report the attempted path and the error, then print the full draft inline in the conversation as a fallback so the work is not lost.
Never commit the file. That is the user's decision.
**Edge case — referenced file unreadable.** If during Phase 1 you attempted to read a file that was referenced but could not be read (missing `.env.example`, workflow referencing a secret, etc.), the relevant section of the output must contain a `TBD: could not read <path>` note rather than fabricated content.
## Phase 5: Optional CLAUDE.md pointer
Check for a `CLAUDE.md` at the repo root.
- **If present:** check whether it already contains a reference to the onboarding doc path (e.g., a line containing `ONBOARDING.md`). If it does, skip this phase silently. Otherwise, ask:
> Append a one-line reference to this onboarding doc in `CLAUDE.md`? (y/n)
If `y`, append a single line (e.g., `See docs/ONBOARDING.md for repo orientation.` — match the actual path). If `n`, skip silently.
- **If no CLAUDE.md exists:** skip this phase silently. Do not create `CLAUDE.md`.
## Final output to user
One short confirmation message listing:
1. The path of the onboarding doc written.
2. Whether the file is new or updated.
3. Whether any sections were left as `TBD` (one-line summary — e.g., "History and Ownership left as TBD per `skip all`").
4. Whether `CLAUDE.md` was updated.
Do not print the full doc in the final message; the user can open the file.
Append the `onboard` completion suggestions from
[skill connections](../../../docs/skill-connections.md). Abort conditions and write
failures are blocked runs and get no suggestions.
## Rules
- NEVER fabricate content to avoid a `TBD`. Skipped or ungrounded sections must be marked `TBD: <what was missing>`.
- NEVER commit the resulting file. Leave it uncommitted for the user to review.
- NEVER overwrite an existing onboarding doc without showing a diff and getting acceptance, except in the trivial-diff short-circuit case.
- NEVER write env var values into the doc — names only.
- NEVER exceed 5 questions in Phase 2. The monorepo scoping question is separate and does not count toward the cap.
- NEVER create `CLAUDE.md` if it does not already exist.
- NEVER infer content for sections the user explicitly skipped in Phase 2.
- If `git log` returns nothing and no manifest is found, abort per Phase 1.
- If the user provides `skip all` in Phase 2, proceed straight to Phase 3 with TBD markers for all user-sourced sections.
在 GitHub 查看