---
slug: "pi-tokenrouter-provider"
source_type: "skill_md"
source_url: "https://cdn.jsdelivr.net/gh/rharagon/pi-tokenrouter-provider@main/SKILL.md"
repo: "https://github.com/rharagon/pi-tokenrouter-provider"
source_file: "SKILL.md"
branch: "main"
---
---
name: token-router
description: Route oversized logs, source files, and long routeable agent-context reference files through a local Ollama model before analysis. Use when the user needs to analyze massive error logs, stack traces, source files over roughly 300 lines, or long AGENTS.md/CLAUDE.md-style reference docs while preserving token budget. Trigger on requests such as "optimize tokens for this log", "look at this big file using the local router", or "route AGENTS.md context".
---

# Token Router (Pi fork)

Use this skill to reduce cloud context load for large logs, source files, or long routeable agent-context reference files. A local Ollama model selects likely line ranges, and `scripts/router.py` returns raw, unedited slices from the original file.

## Workflow

1. For large logs, stack traces, source files, or long routeable agent-context docs, run the router before loading the whole file:

```bash
python3 scripts/router.py <mode> <PATH_TO_TARGET_FILE>
```

Pass the user question when it contains useful domain terms:

```bash
python3 scripts/router.py heavy_code path/to/file.py --query "token expiration"
```

For long agent instruction references, use `agent_context` with the user's task terms:

```bash
python3 scripts/router.py agent_context path/to/agent-context/frontend.md --query "frontend testing workflow"
```

2. Choose `error_log` for logs or stack traces, `heavy_code` for long source files, and `agent_context` for long routeable instruction references.
3. Analyze only the returned raw slices. The local model is a line-number router, not a summarizer.
4. If the returned slice is too narrow, rerun the router or inspect a larger nearby range directly.
5. Do not assume unseen surrounding code. Ask for or retrieve more context before making claims that depend on omitted lines.

## Configuration

The router defaults to the locally installed `gemma4:e2b-it-q4_K_M` model at `http://localhost:11434/api/generate`. Use `OLLAMA_MODEL` and `OLLAMA_URL` to override. See the original README and `docs/token-router/benchmark-report.md` for details.

## Regression Tests

```bash
python3 scripts/run_router_tests.py tests/router-tests.json
```
