Skip to content
AgentDiet
Open source · MIT licensedGo 1.22+ · single static binary

Your AI Agent Deserves a Leaner Context.

AgentDiet helps developers measure, analyze, and optimize AI coding agent context consumption. Identify unnecessary overhead, eliminate duplicated instructions, and keep your AI development workflow efficient.

$go install github.com/qansaid/agentdiet@latest

zero dependenciesno API keyno network callsno config file

discoveranalyzeoptimizeenforce
acme-platform · agentdiet
simulated repository · numbers from a real run · nothing is uploadedreduced motion is on · use replay to watch the scan

The simulated acme-platform repository loads 6,770 always-on tokens across four instruction files on every request, 3.39% of a 200,000-token window, which is grade C against an 8,000-token budget and an estimated $20.31 per 1,000 requests at $3.00 per million input tokens, assuming one request per session. Seven findings include 2,389 tokens duplicated between AGENTS.md and CLAUDE.md.

Numbers come from the simulated example repository, not a benchmark of your codebase.

Reads the files loaded by

  • Claude Code
  • Codex
  • Cursor
  • Gemini CLI
  • GitHub Copilot
  • Windsurf
  • Cline
  • Goose
  • Jules
  • Roo Code
  • Continue

by file convention · no runtime integration

01The problem

The tax you pay before you type

Every agent runtime loads a set of instruction files unconditionally: AGENTS.md, CLAUDE.md, .cursorrules, copilot-instructions.md. Nobody measures them. They grow by accretion until the agent is spending thousands of tokens on instructions before it has read your question.

paid per request

not per task

always-onbilled

Injected on every request, before you type

Keep it ruthless. Rules only.

6,770 tokens
scoped

Loaded only while editing that subtree

Fine, proportional to the work.

196 tokens
on-demand

Costs nothing until the agent opens it

Let it grow. Reference belongs here.

911 tokens
config

Declares tools and servers, not text

Inventory the declarations; do not score their schema.

6 MCP servers

A tool that reports “your repo has 90k tokens of agent config” collapses these rows and cannot tell you what to do. Only the first one is a bill; the rest is inventory.

Field report: 80 public repositoriesSampled through GitHub code search, not a random population. Token counts are estimates, and duplication is counted per repository, not per session.

Five ways the prompt gets fat

Each one is ordinary engineering hygiene until you count it.

  1. 01

    Bloated AGENTS.md

    A rule per incident, a table per architecture decision. Nothing is ever deleted, because removing a rule feels riskier than adding one, so the file only grows.

    AGENTS.md · 285 lines · 3,086 tokens

  2. 02

    Duplicated CLAUDE.md instructions

    The same rules under a second filename, kept in sync by hand. A runtime may load both, one, or neither, so the duplicated text is quantified rather than a guaranteed per-request charge. The drift is immediate and certain.

    AGENTS.md ↔ CLAUDE.md · 2,389 tokens repeated

  3. 03

    Oversized system instructions

    Schemas, endpoint catalogs and glossaries pasted into the root file. They are reference material, needed for one task in fifty, loaded for all fifty.

    one always-on file above 3,000 tokens

  4. 04

    Unnecessary always-on context

    On-call escalation paths, incident history, retention policy. All true, all useful, none of it relevant to the function you asked the agent to change.

    scoped rules promoted to always-on, silently

  5. 05

    Unused MCP servers

    Each connected server contributes tool schemas to the prompt as soon as a session opens. Six servers declared for one repo means six surfaces competing for attention. The audit inventories the declarations; it does not measure the schema tokens they add.

    6 servers declared · inventory only

Duplication is worse than size

The same paragraph in two files is duplication the agent cannot deduplicate. Whether a runtime loads both depends on the agent; the audit quantifies the duplicated content, and the copies drift apart the first time someone edits only one.

AGENTS.mdduplicate

## Git workflow

Branch names are <type>/<issue>-<slug>.

Rebase onto main before opening a PR.

Squash-merge is the default.

CLAUDE.mdduplicate

## Git workflow

Branch names are <type>/<issue>-<slug>.

Rebase onto main before opening a PR.

Squash-merge is the default.

2,389 duplicated tokens identified. Actual savings depend on which files the runtime loads.

The cost line uses $3.00 per 1M input tokens as a default assumption. Change it with --price. It prices the context, not your invoice. The cost assumes one request per session; the CLI reports the same figure per 1,000 sessions, which the site labels as Estimated cost / 1K requests.

02The solution

One binary that prices your prompt

AgentDiet walks the repository, keeps the four tiers apart, and turns the always-on number into something you can argue about, budget for, and gate in CI. It reads files and prints a report and nothing else.

01

Repository scanning

Walks the tree, classifies each recognized instruction file into one of four tiers, and skips node_modules, vendor, dist, build and other dependency trees so a vendored AGENTS.md never counts as your prompt.

internal/audit/scan.go

02

Context token estimation

Prose at 4.5 characters per token, fenced code at 3.4, each segment rounded up. Calibrated against cl100k_base on 137 real agent-config files: 8.1% mean absolute error, 87% within ±15%.

internal/audit/estimate.go

03

Duplicate instruction detection

Normalizes paragraphs and reports text that appears in two or more files, quantifying the duplicated content. Actual savings depend on which files the target runtime loads. The CLAUDE.md-is-a-stale-copy drift is quantified, and the drift itself is certain.

internal/audit/report.go

04

Near-duplicate detection

Flags one instruction file that is at least 60% contained in another, which is what a copy that was edited once and never again looks like.

blockOverlap()

05

Oversized file identification

Any single always-on file above 3,000 tokens is called out by name, because one file that large is reading material, not a rule set.

detectFindings()

06

MCP configuration inventory

Builds an MCP configuration inventory from the config dialects in the wild (.mcp.json, .cursor/mcp.json and .vscode/mcp.json). It identifies declared server names. It does not measure the schema tokens those servers add, because that depends on the runtime and the tools it connects.

mcpServerNames()

07

Token budget enforcement

Exits 1 when always-on context outgrows --max-tokens. Machine-checkable, so the number can only shrink on purpose instead of by hope.

main.go

08

GitHub Actions integration

A composite action installs the binary, runs the audit, exposes always-on-tokens and grade as step outputs, and fails the job when the budget is exceeded.

action.yml

Not a tokenizer

It estimates, and prints the method in every report. A 2 MB vocabulary would buy precision nobody acts on and still be wrong for the next model.

Not an auto-fixer

It never rewrites your instruction files. Findings carry a fix as text; the diff is yours, reviewed by you.

Not a hosted service

No account, no upload, no telemetry, no network call. One binary, one pass over your working tree.

Unshipped work is listed as unchecked in the repository’s roadmap: --since, .agentdietignore, exact tokenizer mode and SARIF are planned, not features.

03How it works

Discover, analyze, optimize, enforce

Four steps, one pass, no server round-trip. The first two are a command; the last two are decisions you make with the output. Each stage below is interactive.

01DISCOVER

Discover what the agent loads

The walker finds instruction files by convention: no config file, no manifest to maintain. Each hit is sorted into always-on, scoped, on-demand or config, because only one of those four tiers is a bill.

No configuration. Convention beats a manifest you forget to update.

see the full report
04Worked example

The same repository, measured twice

A simulated Go monorepo with the drift almost every mature repository accumulates: a 285-line AGENTS.md, a CLAUDE.md that is a full copy of it, per-client rule files restating the same paragraphs, and six MCP servers declared for one service.

simulated fixture

not a benchmark

fixture acme-platform (simulated monorepo)command $ agentdiet . --top 10window 200,000price $3.00/1M
BEFOREAs it accreted: rules, reference and a duplicate, all always-on.
grade C · 6,770 tokens
acme-platform · agentdiet . --top 10
agentdiet . --top 10
estimator: prose chars/4.5 + fenced-code chars/3.4, rounded up per segment (measured MAE 8% vs cl100k_base)
ALWAYS-ON paid on every request, before you type
3,118 1.56% 290 L CLAUDE.md
3,086 1.54% 285 L AGENTS.md
298 0.15% 23 L .cursorrules
268 0.13% 25 L .github/copilot-instructions.md
SCOPED loaded only while editing that subtree
116 0.06% 11 L services/billing/AGENTS.md
80 0.04% 8 L services/ledger/AGENTS.md
ON-DEMAND costs nothing until the agent opens it
560 0.28% 66 L skills/incident/SKILL.md
351 0.18% 43 L skills/deploy/SKILL.md
CONFIG not context; declares what the agent may call
93 mcp .mcp.json
41 settings .claude/settings.json
TOTAL 6,770 always-on tokens (3.39% of a 200,000-token window)
GRADE C (budget 8,000) on-demand surface: 911 tokens
COST $20.31 per 1,000 sessions at $3.00 per 1M input tokens
FINDINGS
· 2,389 tokens repeated across AGENTS.md ↔ CLAUDE.md
→ keep the text in one file and point at it from the others
· 762 tokens repeated across AGENTS.md ↔ CLAUDE.md ↔ skills/incident/SKILL.md
→ keep the text in one file and point at it from the others
· 236 tokens repeated across AGENTS.md ↔ CLAUDE.md ↔ skills/deploy/SKILL.md
→ keep the text in one file and point at it from the others
· AGENTS.md is 100% contained in CLAUDE.md
→ keep one canonical file; the other should be a pointer, not a copy
· CLAUDE.md is 3,118 tokens loaded on every request
→ move reference material into a skill or docs/ and keep the root file to rules
· AGENTS.md is 3,086 tokens loaded on every request
→ move reference material into a skill or docs/ and keep the root file to rules
· 6 MCP servers declared (github, jira, playwright, postgres, sentry, slack); tool schemas enter the prompt on connect
→ disable servers you do not use in this repo — schema cost scales with tool count
--json for machines · --badge for shields.io · github.com/qansaid/agentdiet
verbatim output · simulated repository

Always-on tokens

6,770711

per request, before you type

Grade

CA

8,000 → 1,500 token budget

Estimated cost / 1K requests

$20.31$2.13

at $3.00 per 1M, one request per session

89.5% less always-on context in this fixture

Reference material was reorganized into the right tiers, while unused MCP servers were removed.

AFTERReference material reorganized into the right tiers; unused MCP servers removed.
grade A · 711 tokens
acme-platform · agentdiet . --top 10
agentdiet . --top 10
estimator: prose chars/4.5 + fenced-code chars/3.4, rounded up per segment (measured MAE 8% vs cl100k_base)
ALWAYS-ON paid on every request, before you type
540 0.27% 55 L AGENTS.md
72 0.04% 7 L .github/copilot-instructions.md
51 0.03% 6 L CLAUDE.md
48 0.02% 4 L .cursorrules
SCOPED loaded only while editing that subtree
97 0.05% 11 L services/billing/AGENTS.md
55 0.03% 6 L services/ledger/AGENTS.md
ON-DEMAND costs nothing until the agent opens it
207 0.10% 28 L skills/deploy/SKILL.md
188 0.09% 27 L skills/incident/SKILL.md
85 0.04% 11 L skills/schema/SKILL.md
CONFIG not context; declares what the agent may call
46 mcp .mcp.json
41 settings .claude/settings.json
TOTAL 711 always-on tokens (0.36% of a 200,000-token window)
GRADE A (budget 1,500) on-demand surface: 480 tokens
COST $2.13 per 1,000 sessions at $3.00 per 1M input tokens
FINDINGS
· 2 MCP servers declared (github, postgres); tool schemas enter the prompt on connect
→ disable servers you do not use in this repo — schema cost scales with tool count
--json for machines · --badge for shields.io · github.com/qansaid/agentdiet
verbatim output · simulated repository

What actually changed

AGENTS.mdRules only, 55 lines
Schema, glossary, endpoint catalog, incident themes and the deploy runbook moved to docs/ and skills/, where they load only when the task needs them.
CLAUDE.mdA pointer, 6 lines
The full copy became a two-sentence pointer to the canonical file. Duplication removed at the source, not summarized.
.cursorrules / copilot-instructionsShort form + pointer
Kept the handful of client-specific notes; stopped restating the repository rules in every dialect.
6 MCP servers2 declared
jira, playwright, sentry and slack were removed from .mcp.json, leaving github and postgres. The MCP configuration inventory drops from six servers to two; schema overhead depends on the runtime and connected tools and is not measured here.

Read this before quoting the numbers

This repository is synthetic. The before and after figures describe that fixture only. They are not a benchmark, not a survey, and not a promised saving for your codebase. AgentDiet does not measure agent output quality, before or after.

The CLI prints its cost line per 1,000 sessions because it assumes one request per session. The labels here call the same figure an estimated cost per 1,000 requests; multiply it by the requests a session actually makes if your workflow differs.

MCP findings in that output are an MCP configuration inventory. AgentDiet identifies declared server names; it does not measure how many schema tokens those servers add, because that depends on the runtime and the tools it connects.

The percentage is a consequence of how much duplication the fixture contains. Your repository may have almost none, in which case the report will tell you that too, and the honest next step is to run it on your own tree, which takes one command and sends nothing anywhere.

Run it on your repository
05Developer experience

Install once. Read it in a second.

No config file to write, no account to create, no daemon to keep alive. The whole interface is a command with six flags and three exit codes.

bash: agentdiet
$ agentdiet
estimator: prose chars/4.5 + fenced-code chars/3.4, rounded up per segment (measured MAE 8% vs cl100k_base)
ALWAYS-ON paid on every request, before you type
540 0.27% 55 L AGENTS.md
72 0.04% 7 L .github/copilot-instructions.md
51 0.03% 6 L CLAUDE.md
48 0.02% 4 L .cursorrules
SCOPED loaded only while editing that subtree
97 0.05% 11 L services/billing/AGENTS.md
55 0.03% 6 L services/ledger/AGENTS.md
ON-DEMAND costs nothing until the agent opens it
207 0.10% 28 L skills/deploy/SKILL.md
188 0.09% 27 L skills/incident/SKILL.md
85 0.04% 11 L skills/schema/SKILL.md
CONFIG not context; declares what the agent may call
46 mcp .mcp.json
41 settings .claude/settings.json
TOTAL 711 always-on tokens (0.36% of a 200,000-token window)
GRADE A (budget 1,500) on-demand surface: 480 tokens
COST $2.13 per 1,000 sessions at $3.00 per 1M input tokens
FINDINGS
· 2 MCP servers declared (github, postgres); tool schemas enter the prompt on connect
→ disable servers you do not use in this repo — schema cost scales with tool count
--json for machines · --badge for shields.io · github.com/qansaid/agentdiet

Audit the current repository. Pass a path to audit another tree.

--jsonoffEmit the full report as JSON with stable keys, safe for dashboards.
--badgeoffEmit a shields.io endpoint document instead of the report.
--max-tokens0 (off)CI gate: exit 1 when always-on tokens exceed this number.
--window200000Context window used for the share column.
--price3.00USD per 1M input tokens, used for the cost line.
--top8Maximum files listed per section.
--versionn/aPrint the version and exit.

identical to `agentdiet --help`, which the binary prints itself.

06GitHub integration

Make it a gate, not a habit

A number nobody checks is a number that grows. Wire the audit into the workflow you already have, and the always-on tax becomes a pull request check that has to be justified.

.github/workflows/agent-context.yml
name: agent-context
on: [push, pull_request]
jobs:
agentdiet:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: qansaid/agentdiet@v1
with:
max-tokens: 4000

Pins @v1, the moving major tag the maintainers update on each release. Pin a full semver tag if you prefer immutable refs.

Pull request validation

The check runs on every PR. A change that inflates the always-on tax fails like any other broken invariant, so the reviewer sees it before the merge, not a quarter later.

Machine-readable output

The action exposes always-on-tokens and grade as step outputs, and --json gives you every recognized file, finding and total if you want your own dashboard instead.

No secrets to provision

There is no API key to store, no service to reach and nothing to allowlist. The binary runs in the runner, reads the checkout and exits.

Contribution guidelines
07Open source

Built for Developers. Open for Everyone.

AgentDiet is developed in the open under Qansa, licensed MIT, and deliberately small: a stdlib-only Go binary with no runtime dependencies, no network calls and no telemetry. There is no paid tier and no hosted version to upsell you into.

MIT · public repository

Maintained by Qansa

AgentDiet is a Qansa open-source project. Product identity stays with AgentDiet; the repository, releases and roadmap live under the Qansa organization on GitHub.

08FAQ

Questions developers actually ask

Answers describe what the code does today. Where the tool is approximate, it says so.

Something missing? Open a discussion. The question that is asked twice becomes a section here.

Ask on GitHub
What is AgentDiet?
A single static Go binary that discovers recognized AI agent instruction files based on supported file conventions, and reports what those files cost: per request, per 1,000 requests at one request per session, and against a budget you can enforce in CI. It is one binary with no runtime dependencies, no config file and no network call.
Why should I care about context consumption?
Always-on instruction files are loaded before you have typed anything, by the runtimes that read them. They grow by accretion, a rule per incident and a table per architecture decision, until the agent spends thousands of tokens of attention on stale instructions and reference material that was never meant to be read every time. Unlike skills, which cost nothing until opened, that context is paid for whenever those files are loaded.
Does AgentDiet require an API key?
No. There is no account, no API key, no sign-in and no network access at all. The binary reads files from disk and prints a report.
Does it send source code to external servers?
No. The audit runs entirely on your machine, there is no telemetry and no configuration file that could point it somewhere else. The estimator is arithmetic on character counts, so nothing needs to be embedded or uploaded to count tokens.
Which AI coding agents are supported?
AgentDiet detects file conventions rather than connecting to runtimes: AGENTS.md, CLAUDE.md, GEMINI.md, JULES.md, .goosehints, AGENT.md, .cursorrules, .windsurfrules, .clinerules, .rules, .github/copilot-instructions.md, .cursor/rules/*.mdc, skills/**/SKILL.md, .claude/commands, .github/prompts, .roo/rules, .continue/rules, and MCP configs in .mcp.json, .cursor/, .vscode/ and .claude/. That covers Claude Code, Codex, Cursor, Gemini CLI, GitHub Copilot, Windsurf, Cline, Goose, Jules, Roo Code and Continue.
Does it automatically modify instruction files?
No. AgentDiet is read-only: it opens files, counts, and reports. Every finding carries a fix as text, and you decide how to apply it. Rewriting someone's AGENTS.md automatically would be a much larger claim than measuring it.
Can I integrate it into CI/CD?
Yes. There is a composite GitHub Action (qansaid/agentdiet@v1) that installs the binary, runs the audit and fails the job when always-on tokens exceed max-tokens. Without the action, install the binary with go install and run agentdiet --max-tokens 4000 as a step; exit code 1 is the gate.
How accurate is the token count?
It is an estimate, and it says so in every report. Prose is counted at 4.5 characters per token and fenced code at 3.4, calibrated against cl100k_base on 137 real agent-configuration files from five repositories: mean error +1.2%, mean absolute error 8.1%, 87% of files within ±15%. That is precise enough to answer "400 tokens or 4,000" and "did it grow 30% this quarter", which are the decisions the tool exists for. Exact per-model counts are a tokenizer's job, and the report tells you which file is worth running through one.
Is AgentDiet free and open source?
Yes. MIT licensed, developed in the open at github.com/qansaid/agentdiet, with no paid tier, no hosted product and no feature held back. Issues and discussions are open, and contributions are accepted under the same MIT license.

Measure it before you optimize it.

One command, no account, no upload. If your context is already lean the report will say so in one line, which is the cheapest possible answer to a question most teams never ask.

$go install github.com/qansaid/agentdiet@latest

MIT · Go 1.22+ · no telemetry · no network calls