# Junior Agent — setup for coding agents

The user wants you to install Junior and wire up bounded delegation. Complete this workflow in order. This document does not authorize paid model calls, commits, pushes, or destructive changes by itself; follow the human request and your environment permissions.

## 1. Establish the target and runtime

Use the project the user asked you to work on. If it is unknown, ask for its path before initializing it. Use Node.js 24 or newer, npm, and Git. On Windows use Ubuntu WSL for the Bash installer and worker execution. macOS and Linux can run it directly. Never use sudo or change authentication settings to work around an installation error.

## 2. Install the CLI

First check `junior --version`. Preserve a working installation unless an upgrade was requested.

Install or upgrade from npm. Removing the old global package first and asking npm for fresh metadata guarantees the newest release instead of a cached one:

```bash
npm uninstall -g @matthew-cochran/junior && npm install -g @matthew-cochran/junior@latest --prefer-online && junior --version
```

The same command upgrades an existing install. Afterwards, run `junior update` inside each project to adopt newer managed tools, companion tools and skills, including newer commodity models when `models.autoUpgrade` is set. Inspect the roster and plan a model change with `junior model status` and `junior model upgrade --dry-run`.

To build from source instead, use the pinned source installer. It checks out a reviewed commit, installs locked dependencies, builds JavaScript, and installs the CLI using the active npm prefix. Requires Git; no Rust is required. Download and inspect the script before executing it:

```bash
curl -fsSL https://junioragent.dev/install.sh -o /tmp/junior-install.sh
cat /tmp/junior-install.sh
bash /tmp/junior-install.sh
junior --version
```

These URLs work once the site is deployed. When testing a local site, substitute its origin (for example `http://localhost:4321`) for `https://junioragent.dev`. Do not claim deployment or npm availability without verification.

If the npm prefix is not writable, report the error or use a user-owned prefix chosen by the user; do not escalate silently. `JUNIOR_INSTALL_DIR` and `JUNIOR_NPM_PREFIX` can select user-owned installation locations. Add the selected prefix's `bin` directory to PATH if needed. This installer does not set up your project, start a worker, or collect credentials.

## 3. Initialize the project and skills

Before running init, tell the user what it will create, only when absent: `delivery.config.json`, `tasks/example-task.json`, the delegation skill in `.claude/skills/junior/` and `.agents/skills/junior/` (each with its `.junior-manifest.json`), and the companion skills for the selected targets. Init records every file it newly creates, plus `.delivery/`, as exact local Git excludes in `.git/info/exclude`, so a fresh project is worktree-ready without a commit or stash.

Run inside the intended project, using its real path:

```bash
junior init --target both
```

This installs the delegation skill into `.agents/skills/junior/` for Codex and `.claude/skills/junior/` for Claude Code; choose `--target codex` or `--target claude` if appropriate. The skill and its CLI path manifest come from the installed package. Read the installed `SKILL.md` before delegation. The website also exposes a readable copy at `/skills/junior/SKILL.md`. Re-running init refreshes an unmodified outdated skill copy; a customized copy is kept unless `--force`, and `junior doctor` names either state.

By default init also installs the tested Pi dependency when it is missing — Pi runs the worker and holds the provider credential — so no separate Pi install is needed. If that install fails, or npm cannot write the global prefix, install Pi manually with `npm install -g --ignore-scripts @earendil-works/pi-coding-agent` (or a user-owned prefix) before authenticating. Init then downloads checksum-verified prebuilt FMECA, CPM, Crossmatrix, scientific-process and elicitation tools into `~/.junior/tools` (the binaries delegated runs use), installs the npm companions `@matthew-cochran/fmeca`, `@matthew-cochran/cpm`, `@matthew-cochran/crossmatrix`, `@matthew-cochran/scientific-process`, `@matthew-cochran/elicitation`, `@jevitate/cli` and `@matthew-cochran/triz`, and runs each companion's own skill installer for the same targets. jevitate's installer also writes its user-level Claude Code skills and registers its MCP server. `--no-install` skips every install and `--no-companions` skips the companions. The two newest managed tools are registered before their first release, so a missing release is reported as `unavailable` rather than a failure. Preserve existing configuration and customized skills. Do not add `--force`. A user-wide skill install requires explicit `--user`; for a Windows-hosted manager with a WSL worker use its actual accessible skill directory via `--skill-root`, with user authorization for that location. WSL defaults alone do not install into Windows user skill directories.

Inspect the JSON result. If a dependency or release is unavailable, report it and preserve completed setup; do not pretend all integrations are ready or compile Rust as a fallback. Optional TRIZ setup uses `--with-triz` only when requested and requires access to its release repository. Saved tool state is part of the handoff. FMECA and CPM are not registered as MCP servers: the manager reaches them through `junior tools call`, which records every call as evidence. Files the companion installers create are recorded as local Git exclusions; if `companions.modifiedTracked` lists a tracked file (such as `AGENTS.md`), report it for the user to review.

After init, run `junior matrix init` to create the Crossmatrix `.crossmatrix/` store. Commit that directory with the project so the feature-to-code map travels with the code and is shared across handoffs.

Init writes configuration, an example task, and manager skills. Review these files with the user before committing; worktree delegation requires a clean source checkout, so commit, stash, or set aside pending work first, or pass `isolation: "none"` explicitly. Keep the target on the WSL/Linux filesystem rather than a Windows-mounted path such as `/mnt/c`, where file operations are slow; `junior doctor` warns when the checkout sits on such a mount. Each worktree run is retained under `.delivery/<id>/<run>/worktree` with its logs and result beside it; apply an accepted run with `junior apply <id>` (three-way, `--dry-run` to check first, refuses unsafe states) rather than copying files, then remove inactive ones with `junior prune [--older-than 24h] [--keep-last N] [--dry-run]`, which never forces removal and skips dirty, locked, foreign, or escaping paths. Do not automatically commit these files without authorization.

Shape a cpm plan into bounded handoffs with `junior plan check <plan.json>` (lints the plan and prints `{ ok, findings, cohorts }`) and `junior plan contracts <plan.json> --out <dir>` (writes one contract skeleton per agent deliverable). The skeletons omit `provider` and `model`, so the commodity roster and Jev routing choose the executor.

## Coding agents and IDEs

Use AGENTS.md at the project root as the shared Junior entry point. After init, add or update exactly one managed block using the idempotency rules below:

```markdown
<junior>
For bounded deliverables, read .agents/skills/junior/SKILL.md and its CLI path manifest. Delegate through Junior with explicit scope, acceptance criteria, checks, and a budget. Enable jev.mode: enforce when frontier suitability must gate execution. Review the compact receipt and independent checks; return frontier_required or uncertain decisions to the manager. Never accept worker output automatically.
</junior>
```

Codex, Cursor editor/CLI, and agents that support AGENTS.md can use this entry point. Confirm the actual client's instruction discovery rather than assuming every IDE reads it. Claude Code keeps its installed .claude skill; if a shared entry point is needed, add a tagged pointer in CLAUDE.md. For Gemini CLI, use GEMINI.md; for GitHub Copilot in VS Code, Visual Studio, or JetBrains, use the client's supported repository instruction mechanism (commonly .github/copilot-instructions.md). Copilot CLI also supports AGENTS.md. For Windsurf, Cline, Roo Code, Aider, and other clients, consult that client's current rules/context mechanism and point it to AGENTS.md and the installed skill. Aider may need the file explicitly supplied as read-only context.

Keep any Markdown adapter minimal, inside one Junior block: “Read AGENTS.md and .agents/skills/junior/SKILL.md before delegating.” Do not duplicate the full workflow. Only configure the user's selected clients, preserve existing instructions, and verify the agent can read the skill and execute junior in the same runtime. An IDE alone does not supply terminal or provider access. Junior init installs skills; the setup agent performs the managed AGENTS.md/adapter step described here.

References: [Cursor CLI instructions](https://docs.cursor.com/en/cli/using), [Copilot CLI instructions](https://docs.github.com/en/copilot/how-tos/copilot-cli/customize-copilot/create-custom-agents-for-cli), [Gemini CLI context](https://geminicli.com/docs/cli/gemini-md/).

## Idempotent shared manager instructions

If you add Junior-specific instructions to `AGENTS.md`, `CLAUDE.md`, or another shared Markdown instruction file, place all of that content inside exactly one managed block:

```markdown
<junior>
Use the installed Junior skill to delegate one bounded deliverable. Review its receipt and independent checks before accepting the work.
</junior>
```

On first installation, append the block without replacing existing content. On reruns, replace the existing block in place rather than appending another. Preserve every byte outside the block. If the desired content already matches, leave the file unchanged. If tags are duplicated, nested, or unbalanced, stop and report the conflict instead of guessing or overwriting user instructions. Do not add Junior text outside the tags. Remove only the managed block when uninstalling an authorized integration.

Use these tags for additions to shared prose instruction files, not inside JSON configuration. Dedicated skill files keep their required skill frontmatter and directory structure. Junior init currently installs separate skill files; it does not itself add AGENTS.md or CLAUDE.md blocks. Do not create extra instruction files merely to duplicate the skill.

## Keep the tools current

`junior doctor --check-updates` compares the managed binaries with their latest GitHub releases and the companions with npm `latest` without downloading anything. It also lists newer commodity models. When it reports `updates`, run `junior update`: it updates Junior itself from npm first, then adopts newer managed tools, companions and unmodified skills. Model adoption follows `models.autoUpgrade` — when true, `junior update` applies newer same-lineage commodity models; otherwise it reports them without applying. A newer release becomes the default only at price parity (`models.priceTolerance`, default 1.25x, measured on the cheapest tool-capable endpoint). Use `junior model status`, `junior model list` and `junior model upgrade` to inspect and plan roster changes explicitly.

## 4. Provider authentication — human step

Run `junior doctor`. This step is human-only: `pi` `/login` and `/model` are interactive, so stop and ask the human to run them in the same runtime — do not try to authenticate on their behalf. Alternatively, the human can run `junior auth set openrouter --verify`, which reads the key from stdin and verifies it online; never ask for the key in chat, pass it as a command argument, or log credentials. Authenticate before refreshing the catalog: run `pi update --models` only after `/login`, because the model catalog stays empty until a credential is present. Never change a working provider configuration without authorization. Authentication is required before live execution, but not for a mock handoff.

The current executor is a commodity model. Junior never runs on a frontier model: a frontier or unknown provider/model is refused before any spend, and Jev is a classifier only, never the executor. The default is the cheapest DeepSeek, `deepseek/deepseek-v4.1-flash` (OpenRouter) (the `general` profile). Junior never moves to another model without human approval per run, per plan, or per project, and it gives a rationale: the Jev pick, its confidence, the matched strengths, and the price change against the default. Jev routing and a contract-named model never count as consent. Approve a run with `junior handoff <task> --approve-model <key>`, a plan with `approvedProfiles`, or the project with `junior model approve <key>`; revoke with `junior model revoke <key>`. Inspect the roster with `junior model status`.

## 5. Verify and hand back

Run `junior doctor` again and report execution readiness separately from optional integration readiness. Inspect the generated example contract before using it. For an offline smoke check, validate it and use the mock flag:

```bash
junior validate /absolute/project/tasks/example-task.json
junior handoff /absolute/project/tasks/example-task.json --mock
junior model status
```

Replace the example path with the actual project path. `junior model status` is read-only and reports the pinned model, its commodity verdict, routing and the roster. Report the executor and any pending model upgrade in the setup receipt. Do not dispatch a paid live task until the user authorizes it. Before real work, specify one deliverable, scope, acceptance criteria, independent checks, and a budget; a cpm plan can be shaped with `junior plan check`. Follow the installed skill's review rules: ready_for_review means manager review is required, not automatic acceptance.

Finish with a compact setup receipt: CLI version and location, project, installed skill paths, doctor findings, mock outcome if run, and anything requiring the user's attention. Do not stop after installing the CLI without checking the project setup and readiness.

## Frontier suitability gate

Set jev.mode to enforce in a deliverable contract to require classification before execution. A frontier_required, unclear, or uncertain result returns needs_review without starting the commodity worker. Inspect the compact receipt attention decision, reason, and probability; the manager clarifies, re-scopes, or takes over. Shadow mode is advisory and the default is off. Junior does not automatically invoke a frontier model.
