/agent-rsi:agent-rsifrom agent-rsi
Runs a retrospective and self-improvement loop after tasks that changed code, docs, config, PRs, or deployments, and after failures or user corrections. Records lessons, generates regression tests, ADRs, and postmortems, and promotes repeated patterns into AGENTS.md rules.
Ships in agent-rsi. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them; scripts run unread.
Goal: each mistake happens at most twice. The first time it is recorded. The second time it becomes a rule that every agent loads.
Keep it small. A retrospective that takes longer than the task is waste. For a clean, routine task, step 1 is enough.
The workspace is the directory the session started in: the one holding the top-level AGENTS.md for this work. Its agent-docs/ directory holds the ledger and shared lessons. The machine directory ~/agent-docs/ has the same layout and holds what every project on this host needs. If either directory does not exist when you need it, create it from templates/agent-docs-README.md and templates/ledger.md.
Store each lesson where every session that needs it will read it:
| Lesson about | Location |
|---|---|
| One repository | That repository's docs or AGENTS.md |
| One workspace (several repos) | <workspace>/agent-docs/lessons/<topic>.md |
| Tools on this machine, a cluster or third-party service, or the user's preferences | ~/agent-docs/lessons/<topic>.md, with a pointer in the global rules |
~/agent-docs/.| Artifact | Location | When |
|---|---|---|
| Regression unit / integration test | The affected repo, next to the code, in the same PR as the fix | Every bug that reached a commit, review, CI, or production |
| ADR | <repo>/docs/adr/NNNN-<slug>.md | A design choice that someone would later question or undo |
| Postmortem | <repo>/docs/postmortems/YYYY-MM-DD-<slug>.md if repo-specific; agent-docs/postmortems/ if cross-repo or about agent process | Failure that reached CI, a reviewer, the user, or production; or cost more than ~30 min |
| Shared lesson | See "Lesson scope" | Knowledge another agent in another repo would also need |
| Counter | agent-docs/ledger.md of the same scope as the lesson | Every failure, and every proven method |
| Rule | See "Rule scope" below | Ledger count reaches 2, or a method proved itself twice |
Templates are in templates/ next to this file. scripts/session-stats.py measures where session time went (see step 1). Repo files (tests, ADRs, repo postmortems, repo AGENTS.md) go through the task's branch and a PR, never a repo's main checkout.
| Scope | File | Example |
|---|---|---|
| One repository | <repo>/AGENTS.md | "Read the drizzle migration before editing an Ent schema." |
| One workspace (several repos) | Workspace AGENTS.md | "Deploy backend before the dashboard change that depends on it." |
| Every project you work on | Global rules: ~/AGENTS.md, loaded through ~/.claude/CLAUDE.md (@~/AGENTS.md) and ~/.codex/AGENTS.md | "Work in a worktree; never edit the main checkout." |
Start at the narrowest scope. Move a rule up one scope when the same lesson shows up in a second repository or workspace.
Put rules in these AGENTS.md files, never in a skill. A skill loads only when its description matches the task, but a rule must be in context before the mistake happens. A rule can point to a lesson file for the details.
First measure the session. Do not rely on memory for what was slow:
python3 -I <this skill>/scripts/session-stats.py --transcript <current transcript>
Claude Code transcripts are ~/.claude/projects/<cwd with / as ->/<session id>.jsonl. Codex transcripts are under ~/.codex/sessions/. With no --transcript, the script reads every transcript; add --since 1d to limit it.
The script pairs each tool call with its result and prints findings: command families that take a large share of time, calls that are never fast, slow calls, repeated commands, failures, polling loops, and denied calls. Treat each finding as a candidate slow or mistake row for step 2. A finding is evidence, not a root cause. Read the command and its output before you name a cause.
Limits of the numbers:
Then answer in two or three lines, for yourself:
If nothing went wrong and you learned nothing new, stop here.
Re-read agent-docs/ledger.md right before you edit it; other sessions write to it too. Look for an existing row with the same root cause, even if the symptom differs.
Count, update Last seen, append the new evidence.Count 1 and the next free ID (L-NNNN).Log a time sink found in step 1 with type slow, for example "each remote exec pays 10 s of connection setup". Put the measured numbers in Evidence.
Also log successes that saved real time ("ran the tests locally before pushing and skipped a CI round trip") with type method. Methods are promoted the same way as mistakes.
Then score the rules that shaped this task. Only score rules you acted on; do not audit every loaded rule.
Helped and set Last applied to today.Misled, put what was wrong in Evidence, and fix or retire the rule now (see "Retire stale rules").method with Count 2 and Status promoted → <file>#<section>, then score it.Produce only what the failure warrants:
agent-docs/lessons/ and list that file in agent-docs/README.md. Extend an existing topic file before creating a new one.Promote when either holds:
mistake or slow row reaches Count ≥ 2.method row has saved time at least twice, or the user stated it as a standing rule.How to write the rule:
make test before pushing", not "Be careful with tests".(verified YYYY-MM-DD). When the fact has a known end, add the condition: (verified 2026-03-02; until tool > 1.4.0). A session that observes the fact again updates the date.Status to promoted → <file>#<section>.Rule files load into every session, so keep each one under about 150 lines. Before adding to a file at that size, run "Retire stale rules" on it and merge overlapping rules.
A rule that is no longer true costs more than a missing rule: agents follow a rule file even when the code in front of them disagrees. Retire a rule when any of these holds:
| Signal | Action |
|---|---|
Misled ≥ 2, or Misled ≥ 1 and Misled ≥ Helped | Rewrite the rule so it would not have misled, or retire it |
Its until condition is met (the release shipped, the issue closed, the host is gone) | Retire it, or reduce it to what is still true |
| A file, command, flag, skill, or host it names no longer exists | Fix the reference, or retire it if its subject is gone |
An environment fact is more than 30 days past verified | Check it with one command; update the date or the fact |
| A newer rule or user statement contradicts it | Keep the newer one; retire the older |
No Last applied or Last seen in the last 60 days | Propose moving it to a lesson file; it stays findable but stops loading in every session |
Status becomes retired YYYY-MM-DD: <reason>, superseded → L-NNNN, or demoted → <lesson file>. A later session that meets the same problem finds the history there.agent-docs/README.md.A cost that is small in each session can be large in total. Run a sweep on a schedule, for example weekly, or when the user asks:
session-stats.py --since 7d. Add --json to read the numbers in a script.Count once per sweep, not once per session. Otherwise add a row.Status to proposed → <file>#<section>. Put the change in a pull request where the rule file is in a repository; otherwise list it for the user.until condition, every verified date older than 30 days, and the names each rule references. Verify each signal with one command or read. Propose each retirement, rewrite, or move the same way as a new rule, with its evidence, and set the row's Status to proposed retire → <reason>. Do not edit the rule file.End your final message with one short line, for example:
RSI: L-0004 count 2 → promoted to backend/AGENTS.md#Shared Schema; regression test in internal/admin/user_test.go.
If nothing was recorded, say nothing about RSI.
scripts/session-stats.py (opens in a new tab)scripts/test-session-stats.py (opens in a new tab)templates/adr.md (opens in a new tab)templates/agent-docs-README.md (opens in a new tab)templates/ledger.md (opens in a new tab)templates/lesson.md (opens in a new tab)templates/postmortem.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
npx claudepluginhub luoling8192/skills --plugin agent-rsiOther plugins' skills for the same job