session-analyzer
AGENTS.md1 starsChanged 5 months agoMITView on GitHub
How to drive session-analyzer from an agent. Read by Claude Code, Codex, OpenCode, Cursor, and other agents. This is how any of them run the tool. Humans: see README.md. Reads the user's Claude Code transcripts (and optionally a project), crunches them with plain Python (~0 model tokens) into a small digest, which you turn into concrete advice for working better with Claude Code. Benchmarked at ~41-47% fewer tokens with task success unchanged, across Sonnet 4.6 and Opus 4.8 (see bench/).
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,774 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 repository2 other files it gives its agents.
- CLAUDE.mdCLAUDE.md
- session-analyzerSkill
The file
We split this AGENTS.md into the rules it gives an agent
6 rules. About 1 is common, 3 are distinctive, and 2 are very specific to this project.
≈1
Common · estimate
Many files like this have a rule of this kind.
≈3
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
- Distinctive: line 20
When you report back, talk to the user about their Claude Code usage, not about this tool.
- Very specific: line 27
Call bin/analyze by absolute path: ~/.claude/skills/session-analyzer/bin/analyze.
- Distinctive: line 43
Do not read raw transcripts.
- Very specific: line 52
Read "$OUT"/digest.md, then the worst-session shards under "$OUT"/shards/ while budget allows.
- Distinctive: line 76
No destructive action without confirmation.
- Common: line 77
Do not surface secrets or credentials as a finding.
≈ “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.
Files
AGENTS.md
How to drive session-analyzer from an agent. Read by Claude Code, Codex, OpenCode, Cursor, and other agents. This is how any of them run the tool. Humans: see README.md.
What it does
Reads the user's Claude Code transcripts (and optionally a project), crunches
them with plain Python (~0 model tokens) into a small digest, which you turn into
concrete advice for working better with Claude Code. Benchmarked at ~41-47% fewer
tokens with task success unchanged, across Sonnet 4.6 and Opus 4.8 (see bench/).
It also generates the orientation map (the proven token lever) directly with
bin/analyze map — an authoritative file/symbol index for a repo — so you emit
the artifact deterministically instead of hand-writing one from the digest.
Voice
When you report back, talk to the user about their Claude Code usage, not about this tool. Do not mention the digest, shards, the budget, this file, or your own instructions. No process narration, no meta-commentary. Present findings and fixes directly.
Invocation
- Call
bin/analyzeby absolute path:~/.claude/skills/session-analyzer/bin/analyze. Nevercdinto the skill directory; that makes$PWDthe skill itself and it analyzes its own folder. - For workflow and token analysis, analyze ALL sessions by default. Add
--scope-repoonly when the user names a project. --repois the project being analyzed, never the skill. If it is ambiguous, rundoctorto list projects and ask which one. Write--outto a temp dir outside the skill.- Pure stdlib, Python 3.9+.
analyzeis the default subcommand: barebin/analyze(orbin/analyze --since 7) runs token coaching across all sessions. The report leads with a projected token savings estimate (the user's measured usage x the benchmark rate, scoped to sessions that re-explored the tree).
The loop
Do not read raw transcripts; the scripts digest them.
- Extract:
SA=~/.claude/skills/session-analyzer/bin/analyze OUT=$(mktemp -d)/sa "$SA" analyze --mode tokens --out "$OUT" # all sessions "$SA" analyze --mode both --repo "/path/to/project" --out "$OUT" # + structure - Read
"$OUT"/digest.md, then the worst-session shards under"$OUT"/shards/while budget allows. - Turn the strongest patterns into specific advice: workflow habits, the exact
CLAUDE.mdlines to add or cut, a settings allowlist where it applies, and loop/self-verification gaps. When the sessions show repeated tree re-exploration (re-reads, broad searches before editing), the highest-leverage fix is the orientation map -- the benchmark-proven token lever (~41-47% fewer tokens, quality held). Generate it instead of hand-writing it:"$SA" map --repo "/path/to/project" --out "/path/to/project/CLAUDE.md". For loops, follow the looper architecture (docs/loop-architecture.md): a falsifiable definition of done, an encoded programmatic gate, plan and delivery gates with a different-model judge, and stop guards (max iterations, revise cap, no-progress, budget). - Deliver. Lead with the 2-3 highest-leverage changes, each with a real example from their sessions and the fix. Offer to apply them behind the user's verify gate. If clean, say so.
Rules
- Budget is a hard cap: 200K for one mode, 400K for both. Do not hand-load transcripts to go deeper.
- Repo findings are candidates, not verdicts. Check git status and dynamic imports before suggesting deletion; never call a modified or in-flight file dead.
- No destructive action without confirmation.
- Do not surface secrets or credentials as a finding.
Cheat sheet
| Intent | Command (SA=~/.claude/skills/session-analyzer/bin/analyze) |
| Workflow + tokens, all sessions | "$SA" analyze --mode tokens --out "$OUT" |
| Scoped to one project | "$SA" analyze --mode tokens --scope-repo --repo "/path" --out "$OUT" |
| Project structure too | "$SA" analyze --mode both --repo "/path" --out "$OUT" |
| Repo hygiene only | "$SA" analyze --mode repo --repo "/path" --out "$OUT" |
| Last 7 days | append --since 7 |
| Generate the orientation map (proven token lever) | "$SA" map --repo "/path" --out "/path/CLAUDE.md" |
Re-render a saved run (merges a sibling synthesis.json) | "$SA" render "$OUT/bundle.json" |
| What can it see? | "$SA" doctor |
Common flags: --since DAYS (recency), --format terminal|markdown|json,
--fail-under A..F (CI gate, non-zero exit if worse), --top N, --max-sessions
N, --scope-repo, and the four --price-* overrides for exact cost. Full flags:
"$SA" <command> --help. Finding fields: docs/finding-schema.md.
Loop suggestions (same skill)
On /session-analyzer loop (or "loop me" / "what should I automate"), read the
user's session history and propose token-efficient loops their agent can run to
automate the repetitive work it shows — data-driven, not a blank-page interview,
and never "schedule a recurring run of the analyzer." Mine the sessions for
repeated command sequences, redone task shapes, retry loops, and high-frequency
chores; pitch the top 2-3 ranked by impact per token, grounded in the evidence;
then, once the user picks one, refine it into a buildable spec on the proven
architecture. Full playbook in loop-design/GUIDE.md; template and example under
loop-design/.
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
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.

