{"slug": "i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it", "title": "I was paying too much for Claude and codex here is how I reduced 90% of it", "summary": "Qarinah, an open-source local memory compiler for coding agents, claims to reduce input-context tokens by 98.71% and achieve a 77.81:1 compression ratio, cutting estimated input-context cost from $0.4421 to $0.0057 per query at a flat $1 per million uncached input tokens. The tool, which supports Codex, Claude Code, CLI workflows, and MCP clients, turns project decisions and evidence into a bounded, cited pack for agent queries.", "body_md": "*Less context. More proof.*\n\n**Local project memory and a context compiler for coding agents.**\n\n[ Website](https://qarinah.io) ·\n\n[·](https://qarinah.io/docs/)\n\n**Documentation**[·](https://qarinah.io/paper/)\n\n**White paper**\n\n**DOI**\n`LOCAL-FIRST`\n\n`EVIDENCE-LINKED`\n\n`GRAPH-AWARE`\n\n`OKF-PORTABLE`\n\n`GOVERNANCE-READY`\n\n**98.71% less estimated context - 77.81:1 context compression.**\n\n442,113 → 5,682 estimated input tokens.\n\n**98.71% lower input-context cost at the same token rate.**\n[Reproduce it yourself.](/AjnasNB/qarinah/blob/main/docs/BENCHMARKS.md)\n\n**Less replay. More room for current code, tools, and cited project memory.**\n\n[Technical paper](/AjnasNB/qarinah/blob/main/docs/WHITEPAPER.md) ·\n[Publication PDF](https://github.com/AjnasNB/qarinah/blob/main/output/pdf/Qarinah-Technical-White-Paper-v1.0.pdf) ·\n[Zenodo record](https://doi.org/10.5281/zenodo.21547685) ·\n[Architecture](/AjnasNB/qarinah/blob/main/docs/ARCHITECTURE.md) ·\n[Benchmarks](/AjnasNB/qarinah/blob/main/docs/BENCHMARKS.md) ·\n[Security](/AjnasNB/qarinah/blob/main/docs/SECURITY.md) ·\n[Launch plan](/AjnasNB/qarinah/blob/main/docs/ECOSYSTEM-LAUNCH.md)\n\n**What if your coding agents could send 98.71% less repeated project context?**\n\n442,113 estimated input-context tokens became 5,682 - 98.71% less repeated context and 77.81:1 context compression, with every required target directly covered in the top five.\n\n*Nearly 99% less repeated context. Every selected memory points back to its source.*\n\nSuccessfully verified across React editing, database migration, TypeScript refactoring, web research, production debugging, and governed release work. The evaluated tasks sent 436,431 fewer estimated input-context tokens. At a flat $1 per million uncached input tokens, that compared context slice moves from $0.4421 to $0.0057 - 98.71% less input-context cost under the same unit price. The percentage is independent of the chosen flat unit price; the portable token estimate excludes output, tools, caching, and fixed provider charges. See the\n\n[machine-readable result]and[methodology].\n\n```\nnpm install --save-dev qarinah\nnpx qarinah init .\nnpx qarinah record \\\n  --kind decision \\\n  --title \"Keep releases provenance-bound\" \\\n  --body \"Publish only the reviewed artifact from the reviewed commit.\"\nnpx qarinah build\nnpx qarinah query \"release provenance\" \\\n  --minimum-coverage direct \\\n  --max-tokens 1500 \\\n  --format markdown\n```\n\nStart with the [five-minute guide](/AjnasNB/qarinah/blob/main/docs/GETTING-STARTED.md), then use the [CLI reference](/AjnasNB/qarinah/blob/main/docs/CLI-REFERENCE.md), [JavaScript API reference](/AjnasNB/qarinah/blob/main/docs/API-REFERENCE.md), [MCP guide](/AjnasNB/qarinah/blob/main/docs/MCP-GUIDE.md), [task recipes](/AjnasNB/qarinah/blob/main/docs/RECIPES.md), or [troubleshooting guide](/AjnasNB/qarinah/blob/main/docs/TROUBLESHOOTING.md).\n\nYour project already contains the decisions and evidence behind its changes. Qarinah lets the next agent query that record and receive a bounded, cited pack selected for the current task. The same local memory can support Codex, Claude Code, CLI workflows, and compatible MCP clients instead of locking project context to one editor.\n\nQarinah is a local memory compiler for coding agents. It turns permitted agent activity, project structure, and explicitly committed decisions into durable project memory for Codex, Claude Code, CLIs, and governed workflows. It preserves evidence in a typed graph and deterministic Markdown and JSON views, then compiles a bounded cited pack selected for the current query instead of making an opaque summary or a full transcript the source of truth.\n\nAgent memory usually fails in one of two ways: the next model receives too much history, or it receives a compressed story with no way to verify the source. Qarinah keeps the source record and the compact context separate.\n\nEvidence-linkedEvery selected item cites its event ID and content hash. Conflicts, supersession, authority, retention, and time remain explicit. |\nBudgetedCoverage-aware retrieval compiles a bounded pack instead of replaying the complete project history. |\nRebuildableThe JSONL chain is authoritative. Graph, index, Markdown, project structure, and OKF are deterministic derived views. |\nGovernance-readyExplicit capture policy, fail-closed coverage, read-only diagnostics, and optional Maqam disclosure controls preserve boundaries. |\n\nMetadata-only capture is the default. Content capture requires explicit workspace consent. Hidden reasoning, private transcripts, credentials, and browser session state remain outside the product boundary.\n\nWhen a host or orchestrator queries Qarinah before constructing a model request, Qarinah compiles the retained project history into a bounded cited pack first. That same pack can be supplied to a small local model, a large-context model, or a high-reasoning Codex or Claude session. The compiler itself does not need an embedding API, a hosted memory service, or a Qarinah API key.\n\nPacks are requested explicitly. Hosts can call the CLI or JavaScript API, while sensitive automated disclosure can be registered through a separately governed Maqam capability. Qarinah's built-in MCP server remains a zero-write diagnostic surface.\n\nQarinah records every permitted lifecycle event delivered by a supported host adapter and every decision that a user or governed workflow explicitly commits. It does not claim to infer every cognitive decision automatically.\n\nSupported event classes include prompts, tool requests, tool completions, approvals, artifacts, sources, claims, decisions, summaries, compactions, subagents, completed turns, and failed turns. Relations connect sessions, turns, tool calls, sources, approvals, conflicts, supersession, derived evidence, and produced project structure.\n\nThe project graph covers directories, files, content hashes, JavaScript and TypeScript module references, Markdown links, exact source spans, additions, changes, renames, and deletions. See the [architecture guide](/AjnasNB/qarinah/blob/main/docs/ARCHITECTURE.md) or the [editable diagram source](/AjnasNB/qarinah/blob/main/docs/architecture.mmd).\n\nQarinah is intentionally small, local, and inspectable:\n\n| Layer | Technology |\n|---|---|\n| Runtime | Modern Node.js ESM on maintained Node 22, 24, and 26 releases |\n| Durable memory | Append-only canonical JSONL events, SHA-256 content and chain hashes, machine-local checkpoints, and renewable write locks |\n| Project graph | Typed event, evidence, relation, module, Markdown-link, file, rename, change, and deletion edges |\n| Retrieval | BM25, character-trigram typo tolerance, one-hop graph evidence, reciprocal-rank fusion, deterministic diversity, time, authority, retention, conflict, and supersession |\n| Context compiler | Complete-output character and token budgets, explicit output headroom, evidence-coverage gates, deterministic citations, and reproducible manifests |\n| Human-readable views | Rebuildable Markdown, JSON, graph, index, and Google OKF 0.1 Draft exports |\n| Agent integration | Codex and Claude Code lifecycle hooks, strict JSON stdin, local CLI, typed JavaScript API, and stdio MCP diagnostics |\n| Infrastructure | No vector database, hosted backend, embedding bill, model provider, daemon, analytics endpoint, or Qarinah API key |\n\nQarinah requires a maintained Node.js 22, 24, or 26 release.\n\n```\nnpm install --save-dev qarinah\nnpx qarinah init .\n```\n\nThe package is designed for local use. It does not require a hosted Qarinah account, embedding service, or Qarinah API key.\n\n`npx qarinah init .`\n\nis a one-time, explicit opt-in for that exact workspace and capture policy. After a reviewed Codex or Claude Code integration is installed and its host is restarted, supported lifecycle hooks can append permitted events whenever the host emits them. Qarinah can then rebuild the deterministic graph and compile a small cited pack on demand, so the next task does not need the whole retained history replayed into its prompt.\n\nQarinah is project memory, not an always-running agent or application supervisor. It does not keep Codex or Claude running, prevent provider-side context compaction, capture host activity the host does not expose, or automatically disclose context through MCP. When a host compacts its own conversation, Qarinah preserves only the permitted evidence it actually received and makes that evidence available to an explicit query or separately governed disclosure capability.\n\n```\n# Opt in. Metadata-only capture is the default.\nnpx qarinah init .\n\n# Commit one durable decision.\nnpx qarinah record \\\n  --kind decision \\\n  --title \"Keep releases provenance-bound\" \\\n  --body \"Publish only the reviewed artifact from the reviewed commit.\"\n\n# Record the bounded project structure and rebuild derived views.\nnpx qarinah scan\nnpx qarinah build\n\n# Retrieve only direct evidence and emit cited Markdown.\nnpx qarinah query \"release provenance\" \\\n  --minimum-coverage direct \\\n  --format markdown\n\n# Verify policy, event hashes, checkpoint, and derived state.\nnpx qarinah doctor\n```\n\nFor agent callers, use the strict JSON stdin interfaces so untrusted text is never interpolated into a shell command:\n\n```\nprintf '%s' '{\"query\":\"release provenance\",\"format\":\"json\",\"minimumCoverage\":\"direct\",\"maxChars\":8000}' \\\n  | npx qarinah query --stdin-json\n.qarinah/\n  config.json          portable workspace identity and requested policy\n  events/events.jsonl  authoritative append-only event chain\n  graph/graph.json     event and project nodes with typed edges\n  index/index.json     disposable deterministic retrieval index\n  records/CONTEXT.md   human-readable current record\n  records/okf/         reproducible Markdown interoperability bundle\n  index/event-ids/     checkpoint-authenticated idempotency projection\n```\n\nDelete any derived graph, index, or Markdown view and run `qarinah build`\n\nto reproduce it from the verified event chain.\n\nQarinah can export a verified workspace record as a deterministic [Google Open Knowledge Format 0.1 Draft](https://github.com/GoogleCloudPlatform/knowledge-catalog/blob/main/okf/SPEC.md) bundle:\n\n```\nnpx qarinah export okf\n```\n\nThe export is reviewable Markdown with a root index, a chronological log, one concept file per event, typed relations, citations, content hashes, and chain hashes. It can be diffed in Git, inspected without Qarinah, or passed to another system that understands OKF Markdown. The append-only JSONL event chain remains authoritative; OKF is a deterministic, replaceable interchange view rather than a second database or retrieval engine. See [interoperability](/AjnasNB/qarinah/blob/main/docs/INTEROPERABILITY.md#google-open-knowledge-format-derived-interchange).\n\nQarinah's dependency-free local retriever combines BM25, character-trigram typo tolerance, one-hop graph evidence, reciprocal-rank fusion, deterministic diversity, explicit supersession, conflict visibility, retention, time, and scoped authority.\n\nContext-pack v2 adds evidence coverage:\n\n```\n{\n  \"coverage\": {\n    \"method\": \"query-term-overlap-v1\",\n    \"status\": \"direct\",\n    \"queryTermCount\": 2,\n    \"bestExactTermCount\": 2,\n    \"bestExactTermRatio\": 1,\n    \"directCandidateCount\": 3\n  }\n}\n```\n\n`minimumCoverage: \"partial\"`\n\nrejects no-evidence packs. `minimumCoverage: \"direct\"`\n\naccepts only a record containing every normalized query term. Coverage is a deterministic retrieval diagnostic, not a claim that a model answer is correct.\n\nThe repository includes generated, dependency-free plugin runtimes for Codex and Claude Code. Both provide:\n\n- allowlisted lifecycle hooks;\n- a Qarinah context skill;\n- zero-write\n`context_status`\n\nand`context_doctor`\n\nMCP tools with exact workspace selection for hosts that do not expose MCP roots; - explicit CLI querying for user-directed local workflows.\n\nCodex and Claude Code plugin caches are immutable copies. Reinstall the reviewed plugin and start a new task after an upgrade. Claude requires an explicitly selected absolute Node 22, 24, or 26 executable. Codex still inherits the host's reviewed Node `PATH`\n\nboundary because its current plugin schema does not expose an equivalent file setting. See [host integrations](/AjnasNB/qarinah/blob/main/docs/HOST-INTEGRATIONS.md).\n\nAutomatic MCP context disclosure remains disabled. A context pack must be explicitly requested or disclosed through a separately governed Maqam capability.\n\nThe repository also runs `npm run mcp:smoke`\n\nagainst the exact bundled Codex and Claude runtimes. The smoke test starts each stdio server from its packaged manifest, exercises Codex without MCP roots using an exact trusted workspace selector, exercises Claude with negotiated roots, lists the two annotated tools, calls both tools against a temporary trusted ledger, and verifies clean shutdown without stderr output.\n\nInstall the reviewed `v0.1.0`\n\nplugin once in each host:\n\n```\n# Codex: personal installation, available to opted-in projects.\ncodex plugin marketplace add AjnasNB/qarinah --ref v0.1.0\ncodex plugin add qarinah@qarinah\n\n# Claude Code: personal installation across projects.\nclaude plugin marketplace add AjnasNB/qarinah@v0.1.0 --scope user\nclaude plugin install qarinah@qarinah --scope user\n```\n\nThen opt in from the root of each project that should retain context:\n\n```\nnpx -y qarinah@latest init . --capture content\nnpx -y qarinah@latest scan\nnpx -y qarinah@latest doctor\n```\n\nUse `--capture metadata`\n\nwhen event bodies should not be retained. Content mode records only bounded, redacted fields exposed by supported hooks; it does not parse hidden transcripts or reasoning. At the start of a later task, ask the installed Qarinah context skill for direct evidence related to the task, or run a bounded query:\n\n```\nnpx -y qarinah@latest query \"checkout dialog focus trap\" \\\n  --minimum-coverage direct \\\n  --max-tokens 1500 \\\n  --reserve-tokens 200 \\\n  --format markdown\n```\n\nThe returned pack selects complete cited records from the verified event chain. It is not a model-written rolling summary. Plugin installation is host-wide; capture permission and retained context remain project-specific. See [host integrations](/AjnasNB/qarinah/blob/main/docs/HOST-INTEGRATIONS.md) for current private-clone testing, Claude project/local scopes, upgrades, and interpreter trust.\n\n**Maqam governs** which registered reads and writes are allowed.**Cockroach Crawler gathers** bounded public source records.**Qarinah remembers** decisions, evidence, provenance, and outcomes.**ProductLoop orchestrates** workflows across those explicit boundaries.\n\nThese are composable packages, not one silently merged runtime. Qarinah also works without the other packages.\n\n- no capture outside an explicitly initialized and machine-trusted workspace;\n- revocation state stored outside the repository;\n- metadata-only capture by default;\n- bounded recursive redaction and strict event, log, context, path, and scan limits;\n- renewable append locks, linked-path rejection, hash chaining, rollback checkpoints, and deterministic rebuilds;\n- context treated as untrusted data, never executable instructions;\n- explicit no-evidence and fail-closed retrieval modes;\n- no transcript parsing or hidden chain-of-thought capture;\n- no model provider, database, daemon, analytics endpoint, or Qarinah API key required.\n\nContent-mode redaction cannot prove that arbitrary tool output contains no secret. Keep metadata mode unless retained content has already been reviewed. See [security](/AjnasNB/qarinah/blob/main/docs/SECURITY.md), [privacy](/AjnasNB/qarinah/blob/main/PRIVACY.md), and [threat boundaries](/AjnasNB/qarinah/blob/main/docs/ARCHITECTURE.md).\n\n| Command | Purpose |\n|---|---|\n`qarinah init [path]` |\nOpt a workspace into metadata or content capture |\n`qarinah policy` / `qarinah trust` |\nReview and approve the exact machine-local capture policy |\n`qarinah record` |\nAppend a validated decision, source, claim, approval, or other event |\n`qarinah hook codex|claude` |\nNormalize one supported host lifecycle event from stdin |\n`qarinah scan` |\nRecord a bounded project structure snapshot |\n`qarinah build` |\nVerify and rebuild graph, index, and Markdown |\n`qarinah query` |\nCompile a coverage-aware, cited, budgeted context pack |\n`qarinah export okf` |\nBuild a deterministic Markdown interoperability bundle |\n`qarinah doctor` / `qarinah status` |\nVerify integrity or inspect current state |\n`qarinah untrust` |\nRevoke local capture permission without deleting project files |\n\nRun:\n\n```\nnpm run evaluate:software-tasks\nnpm run evaluate:long-document\nnpm run evaluate:context\nnpm run benchmark\n```\n\n| Software task | Full history + current sources | Qarinah + same sources | Reduction |\n|---|---|---|---|\n| React accessibility edit | 73,765 estimated tokens | 1,025 estimated tokens | 98.61% |\n| Database schema migration | 73,703 | 968 | 98.69% |\n| TypeScript codebase refactor | 73,628 | 895 | 98.78% |\n| Web research to implementation | 73,693 | 963 | 98.69% |\n| Production regression debugging | 73,697 | 954 | 98.71% |\n| Governed release preparation | 73,627 | 877 | 98.81% |\nWeighted total |\n442,113 |\n5,682 |\n98.71% |\n\nThe software-task evaluator keeps the required current source snippets on both sides and replaces only accumulated-history replay. Its estimates use `ceil(characters / 4)`\n\n; they are not provider usage receipts. The release also successfully verifies exact retrieval, typo tolerance, graph evidence, conflict visibility, and supersession. See [BENCHMARKS.md](/AjnasNB/qarinah/blob/main/docs/BENCHMARKS.md) for the committed sources, machine-readable results, commands, and arithmetic.\n\nThe long-document evaluator adds a fixed 600-token ceiling over a deterministic 34,751-estimated-token handbook fixture. All 16 exact and typo-tolerant lookups return the cited answer-bearing section at rank 1, with an average pack of 534 estimated tokens and a worst-case estimated reduction of 98.4%; four unsupported questions fail closed when the caller requires direct evidence coverage. This is a segmented synthetic retrieval fixture - not whole-book summarization, native PDF ingestion, or provider-billed token usage.\n\nQarinah source code is available under [Apache License 2.0](/AjnasNB/qarinah/blob/main/LICENSE). Apache-2.0 permits commercial use, modification, and redistribution under its terms. Copyright, a contributor sign-off policy, product execution, and a distinct brand can preserve project stewardship, but an open-source license cannot prohibit compliant commercialization.\n\nSee [contributing](/AjnasNB/qarinah/blob/main/CONTRIBUTING.md), [governance](/AjnasNB/qarinah/blob/main/GOVERNANCE.md), [third-party notices](/AjnasNB/qarinah/blob/main/THIRD_PARTY_NOTICES.md), [brand use](/AjnasNB/qarinah/blob/main/TRADEMARKS.md), [support](/AjnasNB/qarinah/blob/main/SUPPORT.md), and [launch gates](/AjnasNB/qarinah/blob/main/docs/LAUNCH.md).", "url": "https://wpnews.pro/news/i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it", "canonical_source": "https://github.com/AjnasNB/qarinah", "published_at": "2026-07-25 18:05:26+00:00", "updated_at": "2026-07-25 18:22:44.440364+00:00", "lang": "en", "topics": ["developer-tools", "large-language-models", "ai-agents"], "entities": ["Qarinah", "Codex", "Claude Code", "MCP"], "alternates": {"html": "https://wpnews.pro/news/i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it", "markdown": "https://wpnews.pro/news/i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it.md", "text": "https://wpnews.pro/news/i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it.txt", "jsonld": "https://wpnews.pro/news/i-was-paying-too-much-for-claude-and-codex-here-is-how-i-reduced-90-of-it.jsonld"}}