Skip to main content
Glama
README.md
# Token Saver

[![CI](https://github.com/tobertraubling2004-design/Token_Saver/actions/workflows/ci.yml/badge.svg)](https://github.com/tobertraubling2004-design/Token_Saver/actions/workflows/ci.yml)
[![License: MIT](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)

A Claude Code plugin and [MCP](https://modelcontextprotocol.io) server that makes Claude **read less and still understand more**. Instead of whole files, long logs or giant JSON, Claude gets compact views: outlines, single functions, grouped search hits, log digests and JSON shapes.

Read-only, sandboxed to the project folder, no network.

## Measured savings

Measured with `npm run bench` on four public repositories (express, requests, godot-demo-projects, ripgrep), three real logs (npm, pip, vitest) and three JSON files (a lockfile, PyPI and npm registry metadata):

| Task | Cases | Built-in tools | Token Saver | Saved |
| --- | ---: | ---: | ---: | ---: |
| Understand a file (outline instead of Read) | 129 | 571k | 53k | **91%** |
| Read one function (outline + read_symbol) | 129 | 571k | 91k | **84%** |
| Edit one function (outline + read_symbol + partial Read) | 129 | 571k | 128k | **78%** |
| Search a symbol (search_compact instead of Grep) | 40 | 68k | 13k | **81%** |
| Log / command output (digest) | 3 | 24k | 3.6k | **85%** |
| JSON structure (json_shape instead of Read) | 3 | 27k | 2.8k | **90%** |

How it was measured, so you can judge it:

- Files are source files with at least 150 lines; for small files the saving is smaller and reading them is fine.
- Baselines are conservative: Read is capped at 2,000 lines / 25k tokens, Grep at 250 lines, Bash at 30,000 characters, as in Claude Code. Real full reads are often larger.
- Tokens are counted with the o200k tokenizer because Claude's tokenizer is not public. Absolute numbers differ, ratios are comparable.
- The "Edit" row counts the extra partial Read that Claude Code's Edit tool needs.
- Fixed cost: the tool definitions take about 600 tokens per request (o200k), which one avoided full read usually pays back.

## Install

### Claude Code plugin (recommended)

```
/plugin install token-saver --marketplace tobertraubling2004-design/Token_Saver
```

On Claude Code older than 2.1.275: `/plugin marketplace add tobertraubling2004-design/Token_Saver`, then `/plugin install token-saver@token-saver`.

The plugin brings the bundled server (no `npm install`) and a `Read` hook: the first time in a session Claude tries to read a large file (≈6k tokens or more) in full, the hook suggests the cheaper tools. Repeating the same Read goes through. Set `TOKEN_SAVER_GUARD=off` to disable it, or `TOKEN_SAVER_GUARD_TOKENS=12000` to change the threshold.

### MCP server only

Requires Node.js 20+.

```bash
git clone https://github.com/tobertraubling2004-design/Token_Saver.git
cd Token_Saver && npm install && npm run build

# Claude Code
claude mcp add token-saver -- node /path/to/Token_Saver/dist/index.js
```

Claude Desktop (`claude_desktop_config.json`):

```json
{
  "mcpServers": {
    "token-saver": {
      "command": "node",
      "args": ["/path/to/Token_Saver/dist/index.js", "--root", "/absolute/path/to/project"]
    }
  }
}
```

## Tools

| Tool | Instead of | Returns |
| --- | --- | --- |
| `project_map` | `ls -R`, opening files to look around | Folder tree with token cost per entry (gitignore applied); on a file, its token cost |
| `file_outline` | Reading a file to see what is in it | Classes, functions, types, headings with line numbers |
| `read_symbol` | Reading a file for one function | Only that function's or class's body |
| `read_slice` | Reading a file for lines X–Y | Numbered line range, max 400 lines |
| `search_compact` | Raw grep dumps | Hits grouped per file, max 8 per file, long lines clipped around the match |
| `digest_log` | Pasting logs | Repeated lines grouped (`×200`), errors and warnings kept, head and tail |
| `json_shape` | Reading big JSON/JSONL | Keys, array lengths, maps collapsed, one sample per field |

Command output can be condensed before it reaches the context:

```bash
npm test 2>&1 | token-saver-mcp digest        # or: node <plugin>/plugin/server.mjs digest
```

The server tells Claude the exact command in its instructions.

Outlines: TypeScript/JavaScript, Python, GDScript (Godot), C/C++ (incl. Unreal headers), C#, Java, Kotlin, Swift, Objective-C, Go, Rust, Lua, Ruby, PHP, shell, Markdown. Regex based: fast and dependency free, good for navigation, not a full parser.

## Configuration

| Setting | Effect |
| --- | --- |
| `--root <dir>` / `TOKEN_SAVER_ROOT` / `CLAUDE_PROJECT_DIR` / current dir | The only tree the server may read |
| `TOKEN_SAVER_QUIET=1` | Hide the `[-91%: …]` savings footer |
| `TOKEN_SAVER_NO_GITIGNORE=1` | Do not apply `.gitignore` rules |

## Safety

- Read-only: no writes, no shell, no network.
- Paths outside the root, including symlinks pointing out, are rejected.
- Binary files, lockfiles and build/cache folders are skipped.
- Bad input never crashes the server; errors come back as tool results.

## Development

```bash
npm install
npm test               # vitest
npm run typecheck
npm run build          # dist/ for npm
npm run build:plugin   # plugin/server.mjs, commit it
npm run bench -- --repos <dir...> --logs <file...> --json <file...>
```

See [CONTRIBUTING.md](CONTRIBUTING.md) and [CHANGELOG.md](CHANGELOG.md).

## License

[MIT](LICENSE)

TDQS

B3.4/5.0

Scored across 7 tools

Disambiguation5/5

Each tool targets a distinct inspection granularity: project tree, file outline, symbol body, line slice, grep search, log condensation, and JSON structure. The only apparent overlap is between file_outline/read_symbol/read_slice, but their descriptions make the boundaries clear. An agent can reliably choose the right tool.

Naming Consistency4/5

All names use consistent snake_case and are concise and readable. The pattern mixes noun-first names (project_map, file_outline, json_shape) with verb-first names (read_symbol, read_slice, search_compact, digest_log), but this is a minor deviation rather than confusion.

Tool Count5/5

Seven tools is well-scoped for a token-efficient codebase/log inspection server. Each tool covers a distinct exploration need without obvious redundancy.

Completeness4/5

The surface covers the core read-only inspection workflow: project structure, file outline, symbol extraction, line ranges, search, log summaries, and JSON shape. Minor gaps exist, such as no regex search or explicit multi-file/batch read operation, but agents can work around these with the provided tools.

Maintenance

ActivityMaintained
ResponsivenessNo recent community issues