Skip to main content
Glama
README.md
# Inferni Token Saver

**Make your Claude usage go further: keep big files and web pages out of the chat, and let a free local model on your own PC do the heavy reading.**

[![Discord](https://img.shields.io/badge/Discord-Join%20Inferni-5865F2?logo=discord&logoColor=white)](https://discord.gg/WW8snzSW68)
[![Website](https://img.shields.io/badge/website-infernicantavit.com-ff6a00)](https://infernicantavit.com)
![Python 3.11+](https://img.shields.io/badge/python-3.11%2B-3776AB)
![MCP](https://img.shields.io/badge/MCP-server-8A2BE2)
![License: MIT](https://img.shields.io/badge/license-MIT-green)

Inferni Token Saver is a free, open-source [Model Context Protocol](https://modelcontextprotocol.io) server made
by [Inferni](https://infernicantavit.com) for hobbyists who use Claude (including the free plan) and want their
usage to last longer.

Every message you send makes Claude re-read the whole conversation, including every file and page it has
read so far. One big log or source file can cost tens of thousands of tokens, and it keeps costing on every
message after. Inferni Token Saver gives Claude cheaper ways to get the same answer:

- **Search instead of read:** find the lines that matter in a file or a whole folder.
- **Read a part:** just the lines needed, with line numbers.
- **Let a free local model read it:** [Ollama](https://ollama.com) or [LM Studio](https://lmstudio.ai) on your PC
  reads the big file or web page and Claude gets a short answer.
- **Start fresh without losing your place:** save a handoff note from a long chat, load it in a new one.
- **See what it saved:** a running tally of tokens kept out of your chats.

## Real results

Measured on an RTX 5060 Ti (16 GB) with `gemma4:12b` in Ollama:

| Job | Claude would have read | Claude read instead | Time |
|---|---|---|---|
| Question about a 1,000-line Python file ("how are start/stop requests handled?") | ~12,600 tokens | ~150 | 4 s |
| Which version and components are in a 6,300-line JavaScript library | ~53,500 tokens | ~85 | 44 s (read in 3 parts) |
| Summary of a project README | ~2,800 tokens | ~320 | 4 s |
| Find two function definitions in a 23-file project (`search_files`) | ~12,600 tokens | ~90 | 0.3 s |

All four answers were checked against the files and were correct. The first summary after the model has
been idle takes longer (up to a minute or so) while the model loads onto the graphics card.

### How answers are checked

A small local model can get things wrong, and Claude can't tell when it only sees the summary. So every
answer is checked on your PC before Claude sees it:

1. The local model cites line numbers for each point it makes.
2. Each point is checked against those lines: its key words must be there, and any name, version or identifier
   it mentions must exist in the text.
3. The model judges each point again, this time seeing only that point's evidence lines.

Claude gets the points that pass, with the **real lines** behind them, so it sees evidence rather than the
model's word. Points that don't pass are listed apart, under `unverified`, with the reason. Guesses about
things the text never mentions (such as "probably a firewall" for a log that doesn't mention one) are always
removed, along with any advice that rests on them. If nothing in an answer holds up, Claude gets the exact lines
that match the question instead.

**The cost/saving limit:** texts under 3,000 tokens come back whole, since a summary isn't worth the risk.
Above that, a result costs at most 15% of reading the whole text, and never more than 1,500 tokens.
Debugging and exact-detail questions get **careful mode**: more checking and more real lines (up to 25% or
2,500 tokens). The checking itself runs on your PC, so it costs a few seconds, not Claude usage.

Measured on 20 questions with known answers about real code, logs and libraries (`evals/`, RTX 5060 Ti,
`gemma4:12b`):

| | Correct | Claude read (all 20) | Saved | Time (all 20) |
|---|---|---|---|---|
| 0.2.0 (summaries unchecked) | 18 / 20 | 5,400 tokens | 99% | 258 s |
| 0.3.0 (checked, with evidence) | **20 / 20** | 9,000 tokens | 98% | 275 s |

The 20 files would have cost about 320,000 tokens to read in full. Of 116 points the model made, 8 were set
apart as unverified, including a wrong "firewall" guess that 0.2.0 passed straight to Claude.

**When it helps:** working with logs, code, documents and web pages, or long chats you can hand off.
**When it doesn't:** ordinary back-and-forth chat. Short files are returned whole, because a summary
wouldn't be cheaper.

---

## Contents

- [Tools](#tools)
- [Install](#install)
- [Set up a local model](#set-up-a-local-model)
- [Add it to your AI app](#add-it-to-your-ai-app)
- [Config file](#config-file)
- [Tips for getting the most out of your usage](#tips-for-getting-the-most-out-of-your-usage)
- [Safety](#safety)
- [Development](#development)

## Tools

| Tool | What it does | Needs a local model? |
|---|---|---|
| `file_info` | Size, lines and token cost of a file or folder, with advice on how to read it | No |
| `search_files` | Matching lines (with line numbers) from a file or a whole folder | No |
| `read_lines` | Part of a file, up to 400 lines at a time | No |
| `list_folder` | Files in a folder with sizes (skips `.git`, `node_modules`, venvs) | No |
| `summarize_file` | Local model reads a file and answers a question or summarises it | Yes |
| `summarize_url` | Local model reads a web page and answers a question or summarises it | Yes |
| `save_handoff` / `list_handoffs` / `load_handoff` | Carry a long chat's progress into a fresh chat | No |
| `check_log` | Errors in a log grouped by type, the latest traceback, and the likely cause and fix | Optional (for the explanation) |
| `summarize_project` | Overview of a project folder from its README, config and entry points | Yes |
| `summarize_changes` | What changed recently in a git project, including uncommitted work | Yes |
| `token_savings` | Savings summary (today, last 7 days, all time, by tool and day) and local model status | No |

Without a local model the search, read, log and handoff tools still work, so it's useful on any PC.

### Automatic handoffs

Long chats are the biggest hidden cost: every message re-reads the whole conversation. Inferni Token Saver
asks Claude to keep a handoff note up to date by itself, so starting a fresh chat never loses your place:

- Claude saves a handoff **without being asked** when a piece of work is finished or the chat has grown long,
  and tells you in one line.
- Saving again under the same title **updates the same note**, so each piece of work has one current handoff
  instead of a pile of old ones. The newest 50 notes are kept.
- Claude can't see how long a chat is from inside a tool, so the token saver counts instead: after 25 tool calls
  or about 30,000 tokens of results since the last handoff, results include a reminder (`handoff_due`). A
  pause of over 30 minutes starts the count again, since that's usually a new chat.
- In a new chat, say *"continue from my handoff"*, or just carry on with the same work and Claude offers to
  load the matching note.

Switch it off with `auto_handoff = false`, or change when reminders come with `handoff_after_calls` and
`handoff_after_tokens` in the config file.

### Shortcuts in Claude's + menu

Inferni Token Saver adds ready-made prompts to Claude Desktop's **+** menu, so common jobs are one click:
**Save a handoff**, **Continue from a handoff**, **Check a log**, **Explain a project** and **Token savings**.

### Savings summary

Every result includes a `savings` line (tokens saved by that call, today and in total), so Claude can tell you
as it goes. Ask *"how much has the token saver saved?"* for the full breakdown, or run this in a terminal
(example output):

```powershell
inferni-token-saver --savings
```

```
Inferni Token Saver: estimated tokens kept out of your AI chats

  Today                19,600   (4 uses)
  Last 7 days          84,210   (23 uses)
  All time            142,880   (41 uses since 2026-12-05, 96% less than reading in full)

  By tool:
    summarize_file          88,400   (12 uses)
    check_log               31,050   (9 uses)
    ...
```

## Install

You need **Python 3.11 or newer** ([python.org](https://www.python.org/downloads/); tick *"Add python.exe to
PATH"* on Windows).

```powershell
git clone https://github.com/DiveDevil-oss/inferni-token-saver.git
cd inferni-token-saver
python -m venv .venv
.venv\Scripts\pip install .
.venv\Scripts\inferni-token-saver --check
```

`--check` shows which folders it may read and whether it found a local model. The full path to
`inferni-token-saver.exe` (for example `C:\Users\you\inferni-token-saver\.venv\Scripts\inferni-token-saver.exe`)
is what you give your AI app.

## Set up a local model

### Ollama (recommended)

1. Install [Ollama](https://ollama.com/download). It runs quietly in the tray.
2. Download a model that fits your graphics card:

   | Graphics memory | Model to try | Command |
   |---|---|---|
   | 16 GB or more | Gemma 4 12B | `ollama pull gemma4:12b` |
   | 8–12 GB | a 7–9B model, e.g. Qwen 3.5 9B | `ollama pull qwen3.5:9b` |
   | No graphics card | a small model (slow, but works on the CPU) | `ollama pull gemma4:e4b` |

3. Run `inferni-token-saver --check` again. It should say `"ready": true`.

To keep models off your C: drive, set the `OLLAMA_MODELS` environment variable (for example
`E:\Ollama\models`) **before** pulling, then restart Ollama.

**Tuning:** on an RTX 5060 Ti (16 GB) with Ollama 0.40 and `gemma4:12b`, Ollama's own defaults were the
fastest. Flash attention (`OLLAMA_FLASH_ATTENTION=1`) and a compressed cache (`OLLAMA_KV_CACHE_TYPE=q8_0`)
saved up to 0.9 GB of graphics memory but read and wrote 10–25% slower. A bigger `context_tokens` (65536)
gave the same 20/20 on the test set but took 40% longer, because more text is read per question. So keep
the defaults and `context_tokens = 32768` unless your card is short of memory, in which case the compressed
cache is the setting to try first.

### LM Studio

Download a model in [LM Studio](https://lmstudio.ai), load it, and start the server on the **Developer** tab
(port 1234). Inferni Token Saver uses LM Studio if Ollama isn't running.

## Add it to your AI app

### Claude Desktop (free plan works)

1. Open **Settings → Developer → Edit Config**.
2. Add Inferni Token Saver under `mcpServers` (keep any servers already there):

   ```json
   {
     "mcpServers": {
       "inferni-token-saver": {
         "command": "C:\\Users\\you\\inferni-token-saver\\.venv\\Scripts\\inferni-token-saver.exe"
       }
     }
   }
   ```

3. Fully quit Claude Desktop (tray icon → Quit) and reopen it. It should appear under **+ → Plugins →
   Connectors**.

Store/MSIX installs of Claude Desktop read their config from
`%LOCALAPPDATA%\Claude-Data\claude_<id>\claude_desktop_config.json`, not `%APPDATA%\Claude\`. **Edit Config**
opens the right file.

### VS Code (Copilot Free), Gemini CLI, Cursor and others

Any MCP app works: run `inferni-token-saver.exe` as a **stdio** server. For example, `.vscode/mcp.json`:

```json
{ "servers": { "inferni-token-saver": { "type": "stdio", "command": "C:\\...\\inferni-token-saver.exe" } } }
```

## Config file

Everything is optional. Create an example with `inferni-token-saver --init`. It lives at
`%APPDATA%\inferni-token-saver\config.toml` (Windows) or `~/.config/inferni-token-saver/config.toml`.

```toml
# Folders the AI may search and read. Default: your home folder.
roots = ["C:/Users/you", "D:/projects"]

# "auto" picks Ollama, then LM Studio, and the first chat model found. Or name one.
model = "gemma4:12b"

# How much text the local model reads at once, in tokens. More needs more graphics memory.
# 32768 suits a 12-16 GB card with a 12B model; use 8192-16384 on 8 GB cards.
context_tokens = 32768

# The cost/saving limit (see "How answers are checked").
return_whole_below = 3000   # tokens: smaller texts come back whole
max_share = 0.15            # a result costs at most this share of reading the whole text...
max_result_tokens = 1500    # ...and never more than this
check_answers = true        # check the local model's answers before Claude sees them

# Automatic handoffs (see "Automatic handoffs").
auto_handoff = true
handoff_after_calls = 25    # remind Claude after this many tool calls since the last handoff...
handoff_after_tokens = 30000  # ...or this many tokens of results
```

| Flag | Environment variable | Does |
|---|---|---|
| `--root PATH` (repeatable) | `INFERNI_TS_ROOTS` (`;`-separated) | Folders the AI may read |
| `--model NAME` | `INFERNI_TS_MODEL` | Local model to use |
| `--config PATH` | `INFERNI_TS_CONFIG` | Use a different config file |
| | `INFERNI_TS_DATA_DIR` | Where handoffs and the savings tally go (default `%USERPROFILE%\.inferni-token-saver`) |

## Tips for getting the most out of your usage

- **Start new chats often.** A long chat re-reads everything on every message. Claude keeps a handoff note up
  to date for you (see [Automatic handoffs](#automatic-handoffs)), so when a chat gets long, open a new one and
  say *"continue from my handoff"*.
- **Give Claude the file's path instead of attaching it.** An attached or pasted file goes into the chat in
  full before any tool can help; a path lets Claude search or summarise it.
- **Ask questions, not "read this".** *"Why did my bot crash? The log is C:\bots\mybot\bot.log"* lets
  Claude use `check_log` instead of reading the whole log.
- **Switch off connectors you don't need** in a chat (+ → Plugins → Connectors). Every connector that's on
  adds its tool descriptions to every message.
- **Ask Claude for `token_savings`** now and then to see what it's saving you.

## Safety

- **Only the folders you allow.** Files outside `roots` can't be read or searched.
- **Secret files are refused.** `.env`, private keys, `credentials*`, password databases and similar can't be
  read at all, and anything that looks like a token, password, API key or webhook is replaced with
  `[redacted]` before Claude or the local model sees it.
- **Read-only.** The only tool that writes is `save_handoff`, and only into its own notes folder.
- **Your own network stays private.** `summarize_url` won't fetch addresses on your own network (routers,
  local servers) unless you set `allow_private_urls = true`.
- **Local.** Summaries are made on your PC. Nothing is sent anywhere except the page you ask
  `summarize_url` to fetch.
- **Summaries are checked, but can still miss things.** Answers are checked against the text (see above), but
  a summary can leave out something that mattered. For anything important, have Claude read the cited lines
  with `read_lines`.

See [SECURITY.md](SECURITY.md) to report a problem.

## Development

```powershell
python -m venv .venv
.venv\Scripts\pip install -e ".[dev]"
.venv\Scripts\pytest
.venv\Scripts\ruff check src tests
```

The tests use a fake local model, so they run without Ollama. See [CONTRIBUTING.md](CONTRIBUTING.md).

To measure answer quality with your real local model, write questions with known answers about your own files
(see `evals/cases.json` for the format) and run:

```powershell
.venv\Scripts\python evals\run_evals.py --base C:\path\to\your\projects --cases my_cases.json
```

It prints how many answers were right, how many tokens Claude would read, and the time taken.

## License

Licensed under [MIT](LICENSE).

Also by Inferni: [Inferni MCP](https://github.com/DiveDevil-oss/inferni-mcp-server), which lets your AI see and
manage the apps and bots on your PC.

---

Made by [Inferni](https://infernicantavit.com) · [Discord](https://discord.gg/WW8snzSW68)