⚡ trimtok
Universal, Local, Deterministic Context Compressor & Content Intake Shield for Autonomous AI Coding Agents
⚡ At a Glance: Before vs After
Autonomous coding agents burn over 60% of their context window budget on repetitive, low-entropy noise. trimtok compresses this in-process without losing a single line of actionable truth:
[pytest 200 tests] 56,000 chars ──► 320 chars (-99.4% cross-turn delta)
[FastAPI Traceback] 12,400 chars ──► 890 chars (-92.8% crash-site locked)
[Stripe API Array] 8,900 chars ──► 3,100 chars (-65.1% lossless TOON v2)
[Mixed-Schema JSON] 11,240 chars ──► 6,630 chars (-41.0% merged TOON table)
[Source Code 300 Fns] 13,500 toks ──► 2,400 toks (-82.2% multi-lang AST)
[Web Docs / Search] 15,200 chars ──► 1,800 chars (-88.1% tiered link shaving)
[JSON File 50 Cols] 12,002 toks ──► 6,225 toks (-48.1% file TOON)
[OpenAPI Document] 2,746 toks ──► 1,367 toks (-50.2% JSON minify)
[Build Log 400 Lines] 15,960 toks ──► 4,869 toks (-69.5% adaptive budget)
[MCP Schema 25 Tools] 5,800 toks ──► 780 toks (-86.5% bounded proxy)
[Repo Exploration 4k] 12,000 toks ──► 480 toks (-96.0% 2k-budget map)
[22k-token source] 21,999 toks ──► 571 toks (-97.4% intent retrieval)
Measured across a 32-payload production corpus (1,135,441 characters): 73.2% reduction with zero gate failures, of which every removed character is verifiable through trimtok_retrieve. Retrieval is billed only when the agent asks a question, taking the same corpus from 74.8% to 89.1% saved.
🏗️ How It Works
trimtok operates 100% locally and in-process using the Python standard library, RapidFuzz C++ alignment, tree-sitter AST parsing, and Zstandard compression. No external daemons, no Docker containers, and zero open network ports.
┌────────────────────────────────────────────────────────┐
│ Tier 0: Pre-Flight Context Shield (Zero Disk Footprint)│
│ ├── Bounded MCP Proxy: filters tools/list schemas │
│ └── Codebase Symbol Map: 2k-budget symbol directory map│
└──────────────────────────┬─────────────────────────────┘
▼
Tool / Terminal Output
│
▼
┌────────────────────────────────────────────────────────┐
│ Tier 1: In-Process Hot-Path (< 2 ms, fail-open ≤ 200ms)│
│ ├── 0. Content Policy Gate (secrets / edits verbatim) │
│ ├── 1. Cross-Turn Delta Engine (pytest, cargo test) │
│ ├── 2. Command-Specific Filters (git, npm, pip, etc.) │
│ ├── 3. Structured Traceback Pruning (locks crash-site) │
│ ├── 4. Lossless & Merged TOON v2 (JSON arrays) │
│ ├── 5. Multi-Language AST Skeletonizer (7 languages) │
│ └── 6. Tiered Web & Doc Link De-bloating │
└──────────────────────────┬─────────────────────────────┘
│ level: light │ normal │ aggressive
│ format: TOON │ minified JSON
┌────────────────┴────────────────┐
▼ ▼
Agent Context Window SQLite WAL + Zstandard
(Clean, dense token stream) (Tier 2 Recovery via `#c1`)
📑 Table of Contents
🏛️ Architecture & Benchmarks |
⚡ 4 Engineering Pillars |
🛠️ Setup & Operations |
🥊 Architecture & Benchmark Matrix: trimtok vs Industry Engines
Empirical head-to-head benchmarks measured on identical production workloads:
| Capability / Benchmark | trimtok v5.6.0 🌟 | claw-compactor v7.0 (OpenClaw) | RTK v1.1.0 (Rust) | headroom v0.42.0 (Python) | skim v2.10.0 (Rust) | sqz v2.1.1 (Rust) | tokenfold (Python/Rust) |
|---|---|---|---|---|---|---|---|
| Execution Layer | In-process hook + CLI | 14-Stage Pipeline + Node Proxy | Subprocess CLI | Python library / Proxy | Subprocess CLI | Subprocess CLI | Python FFI library |
| Uniform JSON (500 rows) | 55.3% saved (TOON v2) | 81.9% (lossy sampling) | 99.6% (truncated) | 61.7% saved | N/A | ~55% saved | 55.7% saved |
| Mixed JSON (450 rows) | 41.0% – 44.7% (merged TOON) | ~40% – 50% | 99.6% (truncated) | 46.3% saved | N/A | 42.6% – 45.2% | 24.0% saved |
| Code AST (300 functions) | 82.2% (AST stubs) | 18.4% – 25.0% (whitespace/comments) | 0% (or wipes 100%) | N/A | 82.2% (signatures) | N/A | N/A |
| Cross-Turn Delta Mode | ✅ [tt:delta] (>95%) |
❌ None (per-message log filter) | ❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Framework Traceback Prune | ✅ 77.0% (locks crash-site) | ✅ LogCrunch (stack/error scan) | ❌ Stripped or raw | ❌ None | ❌ None | ❌ None | ❌ None |
| Command-Specific Filters | ✅ 7 commands (git, npm, pip, etc.) |
⚠️ 3 crunchers (Log/Diff/Search) | ✅ 12 commands | ❌ None | ❌ None | ❌ None | ❌ None |
| Full Original Retrieval | ✅ Content-addressed (#c1) |
⚠️ RewindStore (24-char hex) |
❌ Lost permanently | ⚠️ CCR via MCP | ❌ Lost permanently | ⚠️ §ref dedup | ✅ Exact bytes |
| Recovery Storage Backend | ✅ SQLite WAL + Zstd (Persistent on-disk) | ⚠️ In-memory RAM (OrderedDict LRU) |
❌ None (Lossy) | ⚠️ Local disk cache | ❌ None (Lossy) | ⚠️ In-stream reference map | ⚠️ In-memory RAM |
| Full-Text Payload Search | ✅ SQLite FTS5 BM25 (< 10 ms) |
⚠️ In-memory substring scan | ❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Task-Aware Code Map | ✅ trimtok map --focus |
❌ None | ❌ None | ❌ None | ⚠️ Full AST (unbudgeted) | ❌ None | ❌ None |
| Decision-Equivalence Eval | ✅ 3/3 preserved @ 91% cut | ⚠️ SWE-bench partial | ❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Intent-Addressed Retrieval | ✅ --intent (93–97%) |
⚠️ Keyword search (store.search) |
❌ None | ❌ None (full block only) | ❌ None | ❌ None | ❌ None |
| Content Policy Gate | ✅ Secrets & edits verbatim | ⚠️ Annotations only (noqa, TODO) |
❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Adaptive Level | ✅ Pressure-scaled (light/normal/aggressive) | ⚠️ Stage gating (should_apply) |
❌ Static CLI flags | ❌ Fixed heuristics | ❌ Static CLI depth | ❌ Static ratio target | ❌ Static threshold |
| Model-Aware Format | ✅ auto / always / never |
❌ None (generic token opt) | ❌ Single format | ❌ Single format | ❌ Single format | ❌ Single format | ❌ Single format |
| KV-Cache / Prompt Alignment | ✅ trimtok kv-lock (, code-safe) |
✅ QuantumLock (prefix-stable) |
❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Bounded MCP Tool Proxy | ✅ trimtok mcp-proxy |
❌ None | ❌ None | ❌ None | ❌ None | ❌ None | ❌ None |
| Codebase Symbol Map | ✅ trimtok map (<38ms, budgeted) |
❌ None | ❌ None | ❌ None | ⚠️ Full AST (unbudgeted) | ❌ None | ❌ None |
| Fix-Accuracy Benchmark | ✅ 8/8 locate (eval/fix_accuracy.py) |
✅ SWE-bench instance tests | ❌ Unit tests only | ❌ Synthetic only | ❌ Unit tests only | ❌ Unit tests only | ❌ Token counts only |
| In-Process Latency | < 2 ms (micro) | ~50 – 88 ms | 10 – 50 ms (process) | ~9,054 ms (73x slower) | ~259 ms (process) | ~437 ms (process) | 660 – 860 ms |
| Zero Network Ports | ✅ 100% portless | ❌ Opens HTTP port (Node proxy) | ✅ Portless | ❌ Opens HTTP port | ✅ Portless | ❌ Opens HTTP/Web | ✅ Portless |
Where trimtok Excels
- In-Process & Sub-2ms: Direct hook invocation with zero subprocess overhead (headroom takes ~9s, sqz takes ~450ms, claw-compactor takes ~50ms).
- Cross-Turn Stateful Delta: Re-running test suites (
pytest,cargo test) only prints active errors and diffs vs prior turn, slashing >95% tokens. - Persistent Zero Data Loss Guarantee: Everything transformed is stored into local SQLite WAL + Zstandard (
FastCCRStore). Unlike in-memory caches that vanish on process exit or across subagents, trimtok originals remain durable and recallable via#c1. - Intake Shielding: Automatically prunes link bloat and boilerplate headers on
web_extractandread_filewithout offset drift. - 3-Tier Lifecycle Protection: Guards System Prompts (KV-Cache alignment & Bounded MCP schema pruning), Exploratory Turns (Codebase Map), and Hot-Path Payloads simultaneously.
Where trimtok is Weaker
- Language Coverage on AST: trimtok supports 7 languages (Python, JS/TS, Go, Rust, Java, C, C++).
skimsupports 17 languages andclaw-compactorsupports 16 languages via native tree-sitter. - Command Filter Coverage: trimtok has 7 targeted command filters (
git log,git status,ls,npm,pip,find,docker ps).RTKprovides 12 command-specific heuristics. - Extreme Mixed-JSON Compression:
headroomachieves 46.3% on heterogeneous JSON via smart_crusher transforms, while trimtok achieves 41.0% – 44.7% with merged TOON. - NLP Perplexity Benchmarks:
claw-compactorpublishes empirical ROUGE-L scores (0.653 @ 0.3) across SWE-bench tasks; trimtok prioritizes deterministic structural fidelity and exact code recoverability over lossy perplexity pruning. - Model-Awareness is a Heuristic:
toon_mode: autokeys off the model family name, not a measured per-model capability. TOON is plain text and every model can read it; the setting only decides which format is likely to survive a long context best. - Fix-Accuracy Needs a Live Model: the
LOCATEstage runs offline and deterministically, but theFIXstage that proves a patch actually works requires a reachable model endpoint.
⚡ Core Engineering Capabilities
Pillar 1: Terminal & Command Compression
1. Cross-Turn Command Delta Engine (compress_terminal)
When an agent edits code and re-runs test suites or build commands:
- Raw Output: 56,000+ characters of unchanged passing dots.
- trimtok Output (~300 characters — >95% reduction):
[tt:delta cmd="pytest" sim=99% +#1 -#1 !#1 #c2 #c1]
[tt:legend] Delta vs previous run: + added, - resolved, ! still failing; refs = full original via trimtok_retrieve.
--- STILL FAILING / ACTIVE ERRORS (1) ---
! FAILED tests/test_auth.py::test_login - AssertionError: expected 200 got 401
--- ADDED / CHANGED IN THIS TURN (+1) ---
+ ===== 1 failed, 200 passed in 43.2s =====
--- RESOLVED / REMOVED (-1) ---
- ===== 1 failed, 200 passed in 42.1s =====
2. Command-Specific Output Filters
High-volume CLI tools are filtered to essential summaries backed by CCR retrieval:
git log→ commit count, author digest, date range.git status→ current branch, staged/unstaged/untracked counters.ls -la→ file/folder count breakdown by extension.npm install / list→ package installation summary and dependency counts.pip install / list→ installed package names and satisfied requirements count.find→ matched file counts grouped by extension.docker ps / container ls→ running container count, image breakdown, and service names.
3. Structured Traceback Pruning
Internal framework frames (FastAPI, Starlette, Node modules) collapse into compact summaries while strictly locking the entrypoint, user project code, and exact exception crash site (77% reduction):
Traceback (most recent call last):
File "/workspace/app/api/endpoints.py", line 45, in handle_payment
result = await service.charge_card(req)
[... 10 framework frames omitted ...]
File "/workspace/app/services/billing.py", line 88, in charge_card
return gateway.execute_transaction(card_id, amount)
ZeroDivisionError: division by zero
Pillar 2: Content & Code Intake Shield
4. Tiered Web & File Intake (read_file & web_extract)
- Inline URL De-bloat: Converts verbose links
[Anchor Text](https://very-long-url/path "Title")into cleanAnchor Text, cutting 35% – 45% of markdown link bloat in 2–4 ms. - Heading + 2-Line Factsheet Digest: Keeps headings, tables, code blocks, and the first 2 descriptive lines per section, folding excessive narrative into line-anchored CCR
#refstubs (76% – 96% token reduction). - Patch-Safe License Stripping: Automatically removes open-source license headers and divider comments on files < 14KB with Zero Offset Drift.
5. Multi-Language AST Code Skeletonizer
For code files ≥ 2KB, trimtok parses the structural AST using tree-sitter:
- Supported Languages: Python, JavaScript/TypeScript, Go, Rust, Java, C, C++.
- Zero Loss of Structure: Retains all class definitions, function signatures, interfaces, imports, and docstrings.
- Folds Oversized Bodies: Function implementations ≥ 8 lines fold into clean CCR-referenced stubs, preserving line structure for patch safety.
6. Lossless & Merged-Schema TOON v2
Converts nested JSON arrays into columnar tables validated by in-memory equality roundtrips:
- Uniform Arrays: 55% – 57% token reduction.
- Mixed Schemas (Merged TOON): Automatically unifies heterogeneous object structures into a single table with null-filled gaps, achieving 41% – 44.7% savings without splitting into disjoint buckets.
- Wide Tables: Up to 128 columns columnarize losslessly (50 columns × 20 rows: 48.1%).
- Deep Cells: Nested objects longer than the inline cap are stored behind an explicit
=marker instead of rejecting the whole table, so GitHub- and Stripe-shaped payloads compress too (28.8% on a 60-row repository listing). - JSON Files:
read_fileon a.jsonpath routes through the same codec, or whole-document minification for non-uniform objects (OpenAPI document: 50.2%). Both paths are round-trip verified and leave a resolvable#ref.
[tt:legend] TOON table (lossless): @prefix(~/)=https://example.com/items/
@data.results[3]{id,title,url,tags}:
0|Item 0|~/0|["dev","lead"]
1|Item 1|~/1|["qa"]
2|Item 2|~/2|["pm","ops"]
Pillar 3: Zero Data Loss & Self-Healing Telemetry
7. Content-Addressed Context Recovery (trimtok_retrieve)
Every transformed payload is preserved in a local SQLite WAL + Zstandard database (~/.trimtok/trimtok_ccr_v2.sqlite3). Agents recall original bytes anytime:
# Retrieve original or targeted slices directly from shell
trimtok retrieve "#c1"
trimtok retrieve "#c1" --section errors # Error lines with surrounding context
trimtok retrieve "#c1" --section diff # Unified diff hunks with headers
trimtok retrieve "#c1" --section tail # Last N lines
trimtok retrieve "#c1" --grep "ConnectionReset" # Bounded regex search
trimtok retrieve "#c1" --offset 50 --limit 30 # Line-numbered pagination
# Answer a question instead of paging through the file
trimtok retrieve "#c1" --intent "which functions parse JSON" --intent-budget 80
Long-horizon workflows can pin critical CCR references to protect them from automated TTL expiration sweeps:
import trimtok.ccr as ccr
ccr.pin("#c1") # Protects chunk from background TTL cleanup
ccr.unpin("#c1") # Restores default TTL lifecycle
--intent ranks lines by stemmed token overlap with the question and boosts definition and heading lines, so a signature arrives with its body. On a 21,999-token source file, "which functions does this file define" returns 1,458 tokens (93.4% saved) and "how is json minified" returns 571 tokens (97.4% saved), each containing the answer line rather than a truncated guess.
8. Autonomous Telemetry & Diagnostics (gain & discover)
trimtok self-monitors every transformation in ~/.trimtok/usage.jsonl:
trimtok gain: Breaks down real savings by output shape, tool hook, and command family, highlighting compression bottlenecks.trimtok discover: Scans production telemetry for high-frequency, low-savings patterns and recommends targeted filters.- Distributed Trace Correlation (
TRINITY_TRACE_ID): Automatically capturesTRINITY_TRACE_IDfrom the environment and attachestrace_idto each telemetry record, enabling unified correlation across Context, Memory, and Skill governance layers.
9. Fail-Open Budget Guards
- Strict 200 ms Monotonic Deadline (
guard_ms: 200.0): If compression exceeds the deadline or RapidFuzz alignment is slow, trimtok aborts instantly and emits raw output. - Zero Agent Freezes: No timeout cascades, no hangs, no broken builds.
Pillar 4: Policy, Adaptivity & Verification
10. Content Policy Gate
Not every payload should be compressed. Before any transformation runs, trimtok classifies the input and keeps byte-exact what would lose its meaning if a single character moved. These return gate=passthrough_policy with a named reason, never a silently mangled payload:
| Class | Matched by | Reason |
|---|---|---|
| Credentials | .env, .npmrc, .netrc, *.pem, *.key, id_rsa, credentials.* |
secret_path |
| Inline secrets | AWS AKIA…, GitHub ghp_…, OpenAI sk-…, Slack xox…, JWT eyJ…, PEM blocks, password = … |
secret_value |
| Security policy data | security/, policies/, auth/, rbac/ containing YAML, JSON, TOML, INI, Rego or Terraform |
security_path |
| Edit instructions | patch, edit_file, write_file, apply_patch, or any unified diff |
edit_tool / patch_payload |
Source code under security/ or auth/ still compresses, because the AST skeletonizer keeps every signature and leaves a resolvable #ref — a 2,000-line auth.py remains navigable rather than being excluded wholesale. Detection is deliberately narrow: a false positive costs one uncompressed payload, while a false negative would rewrite a credential in place and make it impossible to copy verbatim.
11. Adaptive Compression Level
Compression strength follows the remaining context budget instead of applying one fixed policy to every turn. context_pressure (0.0 – 1.0, supplied per call by the host hook or set in config) selects a level that scales the terminal line budget and the AST body-fold threshold:
| Pressure | Level | Line budget | Body fold threshold |
|---|---|---|---|
| < 0.35 | light |
×1.6 | 20 lines |
| 0.35 – 0.75 | normal |
×1.0 | 8 lines |
| > 0.75 | aggressive |
×0.55 | 4 lines |
Measured on a 400-line unique build log (15,960 tokens): light 51.5% (195 lines kept), normal 69.5% (123 lines), aggressive 83.1% (69 lines). Set adaptive_enabled: false to pin the level at normal.
12. Model-Aware Output Format
TOON is plain text, so every model can read it; what differs is how well a model holds a columnar table together over a long context. toon_mode decides which format the agent receives:
| Mode | Behaviour |
|---|---|
auto (default) |
TOON for model families with a track record on columnar text; minified JSON otherwise |
always |
TOON whenever it wins on tokens |
never |
Always minified JSON |
model_family supplies the target (e.g. claude, gpt, qwen). When it is unset, auto keeps TOON enabled so no existing deployment silently changes format. Both formats are lossless: the same 30 × 20 JSON payload produced 3,881 characters as TOON versus 8,401 as minified JSON, with identical round-trip equality.
13. Retention Controls
Recovery storage is bounded explicitly rather than growing until someone notices:
trimtok purge --older-than 24 # Remove entries older than 24 hours
trimtok purge --max-mb 50 # Evict oldest entries until the store is under 50 MB
--max-mb alone evicts by age without wiping the store first. Defaults: 1,000 entries, 50 MB, 24 hours; the retention window is configured with ccr_ttl_hours.
14. Fix-Accuracy Verification
Token counts say nothing about whether an agent can still do the job. eval/fix_accuracy.py injects a known regression into a real module, compresses it, and asks whether the bug is still fixable:
LOCATE(default, no model required) — verifies the buggy line, its enclosing signature, its line number and neighbour context are either visible in the compressed view or reachable through#ref. A payload that hides the bug without a reference fails, because the agent would have to re-read the file.FIX(--llm) — sends the compressed view to a model, takes back the corrected line, patches the real module, imports it and runs a behavioural predicate. A pass means the repaired code works, not that the text looks plausible.
Current result: 8/8 locate accuracy across Python, TOON codec, dedup and sentinel modules, at 53.8% token reduction. The suite includes a negative control (test_wrong_patch_fails) so a benchmark that cannot fail is itself caught.
🛠️ First-Time Setup (5 Minutes)
Step 1: Install Trimtok
pip install trimtok
Step 2: Run Unified Client Setup Wizard
Automatically configures the local SQLite WAL store, verifies Zstandard acceleration, and registers the stdio MCP server across all detected AI coding environments:
trimtok install
Auto-detects and registers:
- Claude Code (
~/.claude.json) & Claude Desktop - Cursor (
~/.cursor/mcp.json), Windsurf, and VS Code (Copilot) - Google Antigravity & Antigravity IDE (
mcp_config.json) - Gemini CLI (
settings.json) & Codex CLI (config.toml) - OpenCode & Cline
Step 3: Verify Registration & Storage Health
trimtok clients
trimtok status
⚙️ Native Hermes Agent Plugin Configuration
To install trimtok as a native plugin in Hermes Agent:
# Windows (PowerShell)
git clone https://github.com/Stxyu-p/trimtok.git "$env:LOCALAPPDATA/hermes/plugins/trimtok"
# Linux / macOS (Bash)
git clone https://github.com/Stxyu-p/trimtok.git ~/.hermes/plugins/trimtok
# Enable plugin in Hermes
hermes plugins enable trimtok
Configuration Options (~/.hermes/config.yaml or plugin.yaml)
plugins:
entries:
trimtok:
settings:
enabled: true # Master toggle for Trimtok compression
phase2_enabled: true # Enable tool-result compression (TOON, AST, Intake)
guard_ms: 200.0 # Monotonic deadline budget (fail-open if exceeded)
min_chars: 2048 # Minimum character threshold before compression fires
toon_enabled: true # Enable Lossless TOON v2 JSON transcoding
toon_mode: auto # Model-aware format: auto | always | never
model_family: "" # Target model family (claude, gpt, qwen); empty keeps TOON on
policy_enabled: true # Keep secrets, security data and edit payloads byte-exact
adaptive_enabled: true # Scale compression strength with context pressure
context_pressure: 0.0 # Fraction of context window used (0.0 - 1.0)
delta_enabled: true # Enable Cross-Turn Command Delta engine
delta_threshold: 0.65 # Similarity ratio threshold for delta mode (0.50 - 1.00)
mask_enabled: true # Enable stale turn span expiration
mask_keep_turns: 2 # Retain full unmasked history for N active turns
ccr_ttl_hours: 24 # Retention window for the recovery store
ccr_max_bytes: 52428800 # Hard ceiling for the recovery store (50 MB)
ccr_max_entries: 1000 # Maximum cached payloads
excluded_commands: [] # Exact command stems to bypass compression
excluded_tools: [] # Tool names to leave 100% untouched
💻 Slash Commands & Standalone CLI
Hermes In-Chat Slash Commands
/trimtok status: Displays active CCR database size, cache entries, Zstandard compression metrics, and engine health./trimtok usage: Shows live telemetry breakdown across terminal and tool hooks (events, folds, chars saved, top gates)./trimtok gain: Detailed savings breakdown by shape, tool, and command — identifies bottlenecks./trimtok discover: Scans telemetry → finds low-savings shapes/tools → suggests targeted filters./trimtok purge: Purges expired cache entries and vacuums the SQLite WAL database. Accepts--older-than <hours>and--max-mb <size>./trimtok recall <#ref>: Retrieves original output by CCR reference (alias forretrieve).
Standalone CLI Wrapper (trimtok wrap)
Run noisy developer commands directly in your terminal or CI/CD pipelines without Hermes:
# Wrap test suites with automatic terminal compression and CCR storage
trimtok wrap -- pytest tests/
trimtok wrap -- cargo test
# Strictly preserves child process exit code
trimtok wrap -- npm test || echo "Failed with exit code $?"
# Retrieve original output anytime
trimtok retrieve "#c1"
trimtok recall "#c1" --offset 50 --limit 30
# Sub-millisecond SQLite FTS5 search across all captured payloads
trimtok search "ConnectionRefused"
trimtok search "AssertionError in auth" --limit 3
KV-Cache Prompt Stabilizer (trimtok kv-lock)
Lock system prompt prefixes to maximize prompt-cache hit rates (up to 90% cost reduction on Anthropic, Gemini, and DeepSeek) by replacing dynamic dates, times, and UUIDs outside code blocks with stable placeholders, relocating their original values to a delimited appendix at the tail:
# Stabilize a system prompt file or stdin
trimtok kv-lock prompt.txt
# Pipe through shell
cat prompt.txt | trimtok kv-lock
Output preview:
You are an expert software engineer.
System started on <date> at <time>.
Session ID: <uuid>
---
<!-- kv-lock: dynamic context -->
date: 2026-11-05
time: 14:30:00
uuid: 550e8400-e29b-41d4-a716-446655440000
<!-- end kv-lock -->
Task-Aware Codebase Map (trimtok map)
Scan repository structure and output top-level symbols grouped by directory within a strict character budget (default 2,000 characters, executed in < 38 ms). Supports --focus to dynamically prioritize target file imports and reverse references at the top of the map:
# Generate compact symbol map of current directory
trimtok map .
# Task-aware focus: elevate service.py and its dependencies to the top
trimtok map . --focus src/service.py --budget 1200
Output preview:
Codebase map (4 directories):
trimtok/: detect_kind, compress_agent_payload, main, default_dir, build_codebase_map, filter_mcp_message, handle
eval/: declared_hidden, add, tok, verify_patch_safety, refs_in, run_test
trimtok/strategies/: minify_lossless, strip_signatures_rtk, shave_tiered
Bounded MCP Stdio Proxy (trimtok mcp-proxy)
Intercept stdio JSON-RPC communication between any coding harness and third-party MCP servers to prune bloated tool schemas from the model's system prompt:
# Allow only essential tools from a sprawling server
trimtok mcp-proxy --allow "codegraph_explore" -- npx -y @colbymchenry/codegraph
# Deny diagnostic/admin tools that waste system prompt tokens
trimtok mcp-proxy --deny "ctx_doctor,ctx_stats,ctx_purge" -- npx -y context-mode
Drop-in configuration for mcp.json / opencode.json:
{
"mcpServers": {
"context-mode": {
"command": "python",
"args": [
"-m", "trimtok", "mcp-proxy",
"--deny", "ctx_doctor,ctx_stats,ctx_purge",
"--", "npx", "-y", "context-mode"
]
}
}
}
Command Rewriting (trimtok rewrite)
Prints a noise-reduced form of a command without executing it, for use in shell aliases or CI scripts:
trimtok rewrite -- pytest tests/ # -> pytest tests/ -q --tb=short
trimtok rewrite -- git log # -> git log --oneline -n 25
Explicit flags are respected: trimtok rewrite -- pytest -v returns pytest -v unchanged. trimtok wrap applies the same rewrite before execution.
🧪 Verification
Every number in this README is reproducible from the repository:
python eval/eval_real.py # Per-payload reduction + gate failures on the 32-payload corpus
python eval/audit_honesty.py # Claimed vs proven reduction; unproven characters must be 0
python eval/steps.py # raw -> hook -> intent retrieval, per payload
python eval/fix_accuracy.py # Can an agent still fix the bug? (LOCATE, no model needed)
python eval/decision_eval.py # Decision-equivalence: action still visible after compression
python eval/probe_ceiling.py # Are folded lines announced and ref-reachable?
pytest tests/ # 168 tests (pip install -e ".[dev]" first)
The honesty audit is the load-bearing check: it recomputes the claimed reduction from the recovery store and reports any character that was removed without a resolvable reference. Run eval_real.py immediately before audit_honesty.py against a fresh store — pointing both at the same empty TRIMTOK_DATA_DIR — so the audit scores exactly the corpus the first script produced. Current state — 73.19% claimed, 73.19% proven, 0 unproven characters, 0 gate failures, 0 silent line loss, 0 unannounced faults, 168/168 tests passing.
Storage note: the FTS5 index keeps a plaintext copy of each payload so
snippet()can highlight matches, so on-disk usage is roughlycompressed payloads + plaintext index. Both are counted bytrimtok status(bytes,payload_bytes,fts_bytes) and both are included in theccr_max_bytesceiling, so the cap is enforced against the real footprint rather than the compressed half of it.
🌐 Part of the Global Agent Trinity
trimtok forms the Global Agent Trinity alongside MemCore and Skill Proof — unifying context, governed memory, and local skills across all your AI coding agents without daemons or open network ports:
| Pillar | Hub | Role |
|---|---|---|
| trimtok | ~/.trimtok |
Context Shield: Cuts terminal, traceback, web, and JSON bloat in-process with instant #c1 CCR recovery. |
| MemCore | ~/.memcore |
Governed Memory: Shared bitemporal memory with hard SQL scope boundaries, deterministic lexical recall, and Tainted Context Guard. |
| Skill Proof | ~/.skill-proof |
Skill Vault & Router: Sub-2ms deterministic router, multi-lingual negation veto, and OS NTFS read-only Immutable SOP protection. |
# Install and link all three pillars in one pass
pip install trimtok memcore-omnix skill-proof-router
trimtok install && memcore install && skill-proof install
📄 License
Distributed under the MIT License. Designed and crafted for robust, high-leverage autonomous software engineering.
Metadata
Release files for trimtok 5.6.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| trimtok-5.6.0.tar.gz | 192.4 kB | With provenance | Details for trimtok-5.6.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| trimtok-5.6.0-py3-none-any.whl | Python 3 | none | any | Details for trimtok-5.6.0-py3-none-any.whl |
Total release size: 322.8 kB
Release files / trimtok-5.6.0.tar.gz
| Download URL | trimtok-5.6.0.tar.gz |
|---|---|
| Size | 192.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91dcf00abd6d2972242551ce90c48fc927faf9f47da78d0696e8d5ef33a689d1
|
|
BLAKE2b-256 checksum How to use checksums |
11cb8e34fb8c098b37278991fc31232780e67dd64f260637bd46e8714b4516cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logRelease files / trimtok-5.6.0-py3-none-any.whl
| Download URL | trimtok-5.6.0-py3-none-any.whl |
|---|---|
| Size | 130.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
db7806acfba002d7dab5ea20b4d8f3a30b00333cf9ab336253a6d8f14528a468
|
|
BLAKE2b-256 checksum How to use checksums |
050256b6cc815742131a26eae7a4f02d113a0d048f7636b2539cb124b4911cc4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logSecurity for trimtok 5.6.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for trimtok-5.6.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Nov 6, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.