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.
- Hard stop. Anything you pass that looks like a task is written under
## Next, not done. The model never invokes it on its own. - One question round. It asks once, up front, about at most three deletes that would remove a Rule or P1 Todo it can't judge. Clearly stale entries are dropped without asking. It never asks whether to commit or push: running it is the yes.
- One memory. In Claude Code, project
feedbackandprojectentries from built-in auto memory are moved into Rules, Next or Todo, then deleted, so the committedAGENTS.mdis the single place lessons live.userandreferencememories are left alone. - Light on purpose. Context is largest at the end of a session, so the full
AGENTS.mdreview waits for the next session's fresh, cheap context./endsessiononly leaves a<!-- lean-and-mean: review -->flag. - Definition of done.
AGENTS.mdhas a## Donesection listing what finished means for this project, with exact commands: say, merge the PR withgh pr merge --squash --delete-branch, thenmake deploy-staging. It defaults to committed and pushed. When the session's work is complete (what you asked is finished, the project's tests pass, no open question),/endsessionruns those steps in order after pushing, then deletes local branches already merged into the default branch withgit branch -d. Otherwise, or when a step fails,## Nextopens withNot done: <what remains> — <why>, so the next session picks it up. It only runs commands written in## Doneor## Commands, never a deploy it guessed. The session band's timed auto end never ships. - Safe push. Files that look like secrets (
.env, keys, credentials) are never staged; they are named in the summary. A push behind the remote stops without rebasing. Any other push failure gets one attempt, thenUnpushed: <branch> — <reason>becomes the first line of## Next.
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:
| Condition | What it prints |
|---|---|
Block missing from AGENTS.md | The 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 file | A one-line suggestion to set an advisor |
| Anything else | Nothing |
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:
| Context | Under 50K | 50–100K | 100–200K | 200–400K | Over 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.
- Main session on high effort:
"effortLevel": "high"in~/.claude/settings.json. - Routine subagent work on Sonnet at medium effort:
model: sonnet,effort: medium.CLAUDE_CODE_EFFORT_LEVELoverrides subagent effort. - Turning the advisor off:
CLAUDE_CODE_DISABLE_ADVISOR_TOOLorDISABLE_TELEMETRY. OnlyCLAUDE_CODE_DISABLE_ADVISOR_TOOLalso silences the hook's suggestion.
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.
- Style, asked once. On first use the agent replies
STYLE?; Claude asks you for dark or light, dense or airy, and one accent colour. The agent saves the answer in its user memory and reuses it in every project. - Panels fit the task. Tasks with text status (todo, doing, done, blocked), open questions, deliverables with paths, and anything stuck. Questions and stuck items go on top when present; empty panels are dropped; the plan can imply extra ones.
- Claude keeps it current. After every step Claude edits the page's
dashboard-dataJSON block, never the markup. A decision it needs from you goes into questions with its default, and it carries on with that default rather than waiting. - Honest times. The page refreshes every 10 seconds, shows each time with its age ("4 min ago"), and marks itself stale when nothing has updated for 10 minutes. Timestamps come from the shell clock, never invented.
- Contained. No network requests. It writes
.dashboard/.gitignoreso the page is never committed, and the agent reads and writes nothing outside.dashboard/and its memory. It has no shell access.
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.
- Answer first. A short summary on top, then sections. Prose follows about 80% of ASD-STE100: one idea per sentence, 20 words at most, active voice, one term per thing.
- Diagrams replace paragraphs. Flows, structures and comparisons are inline SVG with a text label. Tables carry options and trade-offs.
- Style, asked once. The same
STYLE?round trip as dashboard-builder, saved in its own user memory; it reuses a style already given to dashboard-builder, so you answer once. - Contained. No network requests; it can read the project but writes only
.pages/, which it gitignores. It states only facts it was given or read, with paths. It has no shell access.
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.
- Auto end. The band tracks the 1-hour prompt cache, restarted by every main-loop request. With 5 minutes left after you have worked since the last
/endsession, it runs/endsessionitself (commit and push included) so Rules and Next are written before the cache goes cold and the next turn re-reads the whole context at full price. The countdown itself is in the status line extra below. - Task checklist. After each answered turn, Haiku (low effort, 8-second cap) adds the tasks you asked for and ticks the ones the reply shows finished. A malformed reply keeps the old list. The hide tasks button folds the list to its
tasks 2/3count. - End session button. Runs
/lean-and-mean:endsession. If the command can't run, it fills the prompt with it instead. - Reset.
/clearempties the checklist and the cache timer. Auto end fires once per stretch of work: running/endsession, by hand or automatically, disarms it until your next real prompt. - Nudge. When every task is done you get a toast, the End session button turns primary, and your next prompt tells Claude to suggest
/endsessionbefore new work, once per finished list.
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).