{
  "markdown": "# context-os\n\n[![CI](https://github.com/sravan27/context-os/actions/workflows/ci.yml/badge.svg)](https://github.com/sravan27/context-os/actions/workflows/ci.yml)\n[![License](https://img.shields.io/badge/license-MIT-green)](LICENSE)\n[![Release](https://img.shields.io/github/v/release/sravan27/context-os?label=release)](https://github.com/sravan27/context-os/releases/latest)\n\n**Claude Code's first turn opens the right file instead of grepping for it.** A 400-line Python hook builds a static graph of your repo (symbols + imports + git-hot files) and injects ranked `file:line` candidates into the prompt before Claude's first turn — so it skips the `Glob → Grep → Read → Read → Read` hunt and goes straight to the file.\n\nNo embeddings. No server. No model call. ~50 ms.\n\n**What's proven vs. what to expect.** Retrieval quality is measured and CI-gated (MRR 0.984 synthetic, 0.756 on this repo, beats BM25 — see below). A `--print` A/B showed **−40.9% tokens (N=36, cold-cache, earlier build, p=5e-7)**. Honest caveat: that bench is cold-cache one-shots; in a *warm* interactive session, prompt caching makes re-sent context cheap, so your **dollar** savings are smaller than 40.9% — the durable wins are fewer first-turn tool calls and hitting context limits/compaction later. Don't take our number — **replay it on your own history (no API key): `python3 python/evals/runners/replay_history.py`.**\n\nNeed this applied to a private repo this week? I have **2 paid audit slots open**. [Fund the $1,000 AI Agent Cost Leak Audit](https://buy.polar.sh/polar_cl_z0eLsPUJeMwrcNs4MQPAQbKIM3Rbdb8fLDgVj2RZcmr) or read the [audit scope](https://sravan27.github.io/money-27-proof/agent-cost-leak-audit.html). The OSS tool stays free; the sprint is for teams that want a private report, CI leak gate, and one concrete repo/workflow patch.\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/sravan27/context-os/main/setup.sh | bash\n```\n\n![demo](docs/demo.gif)\n\n*60-second demo: graph stats → autocontext block with import counts → cross-repo eval (auto_context 0.545 winning) → 9/9 CI floors PASS. Reproduce with `bash docs/distribution/demo.sh`.*\n\n## Private repo audit\n\nIf your team is already spending heavily on Claude Code, Codex, Cursor, or other coding agents and wants a private cost-leak report, I am doing **2 paid 48-hour audits** this week: [AI Agent Cost Leak Audit](https://sravan27.github.io/money-27-proof/agent-cost-leak-audit.html).\n\nPayment starts the slot. After checkout, send repo/access details by email or private intake; do not paste private code into a public issue.\n\nThe open-source hook stays MIT and free. The paid audit is for teams that want the same measurement discipline applied to their own repo, prompts, and agent workflows.\n\nWhat the paid sprint ships:\n\n- a private repo scorecard using the same leak signals as the Action\n- a short report on the highest-cost agent loops and file-noise sources\n- one concrete CI, ignore-rule, or repo-guidance patch where the fix is clear\n- a handoff note your team can reuse when running Claude Code, Codex, Cursor, or internal agents\n\nQuick local preview:\n\n```bash\npython3 python/agent_cost_leak_check.py --repo . --json\n```\n\nCI recipe: [`docs/AGENT-COST-LEAK-CHECKER.md`](docs/AGENT-COST-LEAK-CHECKER.md). For public intake without sharing private code, use the [private audit request template](https://github.com/sravan27/context-os/issues/new?template=private_audit.yml).\n\nVersioned GitHub Action:\n\n```yaml\n- uses: sravan27/context-os@v2.9.0\n  with:\n    max-score: \"40\"\n```\n\n## The number\n\nLive A/B on 36 real `claude --print` calls, identical fixture, identical model, only difference is whether the hook is active:\n\n| Metric                           |        Value |\n| -------------------------------- | -----------: |\n| Aggregate tokens                 |   **−40.9%** |\n| Prompt-level wins                |      **6/6** |\n| Bootstrap 95% CI                 |  32.7%–48.9% |\n| Paired t-test                    |   p = 5.1e-7 |\n| Wall-clock                       |       −35.3% |\n\n**Read this number honestly:** these are **cold-cache `--print` one-shots** (Claude Code pays full cache creation per call — see [`METHODOLOGY.md`](docs/METHODOLOGY.md)). That's the right setup to isolate the hook's effect, but it's *not* your warm interactive session: there, prompt caching makes re-sent context cheap, so the **dollar** delta is smaller. It's also N=36 on one repo, on an earlier build. Treat it as \"the hook clearly removes first-turn exploration,\" not \"you'll save 41% on your bill.\" The version-independent, CI-gated claim is the retrieval quality below.\n\nRaw JSON for every call: [`python/evals/reports/live-session-bench-raw.json`](python/evals/reports/live-session-bench-raw.json) · methodology: [`docs/METHODOLOGY.md`](docs/METHODOLOGY.md).\n\nCross-repo: 36 hand-labeled prompts × 3 unseen OSS repos (axios, ripgrep, requests). Weighted MRR **0.545 vs 0.461** best lexical baseline — **+18.2%**. Beats every baseline in every language. Report: [`multi-repo-eval.md`](python/evals/reports/multi-repo-eval.md).\n\n## What Claude sees\n\nBefore:\n```\nuser: where is the gitignore parser\nclaude: Glob → Grep → Read → Read → Read → \"found it in walk.rs\"\n```\n\nAfter:\n```\n<context-os:autocontext>\ncrates/ignore/src/gitignore.rs:42  · Gitignore (struct)\ncrates/ignore/src/gitignore.rs:118 · matched (fn) · imports: …\n</context-os:autocontext>\nclaude: Read crates/ignore/src/gitignore.rs → done\n```\n\n## Read less — the compounding cost nobody attacks\n\nauto_context kills *first-turn* exploration. But the bigger, compounding cost is\nthat **every file Claude reads is re-sent on every later turn until compaction.**\nRead an 800-line file at turn 3 and you pay for it again, and again, for 40 turns\n— when Claude needed one 40-line function.\n\nSo when Claude goes to read a whole file, context-os intercepts it and hands back\nthe file's **outline** — every symbol with its exact line range, rendered from the\ngraph with *zero* file content — and Claude re-reads only the slice it needs:\n\n```\nuser: (Claude is about to Read payment.py — 847 lines)\ncontext-os intercepts ↓\n  L12-45    class PaymentProcessor\n  L47-89      def charge(self, amount, method)\n  L91-120     def refund(self, txn_id)\n  L340-410  def validate_card(number, cvv)\n  … +28 symbols\n  e.g. Read(\"payment.py\", offset=47, limit=43) for the block at L47.\n\nclaude: Read payment.py offset=47 limit=43 → 43 lines, not 847.\n```\n\nThe 800 lines never enter context — so they're never re-sent. One whole-file read\nturned into an outline can keep ~20k tokens out of context per file. It fires once\nper file per session (no nag), only on big files, and only when the graph has the\nstructure to slice. `/outline <file>` does it on demand. Disable with\n`CONTEXT_OS_SMART_READ=0`.\n\n## Your savings, measured — not estimated\n\nSaving 40% silently builds no habit. So context-os keeps a receipt — and it\n**measures** the saving causally from your own transcript, it doesn't guess.\n\nEvery prompt is classified: did Claude open the right file *first* (a search\n**avoided**), or did it Glob/Grep around before finding it (an **exploration**)?\nThe exploration cost is read straight off the real `tool_result` sizes — so each\navoided search is credited the average a search *actually cost in your session*.\nA Stop hook does this; the statusLine shows a live meter; `/savings` shows the rest:\n\n```\n💰 2.3M saved · 5d🔥        ← statusLine, every prompt\n\n$ /savings\n  All-time saved      2,340,000 tokens  (~$14.04)\n  Runway bought            ~47 prompts before the rate window\n  Searches avoided            412  (opened the right file with no Glob/Grep)\n  Big reads sliced             96  (whole-file reads turned into an outline)\n\n  Where it came from\n  Avoided searches    1,402,000 tok  (auto_context → straight to file)\n  Sliced big reads      938,000 tok  (smart_read → outline, not whole file)\n\n  How it's measured\n  A search cost        14,200 tokens on average — measured\n                       from 287 of your own prompts that still explored\n  ╭─────────────────────────────────────────────╮\n  │            context-os · receipts            │\n  │  2,340,000 tokens saved   (~$14.04)         │\n  │  412 searches replaced by a direct open     │\n  │  avg search cost 14,200 tok — measured      │\n  ╰─────────────────────────────────────────────╯   ← copy/paste anywhere\n```\n\nLocal-only, no phone-home. The credit per avoided search is clamped to ≤15k\n(below the 21k aggregate the live A/B measured), and sessions with nothing to\nmeasure fall back to a labelled 8k estimate — so the number under-claims, never\nover-claims. Correctness is CI-gated (`python3 python/evals/runners/savings_test.py`, 49 assertions).\n\n**Don't trust my A/B — replay it on *your own* history (no API key, $0):**\n\n```bash\npython3 python/evals/runners/replay_history.py --all\n```\n\nScans your existing `~/.claude/projects/**/*.jsonl` transcripts and backtests\nthe whole stack: how many whole-file reads smart_read would have sliced (load\nsizes measured exactly from your transcripts) and how many explorations\nauto_context's top-5 would have collapsed. It's a counterfactual, not a live\nA/B — and it's honest that results depend on your session mix (navigation-heavy\ninteractive work is the regime these hooks target; long autonomous build runs\nshow less).\n\n## Install\n\nPer-project:\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/sravan27/context-os/main/setup.sh | bash\n```\n\nGlobal response-shaping + env vars to `~/.claude/`:\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/sravan27/context-os/main/setup.sh | bash -s -- --global\n```\n\nReproduce the eval locally:\n\n```bash\ngit clone https://github.com/sravan27/context-os && cd context-os\npython3 python/evals/runners/ranker_floor.py     # 9 CI-enforced floors, ~45s\npython3 python/evals/runners/multi_repo_eval.py  # cross-repo eval, ~2 min\n```\n\n## What it installs\n\n`setup.sh` writes 31 techniques across `CLAUDE.md`, `.claudeignore`, `.claude/settings.json`, thirteen slash commands, an output style, a Haiku explorer subagent, and nine stdlib-Python hooks under `.claude/hooks/`. Full list with evidence per row: [`docs/TECHNIQUES.md`](docs/TECHNIQUES.md).\n\nThree hooks are the heart of it, all backed by one graph: **`auto_context.py`** (UserPromptSubmit — retrieval, skip first-turn exploration), **`smart_read.py`** (PreToolUse — structural slicing, read the slice not the file), and **`savings_tracker.py`** (Stop — measure both, causally) surfaced via `/savings`. All hooks fail-open — if they break, your session keeps going.\n\n## What it doesn't do\n\n- No LLM routing, model swapping, prompt rewriting.\n- No proxy. Claude Code talks to Anthropic directly.\n- No telemetry, no phone-home, no analytics. Read [`setup.sh`](setup.sh).\n\n## Uninstall\n\n```bash\ncurl -fsSL https://raw.githubusercontent.com/sravan27/context-os/main/setup.sh | bash -s -- --uninstall\n```\n\nRemoves only the `<!-- context-os -->` block from `CLAUDE.md` and files context-os wrote. Idempotent.\n\n## Limitations\n\n- On repos where prompts already name the exact class (`psf/requests` calling out `PreparedRequest`), well-tuned BM25 ties us. Lexical-ceiling regime.\n- Live A/B is 36 calls on 6 prompts — `p < 1e-6` is real but not Anthropic-scale.\n- Symbol extraction is regex-based and ships handlers for Python, TS/JS, Rust, Go. Other languages fall back to path-only ranking.\n- Hook adds ~12–15% input overhead per turn; amortizes in 1–2 turns on non-trivial repos.\n- Hook p99 latency 118 ms at 10k files, 589 ms at 50k.\n\nFull caveats: [`docs/limitations.md`](docs/limitations.md).\n\n## Compatible with\n\nClaude Code on macOS + Linux. Requires `python3` (stdlib only). Optional Rust binary (`apps/cli`) adds output compression and session-memory hooks.\n\n## License\n\nMIT. See [LICENSE](LICENSE).\n",
  "bytes": 11818,
  "sha": "d28a7e10d9600dce814a7f9227c66141e25fa40eb89199c34edb3e9dcab5f665",
  "repo_slug": "sravan27/context-os",
  "fonte": "repo",
  "truncated": false,
  "api": "https://agentalog.com/api/listings/plg_sravan27_context_os_context_os_593c32a4/readme"
}