@tvonhake/opentk
v0.1.2
Published
Token reduction plugin for coding agents - reduces LLM token consumption by 60-90%
Maintainers
Readme
opentk
Reduces LLM token consumption by 60–90% on common developer commands. Works with Claude Code, OpenCode, and any AI coding agent that supports shell hooks or plugins.
- 60+ command patterns — git, cargo, pytest, vitest, tsc, eslint, terraform, kubectl, and more
- 12 filtering strategies — stats extraction, error-only, grouping, deduplication, tree compression, etc.
- Zero config — auto-configures Claude Code and OpenCode on install
- Local-only tracking — all data stays on your machine, no telemetry
Install
npm install -g @tvonhake/opentkOn install, opentk automatically configures:
- Claude Code — adds a
PreToolUsehook to~/.claude/settings.json - OpenCode — adds itself as a plugin to
~/.config/opencode/opencode.json(if present)
That's it. No manual config needed.
How It Works
Claude Code
opentk runs as a PreToolUse hook. When Claude runs a matched bash command, opentk rewrites it to pipe the output through a filter before Claude sees it:
git log --oneline -20
→ bash -c '... git log --oneline -20 | opentk-filter --strategy stats ...'- Original exit code is preserved
- Falls back to unfiltered output if the filter fails
- Only intercepts simple commands — anything with
&&,||,|,$(, orsudopasses through unchanged
OpenCode
opentk runs as a JS plugin using OpenCode's tool.execute.before / tool.execute.after hooks, which can mutate tool output directly.
Manual Setup
If you prefer to configure manually:
Claude Code — add to ~/.claude/settings.json:
{
"hooks": {
"PreToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": "opentk-hook" }]
}
]
}
}OpenCode — add to ~/.config/opencode/opencode.json:
{
"plugin": ["@tvonhake/opentk"]
}Supported Commands
Git
git status, git diff, git log, git show, git blame, git stash list, git reflog, git shortlog, git branch, git ls-files
GitHub CLI
gh pr list/status, gh issue list, gh run list/view, gh workflow list
Files & Search
ls, tree, find, fd, du, df -h, grep, rg, ag, cat, head, tail
JavaScript / TypeScript
npm run, pnpm, yarn, bun, npx, vitest, jest, mocha, tsc, eslint, prettier, biome
Python
pytest, ruff, pip install/list/freeze/show/check/audit, mypy, pylint, flake8, pyright
Rust
cargo test/build/check/clippy/audit/outdated/metadata/tree
Go
go test/build/vet, golangci-lint
Ruby
rspec, bundle exec rspec, bundle list
Java / JVM
mvn test/build, gradle test/build
Docker & Kubernetes
docker ps/images/logs/inspect, kubectl get/describe/logs/top, helm list/status
Cloud & Infrastructure
terraform plan/show/state, tofu plan/state, aws ... list/describe, gcloud ... list/describe, az ... list
System
ps aux
Viewing Token Savings
opentk # overall stats
opentk --timeRange today # today only
opentk --timeRange week # past week
opentk --groupBy command # breakdown by command type
opentk --groupBy project # breakdown by project
opentk --reset # clear all dataConfiguration
Optional — opentk works with defaults out of the box.
OpenCode
Add an opentk key to your project's opencode.json:
{
"opentk": {
"enabled": true,
"excludeCommands": [],
"filterLevel": "aggressive",
"trackingEnabled": true,
"historyDays": 90
}
}Claude Code
Create a .opentk.json file in your project directory (or ~/.opentk.json globally):
{
"enabled": true,
"filterLevel": "aggressive",
"excludeCommands": ["my-custom-tool"]
}Config priority (highest wins): env vars → project .opentk.json → global ~/.opentk.json
| Env var | Values | Description |
|---|---|---|
| OPENTK_ENABLED | true / false | Enable or disable filtering |
| OPENTK_FILTER_LEVEL | aggressive / minimal / none | Filter aggressiveness |
| OPENTK_EXCLUDE_COMMANDS | comma-separated list | Commands to skip filtering |
Config options
| Key | Default | Description |
|---|---|---|
| enabled | true | Enable or disable opentk |
| filterLevel | "aggressive" | "aggressive", "minimal", or "none" |
| excludeCommands | [] | Commands to pass through unfiltered |
Privacy
- No network calls
- No telemetry or analytics
- All tracking data stored locally in
~/.local/share/opentk/
License
MIT
