Skip to content

How It Works

Miskin uses two strategies to save tokens:

1. Command Output Filtering

When your AI tool runs a shell command (via hooks), Miskin intercepts it:

AI tool:  git status
Hook:     miskin git status
Miskin:   runs git status → captures output → applies filter → returns compact result
AI tool:  receives 200 tokens instead of 2000

Filter strategies per command type:

StrategyExampleApplied to
OK-modegit pushok maingit add/commit/push/pull/checkout/...
Status groupingStaged/unstaged/untracked sectionsgit status
Diff compactionPer-file +/-, 15-file limitgit diff
Failure extractionShow only FAILED testscargo test, pytest, jest
Error groupingGroup by fileeslint, ruff, tsc
Table compactionShow count + first N rowsdocker ps, gh pr list
Log dedupCollapse repeated linesdocker logs, kubectl logs
TruncationHead/tail with skip countcat, find, curl

2. Caveman Prompt Injection

When enabled, Miskin injects "be concise" rules into the AI tool's system prompt. The model itself produces fewer output tokens:

Normal agent:  "Sure! I'd be happy to help. The issue is on line 42..."
Caveman agent:  "Bug L42. Fix: add null check."
Same fix. 65% fewer tokens.

Prompt is injected once per session via markdown files (CLAUDE.md, AGENTS.md, etc.) or plugin hooks depending on the AI tool.

Hook Architecture

Miskin installs hooks that rewrite commands before execution:

AgentHook typeFile
Claude CodeBash hook script.claude/hooks/miskin-rewrite.sh
CopilotJS preToolUse hook.github/copilot-hooks/miskin-hook.js
Cursorhooks.json.cursor/hooks.json
Geminisettings hook.gemini/miskin-hook.json
CodexInstructions.codex/miskin.md
OpenCodeTypeScript plugin.opencode/plugins/miskin.ts
WindsurfRules file.windsurfrules

Token Counting

Miskin uses tiktoken-rs (cl100k_base, same tokenizer as GPT-4/Claude) to count tokens accurately. Savings are recorded locally in ~/.local/share/miskin/analytics.json.

Tee Mode

When a command fails, Miskin saves the raw unfiltered output to ~/.local/share/miskin/tee/<timestamp>_<command>.log. The AI tool can read this file to see full error output without re-executing the command.

Released under the MIT License.