agentleFS
kelesmertkelesmert/turnlens/AGENTS.md

turnlens

AGENTS.md4 starsChanged 4 months agoMITView on GitHub

Per-turn token and cost monitoring for AI coding agents. It answers one question that agent session files do not answer directly: what did this single prompt and its response cost? TypeScript, ESM, zero runtime dependencies. This file holds what is worth knowing in every task; everything else is routed to below. lint runs itself: a Stop hook in .claude/settings.json blocks the end of any turn that wrote a .ts file and left a lint error. The user-facing surface is turnlens…

  • Installs packages
  • 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 35,117 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 repository4 other files it gives its agents.

The file

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

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

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈4

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

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

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Never write a claim about this code from memory: Not a return type, not a column count, not what a test file covers, not a line number.

    line 37
  2. Distinctive:

    Before a factual sentence about the codebase, run the read.

    line 58
  3. Distinctive:

    Before an expected output, derive it from the decision it belongs to, or run the command and paste what came back.

    line 59
  4. Distinctive:

    When a document is finished, sweep it as a cold reader would: every path, symbol, line number and figure resolved against the repository, …

    line 61
  5. Very specific:

    The home directory is resolved by core/home.ts: Do not call os.homedir() anywhere else.

    line 68

≈ “Common” is an estimate: at least 1 in 5 of the 45,344 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

TurnLens

Per-turn token and cost monitoring for AI coding agents. It answers one question that agent session files do not answer directly: what did this single prompt and its response cost?

TypeScript, ESM, zero runtime dependencies. This file holds what is worth knowing in every task; everything else is routed to below.

Commands

npm test                  vitest
npm run typecheck         includes test/
npm run lint              eslint, type-aware, src and test
npm run check             the three above, in order
npm run build             tsc, cleans dist/ first
npm run pricing:snapshot  regenerates src/pricing/snapshot.generated.ts
npm run verify:costs      cross-checks pricing against ccusage

lint runs itself: a Stop hook in .claude/settings.json blocks the end of any turn that wrote a .ts file and left a lint error.

The user-facing surface is turnlens --help. It is not copied here, because a copy is right until the next flag is added.

Skills

  • live-verification: checking TurnLens against live agent data, or taking any figure that will be treated as evidence.
  • design-doc: designing work that this session will also implement.
  • typescript-best-practices: writing, reviewing or refactoring .ts.

Open the file

Never write a claim about this code from memory. Not a return type, not a column count, not what a test file covers, not a line number. Open it. This costs seconds and the alternative has already cost a working day.

Measured on one design document, 11 August 2026: roughly half its defects were sentences written without opening the source. formatCostUsd was described as producing a number when it returns a toFixed(6) string. The CSV was called 24 columns when CSV_HEADER held 23 that day, which is the sort of figure that rots: it is 24 now, and the point is that neither number was ever counted. test/history.test.ts was named as covering readRecordedKeys on the strength of its filename alone, when it tests formatHistoryBlock and never opens a CSV.

A green test run is not evidence that a document is right. The worst of those defects put a new CSV column mid-schema instead of last, which would have re-mapped every existing row's duration_ms into it. Nothing would have failed: readRecordedKeys reads only turn_id, status and timestamp, all of them before the insertion point. The whole suite would have passed while every user's spreadsheet read a duration as a cost breakdown.

Three habits follow, and they apply to plans and documents as much as to code.

  • Before a factual sentence about the codebase, run the read.
  • Before an expected output, derive it from the decision it belongs to, or run the command and paste what came back.
  • When a document is finished, sweep it as a cold reader would: every path, symbol, line number and figure resolved against the repository, and every section checked against the ones it could contradict. Do this before handing it to a reviewer, not after.

Always

  • The home directory is resolved by core/home.ts. Do not call os.homedir() anywhere else. Two modules resolving it separately is two homes in one program.
  • An unpriced turn is empty, never 0. cost_status says why. A zero joins a spreadsheet sum and cannot be told from a genuinely free turn.
  • A closed turn is never repriced. pricing_version is a column for this reason; the rate that paid for a row travels on that row.
  • A report dates a turn by startedAt, its prompt; everything else uses at, its close. The CSV, the live table and lastActivity answer "when did this finish". A report answers "what did I spend that day", and under the closing timestamp that day depended on how long the agent thought. at is the fallback when no start was seen. #resetTurnState must keep clearing #startedAt: model deliberately persists across a boundary and a start must not.
  • Nothing is fetched while a session is being watched, or while a report is being built. Pricing resolves once, before either loop, and lookup is synchronous. Adding an await to that path breaks a guarantee no test covers, and a report replays every transcript on the machine through it.
  • The update check shares that one moment and adds no other. It is issued with Promise.all beside the pricing request in cli.ts, so it costs the slower of the two rather than the sum. It must never become a background task: update-notifier spawns an unref'ed child that outlives the process, which is precisely the fetch-while-watching this codebase forbids. Every failure on that path is silence, and a version from the registry is checked against ^\d+\.\d+\.\d+$ before it reaches a terminal.
  • A token count of zero is printed; a cost that could not be computed is blank. The two look alike and mean opposite things. A count is never unknown, so blanking a zero would make a known figure look unknowable; a cost of 0 would read as free.
  • Long-context, priority, flex, batch and regional rates are deliberately unused. They look like an omission and are not.
  • message.usage.iterations is not summed. The record's own usage already contains ordinary message entries. advisor_message is the one measured additional kind and is read separately with its own model.
  • replaySession in core/replay.ts is the batch path: one file in, priced turns out, and nowhere for them to go. The watcher, the report and importHistory all sit on it. Anything that reads a whole transcript belongs there rather than beside it.
  • importHistory is still deliberately unreachable from the CLI. A --import-history flag was considered and rejected. What it owns now is only the CSV: deduping and appending. It stopped renumbering when a row's number became the turn's place in the transcript.
  • The CSV is written, not read. A row's number is the turn's position in the session and the exit summary is folded from the session's turns, so neither depends on a file that lands wherever the command was run. readRecordedKeys is the one read left and importHistory is its only caller, because merging a replay into an existing file means knowing what that file holds. Adding a second read puts program state back into an output.
  • Display width is deliberately counted in code units. A half-built Unicode table that is wrong in a new way is worse than an honest note.
  • Colour is a Paint passed in, applied after fitting, and never nested. A renderer never asks whether colour is on: the default is PLAIN, which is why every width test measures what a reader sees. An escape lengthens a string without occupying a column, so painting a value on its way into fit makes the cell short by its own escapes. And escapes do not nest, so cells and rules are painted separately: an inner reset ends the outer colour and the rest of the row comes out plain. Stripping every escape must leave the output unchanged.
  • No lifecycle script is ever declared in package.json. Not prepare, not postinstall, not install. None of them would run for someone installing TurnLens, but declaring one is enough to make npm warn every installer that this package runs code at install time, and npm's remedy for that warning errors on a global install. This is the whole reason there is no pre-commit hook: development tooling lives in .claude/ and .github/, which npm never reads. npm install turnlens prints one line, and that is a property to check, not to assume.
  • A change is not finished until the document its update-when names is edited, where such a document exists. See below.

Documents

If a docs/ directory is present, read docs/README.md first. It indexes the working documents and says which to open for which task: one per pipeline area, plus the architecture, the decisions, the measurements and the roadmap.

That directory is not part of this repository. It is gitignored and stays on the machines that develop TurnLens, so a clone will not have it, and this section is written to be true either way. Working from a clone, the code and its comments are the whole record: read those, and do not conclude a decision was never made merely because you cannot find a file recording it.

A document tells you where to look and what was already decided. Before changing code, stating what is true now, or refusing a change because it was decided against, open the source it names. A record knows why a decision was made; it does not know what would break today.

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.