Skip to main content
Glama
README.md
# NoBleed — Universal AI Agent Token-Saver Plugin & Skill

![NoBleed — Stop the Token Bleed · Universal AI Agent Plugin](./assets/nobleed-banner.jpg)

Stop the token bleed across **any AI coding agent** (OpenCode, Antigravity, Claude Code, Cursor, Codex CLI, Gemini CLI, Windsurf, Cline, Roo Code, GitHub Copilot). NoBleed packages always-on terse-output rules, an 8-tool stdio MCP server, cross-agent lifecycle hooks, 13 RTK compression filters, cached zero-token project maps, and an optional local compression proxy into one lightweight TypeScript plugin — zero UI bloat.

## Quick Install (Any AI Agent)

```bash
npm install
npm run build

node dist/index.js agents                  # detect installed agents & status
node dist/index.js install opencode        # install into OpenCode (MCP + skill + AGENTS.md)
node dist/index.js install                 # auto-install on all detected agents (global)
node dist/index.js install --project       # install into the current repo (.agents + AGENTS.md + .mcp.json)
node dist/index.js install claude-code cursor antigravity  # specific targets
node dist/index.js uninstall               # cleanly remove NoBleed entries (backups kept as *.nobleed.bak)
```

Supported targets: `antigravity`, `claude-code`, `cursor`, `codex`, `gemini-cli`, `opencode`, `windsurf`, `cline`, `roo`, `copilot`, `universal` (or `all`). Use `--dry-run` to preview changes without writing files.

### Direct Native Installs

- **OpenCode**: `node dist/index.js install opencode` (installs `~/.config/opencode/skills/nobleed/`, updates `~/.config/opencode/AGENTS.md`, and registers `mcp.nobleed` in `opencode.json` while preserving commented `opencode.jsonc`)
- **Antigravity (`agy`)**: `agy plugin install .` (uses `plugin.json`, `mcp_config.json`, `hooks.json`, `rules/AGENTS.md`, `skills/nobleed/`)
- **Claude Code**: install via `.claude-plugin/plugin.json` / `.claude-plugin/marketplace.json` (includes `.mcp.json`, `hooks/hooks.json` with noisy-command auto-wrap, `skills/nobleed/`)
- **Gemini CLI**: `gemini extensions link .` (uses `gemini-extension.json` + `rules/AGENTS.md`)
- **Cursor**: copy `.cursor/rules/nobleed.mdc` + `skills/nobleed/` (or run `node dist/index.js install cursor`)
- **Codex / Windsurf / Cline / Roo / Copilot / Generic**: run `node dist/index.js install <agent>` or point your agent's skill loader at `skills/nobleed/SKILL.md`

## How It Saves Maximum Tokens

| Layer | Mechanism | Typical Savings |
|-------|-----------|-----------------|
| **Output tokens** *(3–8× costlier)* | Always-on Caveman/Ponytail rules (`rules/AGENTS.md`) + auto-escalation (`caveman-lite` → `caveman-full` at 20k tok → `caveman-ultra` at 60k tok) | **40–65%** |
| **Repo exploration** | `SessionStart` hook & `nobleed_project_map` inject a cached ~400–600 tok map instead of 10–30 `ls`/`tree`/`find`/`README` calls | **5k–25k tok/session** |
| **File reading** | `nobleed_read` `mode: "outline"` (~90% smaller symbols+lines), **Delta Re-Reads** (diff-only when a previously read file changes), query filtering, and unchanged repeat-read deduplication | **70–98%** |
| **Shell & test output** | `nobleed_run` / `nobleed exec` / `PreToolUse` auto-wrap apply 13 RTK filters, **Test-Run Failure Delta** (`FIXED`/`STILL FAILING`/`NEW`), **JSON/NDJSON Schema Folding** (schema + samples + anomaly outliers), **Blob & Stack-Cascade Folding** (data URIs, SVG paths, vendor frames, TS cascades), and >16KB disk spill | **50–99%** |
| **Runaway loops** | Loop guard stops identical failing tool calls after 3 repeats in 60s | Prevents retry bleed |

## MCP Tools (`nobleed mcp` / `nobleed-mcp`)

| Tool | Purpose |
|------|---------|
| `nobleed_project_map` | Cached repo orientation brief (`lite`/`standard`/`full`) — replaces `ls`/`tree`/`find` |
| `nobleed_run` | Run shell command with RTK filters, test-failure delta, JSON schema folding, blob/stack folding, and >16KB spill |
| `nobleed_read` | Targeted file read with `mode: "outline"`, delta re-reads on modified files, `query`, `start_line`/`end_line`, head/tail truncation, and unchanged repeat-read dedup (`force: true` bypasses cache) |
| `nobleed_compress` | Compress raw text/JSON/logs with `auto`, `json`, `blobs`, or named RTK filter |
| `nobleed_recall` | Bounded slice/query inspection of spilled >16KB outputs |
| `nobleed_stats` | Live token savings ledger, proxy stats, style level, and daily budget |
| `nobleed_search` | Search compression history and touched files |
| `nobleed_checkpoint` | Structured compact Markdown checkpoint for session handoff/compaction |

## CLI & Optional Compression Proxy

```bash
nobleed exec -- git diff                   # run command + RTK compress + preserve exit code
git log -n 30 | nobleed pipe               # compress any stdin stream
nobleed mcp                                # start stdio MCP server (or `nobleed-mcp`)
nobleed overview                           # view token savings summary
nobleed setup                              # optional: start local HTTP compression proxy (:8199)
```

### Environment Kill Switches

- `NOBLEED_HOOKS=off` — disable all lifecycle hooks
- `NOBLEED_AUTO_WRAP=off` — disable Claude Code `PreToolUse` noisy-command auto-wrapping
- `NOBLEED_PROJECT_MAP=off` — disable `SessionStart` project map injection
- `NOBLEED_GUARD=off` — disable repeated-tool-call loop guard (`NOBLEED_GUARD_REPEAT=3`)
- `NOBLEED_OUTPUT_STYLE=off` — disable proxy terse-output prompt injection

## Repository Layout

```text
├── plugin.json                    # Antigravity native plugin manifest
├── mcp_config.json                # Antigravity MCP server config
├── hooks.json                     # Antigravity lifecycle hooks
├── .claude-plugin/                # Claude Code plugin & marketplace manifests
├── .mcp.json                      # Claude Code / generic MCP config
├── hooks/hooks.json               # Claude Code / Gemini CLI hooks
├── gemini-extension.json          # Gemini CLI extension manifest
├── .cursor/rules/nobleed.mdc      # Cursor always-on rule
├── rules/AGENTS.md                # Universal always-on token-reduction rule
├── skills/nobleed/                # Universal Agent Skill (SKILL.md + references)
├── src/                           # Core TypeScript engine (MCP, hooks, installer, RTK, proxy)
└── tests/                         # Full Node test suite
```

## Development

```bash
npm run build       # Compile dist/ (index.js, mcp-entry.js, hook-entry.js)
npm run typecheck   # Strict TypeScript check
npm test            # Run full test suite
npm run verify      # Encoding check + typecheck + tests
```

Requires Node.js v22.13+. SQLite uses optional `better-sqlite3` or built-in `node:sqlite`.

## License

MIT