lean-and-mean · Guide

In depth

How the session handoff, the hook and the cost model work, and what the bundled extras do.

On this page: /endsession · The session-start hook · Why sessions should be short · Advisor and effort · dashboard-builder · explainer · Session band mod · typesafe-ai · Manual install

/endsession

The last message of a session. It turns this session's mistakes and failed approaches into Rules, rewrites ## Next and ## Todo, flags a full review for the next session if the project's layout or commands changed, then commits and pushes, opening a PR when the branch is a feature branch or the default branch is protected. It never force-pushes. Then it prints a short summary of what was done, what was updated and what comes next. Then it stops.

The session-start hook

One short POSIX shell script runs when a session starts. Once the ## Operating Mode block is in AGENTS.md, the mode needs no hook, flag or per-turn reminder: the host loads the file natively. The hook only covers the gaps:

ConditionWhat it prints
Block missing from AGENTS.mdThe block itself, so the mode is active anyway, plus a nudge to run /lean-and-mean
Block differs from the plugin's current copy (plugin updated)An instruction to run the full /lean-and-mean pass before your first task
AGENTS.md over 250 lines
/endsession left the review flag
Claude Code: CLAUDE.md is anything but @AGENTS.md
Claude Code: no advisorModel in any settings fileA one-line suggestion to set an advisor
Anything elseNothing

The CLAUDE.md check is also the upgrade path: a 3.x project kept its block in CLAUDE.md, so the pass merges that file into AGENTS.md and writes the one-line stub. Anything added to CLAUDE.md later moves over the same way. A CLAUDE.local.md keeps working alongside the stub.

Why sessions should be short

Every tool call resends the whole context as cache reads, so cost scales with requests × context size. Mean cost per request by context size:

ContextUnder 50K50–100K100–200K200–400KOver 400K
Per request$0.07$0.08$0.12$0.19$0.33

A request over 400K costs four times one under 100K. Restarting at task boundaries keeps requests in the cheap columns; a fresh session's first request costs a median $0.27.

Walking away is the expensive part. The cache lasts an hour. After that, the next turn re-writes the whole context at 2× input. Across 29 measured cold resumes the median cost $1.21, 4.5× a fresh start, and the worst, at 455K, cost $8.79. Compaction doesn't help: it fires late, after the large-context turns are paid for, and its summary is lossy. /endsession writes a deliberate handoff for a median $0.27 (max $2.19), so end at task boundaries and before any break.

Unrequested code is paid three times: as output (a 150-line speculative helper with tests is ~3K tokens, ~$0.15 on Fable), as context on every later turn (~$0.15 more over 200 requests), and in review and maintenance, which is the real cost.

Concise prose is for readability, not cost. Output, code and thinking included, is 18% of measured spend; cache reads are 56% and cache writes 26%. Trimming chat prose saves a few percent.

Measured from the maintainer's session logs: 63 Claude Code sessions, 5,197 requests, 2026-09-03 to 2026-10-03, mostly Opus 5, Opus 5.5 and Fable 5.1, priced at API list rates (output $50 / $20 per million on Fable 5.1 / Opus 5.5, cache reads $0.25 / $0.20, 1-hour cache writes at 2× input). The code-cost example above is modeled. Most requests ran on Opus 5, whose cache reads cost $0.50; on Opus 5.5 at $0.20 the absolute figures are lower. Advisor calls may be undercounted. Not a subscription billing model or a Codex pricing claim; actual costs depend on host, model, caching and context policy.

Advisor and effort

Claude Code can pair the main model with an advisor: a stronger reviewer it consults before committing to a plan, when the same error keeps coming back, and before declaring a task done. Set it once:

/advisor fable

(or opus; an Opus 5.5 main model accepts only those two). Each advisor call re-reads the full transcript uncached, and subagents inherit it, so its cost grows with session length. That is another reason to /endsession at task boundaries.

dashboard-builder

A subagent, Claude Code only, that builds .dashboard/index.html: one self-contained page you open by double-click to follow a long task without reading the transcript. Its description tells Claude to use it before any task over about five steps or 30 minutes; if Claude doesn't, call it with @agent-lean-and-mean:dashboard-builder.

explainer

A subagent, Claude Code only, that writes .pages/<slug>.html: one self-contained page for an answer too long or too structural for the terminal. The Operating Mode block tells Claude to explain in the cheapest form that works: a sentence, then a diagram, then a page. Call it directly with @agent-lean-and-mean:explainer.

Session band mod

A mod is a plugin module of function hooks that Claude Code loads and runs inside the session. This one is hooks/register.tsx (helpers in hooks/judge.ts), listed under modules in hooks/hooks.json. It is the only plugin code that runs on every turn. Claude Code only, on by default; turn it off in /config under Session band. Codex ignores it.

tasks 2/3   [ hide tasks ]  [ end session ]
  ✓ Fix the login redirect
  ✓ Add a test for it
  ☐ Update the changelog

It hooks session start and end, prompt submit, turn start and completion, command runs, and the area above the prompt. Nothing is written to your project; its state lives in Claude Code's plugin storage.

Status line extra. extras/statusline.sh draws dir, branch, model, a ctx … exp. segment from prompt_cache.expires_at, and the 5-hour limit. Plugins can't set statusLine: copy the script to ~/.claude/statusline.sh and add "statusLine": { "type": "command", "command": "bash ~/.claude/statusline.sh", "refreshInterval": 60 } to ~/.claude/settings.json. Needs jq.

typesafe-ai

A bundled copy of TypeSafe AI's skill for building app features on Jev, their System One model. Jev doesn't generate text: it takes natural language plus application state and returns typed answers and probabilities, such as yes/no or pick-one, that ordinary code can combine. It fits routing, ranking, extraction, verification, or anywhere a prompt-and-parse step could become a structured decision.

The skill reads TypeSafe's live docs and cookbooks as part of each task. The only change from the original is the endpoint: Jev is called through OpenRouter.

export OPENROUTER_JEV_API_KEY=...

Calls go to POST https://openrouter.ai/api/alpha/decisions with model ~typesafe/jev-latest; request and response match TypeSafe's API.

Without that key, Jev isn't used; there is no fallback to TypeSafe's own endpoint or TYPESAFE_API_KEY.

Disabled for now: the skill is out of the Operating Mode block and the assistant won't load it on its own. Copyright and credit belong to TypeSafe AI (MIT).

Manual install

Claude Code: copy skills/lean-and-mean/ and skills/endsession/ into ~/.claude/skills/, copy hooks/session-start.sh somewhere, and add the SessionStart entry from hooks/hooks.json to ~/.claude/settings.json, pointing at that script. Manual installs get the bare /endsession and /lean-and-mean.

Codex without plugin support: copy both skill folders into ~/.agents/skills/ and run $lean-and-mean yourself. The mode persists, but there is no automatic session-start review. Remove any AGENTS.override.md: Codex reads it instead of AGENTS.md. The hook needs a POSIX shell (macOS, Linux or WSL).