agentleFS
serionistserionist/claude-session-restore/AGENTS.md

claude-session-restore

AGENTS.md0 starsChanged 16 days agoMITView on GitHub

The rules for anyone who changes this repo, person or agent. Claude Code reads this file through .claude/CLAUDE.md, Codex reads it directly; the gate caps it at 150 lines. What the plugin does for those who use it is in README.md. session-restore, a Claude Code plugin (a mod: a hooks module, no MCP server, no skills) that reopens the sessions a crash, a restart or a closed terminal cut off. The repo is its own marketplace. - The plugin (plugin/):…

  • Where files are headingNew AGENTS.md files have more rules about keeping secrets out of the code, and fewer about code style.

    Of the AGENTS.md files we read, the 31,700 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.

  • In this repository6 other files it gives its agents.

The file

We split this AGENTS.md into the rules it gives an agent

5 rules. About 2 are common, 1 is distinctive, and 2 are very specific to this project.

  • ≈2

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 2

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    No tool attribution anywhere: no AI co-author trailers, no "Generated with" lines, no session links, in commits, PR titles or PR bodies.

    line 85
  2. Common:

    Check out, build or run code from outside the maintainers (a contributor's PR or branch) on your machine: read it, and let CI run it.

    line 135
  3. Very specific:

    Put a record's text (a folder, a flag, a path) into a script or a command line a shell parses: it travels as data (psString, crtQuote, …

    line 137
  4. Distinctive:

    Add tool attribution: commits, PR titles, PR bodies.

    line 139
  5. Common:

    Commit secrets, or a real person's session record: tests use invented ones.

    line 140

≈ “Common” is an estimate: at least 1 in 5 of the 40,246 AGENTS.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
AGENTS.md

claude-session-restore

The rules for anyone who changes this repo, person or agent. Claude Code reads this file through .claude/CLAUDE.md, Codex reads it directly; the gate caps it at 150 lines. What the plugin does for those who use it is in README.md.

What this is

session-restore, a Claude Code plugin (a mod: a hooks module, no MCP server, no skills) that reopens the sessions a crash, a restart or a closed terminal cut off. The repo is its own marketplace.

  • The plugin (plugin/): hooks/register.tsx hooks the session's life and draws the band and the pane; hooks/lib.ts holds the pure logic (which sessions count as cut off, the launch flags, the command lines); types/index.d.ts declares the record and the plugin's state.
  • It runs inside Claude Code, in an environment with no DOM and no Node: everything outside reaches it through $ ($.fs, $.process, $.session, $.ui). The API is early access and changes between Claude Code releases.
  • On every system: Windows Terminal (or console windows) on Windows; Terminal, iTerm2 or tmux on macOS; tmux or the desktop's terminal on Linux; the commands printed where no window can open. docs/design.md says how each part works.

Where things are

PathWhat
plugin/the plugin: .claude-plugin/plugin.json (name, version, the shell and terminal options), hooks/ (hooks.json, register.tsx, lib.ts, and their tests register.test.tsx, lib.test.ts), types/index.d.ts, tsconfig.json, README.md
.claude-plugin/marketplace.jsonthe marketplace: one plugin, source ./plugin
docs/design.md (how it works), releasing.md, testing-by-hand.md (a real window, on each system); plans/, reviews/: dated records, never current truth
tools/gate.ts (the gate), hooks.ts (behind .githooks/), setup.ts (once per clone; link for skills), gate.test.ts, launcher.test.ts (the restore scripts run for real: PowerShell on Windows, sh on macOS and Linux), try-restore.sh (the by-hand test's setup and check); Node's standard library only
.githooks/commit-msg refuses attribution, pre-push runs gate quick on what the push sends, post-checkout and post-merge name changed AI setup files
.claude/CLAUDE.md (imports this file), settings.json (no attribution; allows read-only git and gh, plus the repo's own checks), skills/ (below)
.agents/skills/links to .claude/skills/<name> for Codex, written into git's index by node tools/setup.ts link
.github/CI, CodeQL, the PR text check, the release, Dependabot, issue forms, the PR template, CODEOWNERS
AGENTS.md, REVIEW.mdthis file; what a review finding is, and the questions every review answers
.mcp.jsonContext7 over HTTP; .claude/settings.local.json.example turns it on
package.json, package-lock.json, .npmrc, .nvmrcthe dev tools, pinned exactly (Claude Code, Biome, TypeScript); no install scripts; Node 24
biome.jsonc, tsconfig.jsonlint and format for everything; the tools' types (the plugin's are plugin/tsconfig.json)
.gitleaks.tomlthe secret scan: gitleaks' own rules, and any exception with its reason
.editorconfig, .gitattributes, .gitignoreUTF-8 and LF everywhere; what git ignores
README.md, CHANGELOG.md, CONTRIBUTING.md, SECURITY.md, LICENSEfor users; what changed, under Unreleased; a first contribution's short path; how to report a vulnerability; MIT

A new top-level file or folder adds its row in the same change.

Build and test

You need Node 24, git, and gitleaks for the secret scan. Claude Code itself comes pinned from npm ci.

WhatCommand
once per clonenpm ci, then node tools/setup.ts (hooks, skill links)
the plugin's testsnpm run claude -- plugin test plugin (the pinned Claude Code)
the gatenode tools/gate.ts quick (pins, Biome, types, the plugin validated, version, AGENTS.md, skills, hooks, attribution, secrets); full adds the plugin's tests and the tools' tests
formatnpx biome check --write ., then review the diff
run itclaude --plugin-dir plugin: the mod from this clone, reloaded on each save (README, Developing)
  • The plugin's types come from Claude Code: it writes them to plugin/.claude-plugin/types/ when a session loads the mod. No command writes them, so CI can't check them: gate quick checks them where they are, and skips with the reason where they are not. Load the mod once before a PR that changes plugin/.
  • Tests run in the engine's sandbox: $.fs, $.process and the clock are mocks, so no test starts a terminal or a PowerShell. What only a real session shows (a restore, the band) is checked by hand, and the PR says how.

How a change lands

  1. An issue for anything beyond a typo.
  2. A plan in docs/plans/ for non-trivial work (docs/plans/README.md says when), reviewed with review-plan until approved, then approved by the maintainer.
  3. A branch <issue>-<slug> from origin/main, the plan its first commit.
  4. The code, with its tests and docs in the same change.
  5. finish-work: node tools/gate.ts full, review-code until clean, a PR.
  6. The maintainer, @serionist, squash-merges; merging is the approval. main takes PRs only.

The skills in .claude/skills/ run this loop: start-work (1 to 3), review-plan, review-code, finish-work (5), and write-skill for writing or fixing a skill.

Writing

  • A lead line, then a table or short bullets. Conclusion first; name the file, the command, the number.
  • Plain words. No "ensure", "robust", "comprehensive", "leverage" or "seamless"; spaced hyphens, never em dashes; British spelling (behaviour, licence).
  • A comment says why, not what the next line does, and says it in its own words, not only as a plan or review id.
  • Docs move in the same change: README.md and plugin/README.md for what users see, docs/design.md for how it works, CHANGELOG.md when users notice, this file for a changed path, command or rule.

Commits and PRs

  • A plain imperative subject that says what changed; a body that says why, ending Refs #<n> or Closes #<n>.
  • PRs are squash-merged: the PR title becomes the subject on main, its description the body.
  • No tool attribution anywhere: no AI co-author trailers, no "Generated with" lines, no session links, in commits, PR titles or PR bodies. commit-msg refuses them, the gate checks every message, and CI checks the PR's text.
  • Versions: users get a change only when plugin.json's version moves. A release PR sets it and dates the CHANGELOG section (docs/releasing.md); no other PR touches it.

One-way doors

Users depend on these. Change one only in a PR that names it in its title, after the maintainer agrees in its issue; in 0.x a minor may break one, under CHANGELOG's Breaking.

  • the plugin's and the marketplace's name, session-restore;
  • the /restore command and its arguments (all, numbers, an id prefix, forget);
  • the shell and terminal options, their names and their values;
  • the record folder, <config>/session-restore/sessions/, and the record's fields: a new version reads the records an older one wrote, so a field is added, never renamed or retyped.

Traps

What this code already paid for; docs/design.md has the detail.

What brokeWhereThe guard
Windows reuses pids, so a new process kept a dead session looking aliveisInterruptedThe pid and its start time must both match
Windows Terminal gives new tabs the caller's environment; a claude that sees CLAUDE_CODE_* runs as a child session, which keeps no transcript to resumelaunchScriptSESSION_ENV is cleared first
wt splits its own arguments on ;wtLines\; keeps one
PowerShell takes U+2018 to U+201B for quotes, so doubling ' let a folder named x’$(calc)’ run codepsStringRecord text reaches PowerShell only as base64
cmd reads &, % and ^ in a folder or a flagtabArgv, launchScriptNo record text reaches cmd; console windows start through Start-Process
Start-Process reads a working directory as a wildcard, so [old] api matched nothinglaunchScriptWildcardPattern.Escape
A bare claude in PowerShell is npm's claude.ps1, which a Restricted policy refusesrunArgvScriptThe program on PATH (-CommandType Application), with no flags
Windows PowerShell writes to a pipe in the console's code page, garbling C:\Users\SómarunPowerShellUTF-8 output first
A shell cd in a tool moved cwd(), and the restore opened a folder --resume can't find the session fromsyncThe record keeps root()
The process lookup failed at startup, while MCP servers spawnbeatTried again at heartbeats 1, 3, 7 and 15, then no more
The band acted on the list as last scanned, and reopened a session already restored or resumedstillCutOffRestore and Dismiss scan again, one at a time
tmux reads new-window -c <folder> as a format, where #(...) runs a commandterminalArgvNo terminal gets the folder; the script cds
Most Linux terminals run until their window closes, Ubuntu's x-terminal-emulator on purpose, and a call past 30 s is killed with the windowdetachedStarted apart with setsid -f
Linux derives ps's start time from the wall clock, which a laptop's wake can stepPROCESSES, LOOKUPThe boot id and the start tick, from /proc
A heartbeat's save landed after /exit closed the record, and the dead session was offeredsync, saveA count of ends; one write queue
A session with no prompt has no transcript, and --resume finds nothingsyncTracked from its first turn

Look up APIs before coding against them

The hooks API: plugin/.claude-plugin/types/claude-code/index.d.ts, written by the Claude Code that loaded the mod; grep it for the event or noun ('session.end', Pane: {). npm run claude -- plugin validate plugin lists what the module hooks and calls, and what the engine would refuse. Anything else (Windows Terminal, PowerShell, Node): Context7 (.mcp.json) or the vendor's docs, never memory.

Never

  • Push to main, or merge with a failing gate.
  • Weaken a test, a check, a hook or CI to make a change pass: no skip, no new ignore, no --no-verify.
  • Check out, build or run code from outside the maintainers (a contributor's PR or branch) on your machine: read it, and let CI run it. A hooks module runs in every Claude session, with every credential there.
  • Put a record's text (a folder, a flag, a path) into a script or a command line a shell parses: it travels as data (psString, crtQuote, posixQuote; docs/design.md).
  • Add tool attribution: commits, PR titles, PR bodies.
  • Commit secrets, or a real person's session record: tests use invented ones.
  • Change a one-way door without the maintainer's agreement.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.