TECHDEV · Flagship · Open-source tool

context-diet

A deterministic diet for agent context — every cut accounted for, nothing invented. It shrinks accumulated content before it reaches the model, and proves every cut with a manifest.

TypeScript · MCP server + CLI · MIT · Node 20+ · Runtime dependencies: MCP SDK, zod · No model, no network, no shell execution.

Why context runs out

Coding agents do not run out of context because of one big file. They run out because of accumulation: tool outputs, test logs, build logs, repeated turns, and the same content pasted again in a new form. Context Diet shrinks that accumulated content before it reaches the model — and proves every cut with a manifest.

What it does

Context Diet is an MCP server (plus a CLI) with six tools:

ToolWhat it does
diet_countLines, bytes, and estimated tokens of a text
diet_dedupeRemoves duplicate lines and repeated blocks (traces differing only in 0x addresses collapse too, first occurrence kept verbatim)
diet_extractRelevance-ranked excerpts for a query
diet_summarizeExtractive summary to a token budget
diet_packFull pipeline + a manifest for every line
diet_checkPlanned-vs-executed completeness: which planned items survived in an output

The core promise

Output lines are always copied verbatim from the input. Context Diet never invents, paraphrases, or rewrites text. If a detail matters, it is either in the output or counted in the manifest — never silently rewritten.

Near-duplicates

Repeated stack traces that differ only in 0x memory addresses collapse to their first occurrence, which is kept verbatim with its location; later locations are counted (not kept) and reported separately from exact duplicates in the manifest. Bare hex without a 0x prefix, timestamps, and PIDs are left exact, because they may be meaningful identifiers. This is text matching, not proof that two failures share a fix. Pass --exact-only (CLI) or exactOnly (MCP) for strict byte-identical matching.

Protected lines

Pass verbatim lines that must survive (protectLines in diet_summarize/diet_pack, --protect-file in the CLI). They are kept first, ahead of error lines. If they alone exceed the budget, fail mode (default) throws instead of dropping them; partial mode keeps them and flags shortfall for diagnostics only. The pack manifest reports protected kept vs missing. Protection is an explicit caller list, never a guessed pattern, and this tool does not detect semantic contradictions between requirements: the over-budget/missing report, naming every protected line at stake, is the conflict report — it never silently chooses which requirement to drop.

Completeness check

Give diet_check (or CLI check) a plan — the items that were supposed to appear, e.g. test names — and an output, possibly already trimmed. Each item is found when some output line contains it verbatim as a substring (case-sensitive); every found item carries its evidence line, and missing items are listed by name. The result is the durable sidecar record: keep it outside the trimmed artifact, never appended inside it. The loud channel is separate: the CLI exits non-zero when the check fails, so CI goes red exactly when a sentinel did not survive. Quiet when OK, loud when broken. The check is one-directional by design — it does not detect executed-but-unplanned items — and short identifiers can false-positive inside longer ones, so use specific identifiers.

Marker mode (opt-in): pass execution markers and a line counts as execution evidence only when it contains the item verbatim AND carries a marker on word boundaries, so a log that merely recites the plan scores 0 executed-pass. Among the lines containing an item, the first marked line decides: a fail marker on it means executed-fail, otherwise executed-pass, and survived requires nothing missing and nothing failed. Markers are caller-supplied (markers / --markers); fail markers default to ["FAIL"] unless the caller overrides, and fail markers without markers are an error. Caller-declared skips (skipped / --skipped) are plan changes, not executions: the check trusts the declaration, lists skips by name, and never counts them as missing. Limits, stated plainly: marked evidence is text presence, not proof against a log that echoes markers — keep the plan and the output in separate channels and audit evidence lines; an earlier FAIL is not erased by a later PASS, because the first marked line decides.

Use it

# Try it in 3 steps
git clone https://github.com/techdevfun/context-diet
cd context-diet
npm install && npm run build
# as a CLI:
node dist/cli.js pack --input examples/session.log --budget 400 --query "test failure"
# as an MCP server (Claude Code, Cursor, any MCP client) over stdio:
#   command: node, args: ["<path>/context-diet/dist/server.js"]
# MCP configuration
{
  "mcpServers": {
    "context-diet": {
      "command": "node",
      "args": ["/path/to/context-diet/dist/server.js"]
    }
  }
}
# How big is this log, really?
node dist/cli.js count --input ci.log

# Just the failures and their surroundings:
node dist/cli.js extract --input ci.log --query "timeout database"

# Fit it into 300 tokens, with receipts:
node dist/cli.js pack --input ci.log --budget 300

Commands and config copied from the context-diet README (v0.5.0). Requires Node 20 or later. There is no npm install for this tool yet: an npm package install, npm install -g context-diet, arrives with the first npm publish — see Roadmap in the README. Until then, build from source as above.

Measured numbers (README, a real session log)

examples/session.log (169 lines of real command outputs: verbose test runs, a README excerpt, a build output) packed to a 400-token budget with the query test failure:

LinesBytesEst. tokens
Before1697,9171,942
After231,587392
Saved86.4%80.0%79.8%

What this is NOT

No “where rivals beat us” section is included here because the README has no such section — only the “What it is not” list above.

Limits and safety

Not in v1 (roadmap): LLM summarization (opt-in), model-based compression, AST-aware code minification, cross-session cache, dashboard, auto-apply to agent configs, JUnit/XML parsing, SARIF output, secret redaction.

License

MIT. See LICENSE in the repository.

Source + README on GitHub → · Report an issue → · ask@techdev.fun

Related tools

More open-source tools from TECHDEV: sessguard, runverdict, gheist-guard, vetgate, ci-failure-detective, agent-seatbelt, devsecops-os, env-doctor, skill-audit, logtrim, testguard, breakcheck, keymap, memgraph, ggufit, leaseguard, factfence, jsonfold

Have a say

Vote for this tool, suggest a feature, or discuss it with other operators on the community board.