promptopt

promptopt

Enables local, offline prompt compression, smart asking when needed, and routing to the cheapest capable model to save tokens and costs for terminal AI agents.

Category
访问服务器

README

<div align="center">

<img src="docs/banner.svg" alt="promptopt — stop burning tokens" width="100%" max-width="920px">

the token-saving plugin for terminal AI agents

Claude Code · Codex CLI · opencode · Gemini CLI · Claude Desktop · any MCP client

npm npm downloads license node offline keys

Your agent burns most of its tokens before it writes a single line of code. promptopt plugs the leaks — locally, offline, for free.

</div>


⚡ TL;DR

npx promptopt install        # one command. every detected CLI. done.

That single command registers an MCP server, injects a ~200-token discipline protocol, adds cheap-model subagents, and starts tracking your savings in a stylish HTML dashboard.

Prefer checkboxes? Installing via npm (npm i promptopt) or running promptopt init opens an interactive checklist - arrow keys to move, space to toggle the CLIs you want, a to check all, enter to configure them:

promptopt - select the CLIs to configure:
  [x] claude
  > [ ] claude-desktop
  [x] codex
  [ ] opencode
  [ ] gemini
  [ ] generic
  space: toggle   a: check all   enter: continue   esc: cancel

It only appears on real interactive installs - never in CI, never during npx runs, never inside this repo itself (PROMPTOPT_NO_INIT=1 disables it permanently).

$ promptopt "Hey, could you please fix the bug in src/app.ts? Thanks!"

tokens: 15 -> 7 compressed (net -53.3%)
intent: fix (85% confidence)

--- optimized prompt ---
Fix the bug in src/app.ts

route: simple · gemini-2.5-flash ~$0.0032  (92% under flagship pricing)

🩸 The problem

Token leak What actually happens promptopt's fix
🔁 Rework loops Agent guesses an ambiguous request wrong → you re-prompt → double spend Asks ≤3 sharp questions when guessing is expensive; auto-assumes + states assumptions when it isn't
🗣️ Chatty prompts "Hey, could you please maybe..." Rule-based compression: 15–55% off typical prompts
🏋️ Wrong-size model Opus-grade reasoning spent on grep-level lookups Tier classifier routes to the cheapest capable model/subagent
📜 Verbose sessions Restating tasks, narrating unchanged code, recaps Behavior protocol rules 1–6

On three real prompts, promptopt spent $0.078 where uncompressed-flagship would have spent $0.300 — tracked live in its own report.


📦 Install

Requirement: Node ≥ 18. No API keys. No accounts. Nothing leaves your machine.

One command for everything

npx promptopt install
# or the interactive checklist, anytime:
npx promptopt init

Auto-detects which CLIs you have installed and configures each one. Add -n to preview first (--dry-run), --all to force every target.

Pick your target

<details open> <summary><b>🤖 Claude Code</b></summary>

npx promptopt install claude

Registers the MCP server in .mcp.json (project) or ~/.claude.json (--user flag), injects the protocol into CLAUDE.md, and creates two real subagents:

  • promptopt-scout → haiku — read-only lookups & searches, ≤5-line answers
  • promptopt-worker → sonnet — well-scoped edits, diff-first output

Restart your Claude Code session → done.

Heads-up: project-scope MCP servers need a one-time trust approval — start claude in the folder and accept the prompt (or run /mcp). Stuck at "Pending approval"? That's this. Install with --user instead and it's trusted in every project with zero prompts. </details>

<details> <summary><b>🖥️ Claude Desktop</b></summary>

Claude Desktop has no URL scheme for local servers, so pick one of these:

Option A — one-click bundle (recommended): Download promptopt-&lt;version&gt;.mcpb from Releases and drag it onto the Claude Desktop window. All dependencies are bundled — no Node tooling needed on the other end.

Option B — installer:

npx promptopt install claude-desktop     # writes claude_desktop_config.json for you

Option C — manual: paste into %APPDATA%\Claude\claude_desktop_config.json (Windows) or ~/Library/Application Support/Claude/claude_desktop_config.json (macOS):

{
  "mcpServers": {
    "promptopt": { "command": "npx", "args": ["-y", "promptopt", "mcp"] }
  }
}

Restart Claude Desktop → the tools appear in your chats. </details>

<details> <summary><b>⌨️ Codex CLI</b></summary>

npx promptopt install codex --user    # ~/.codex/config.toml + ~/.codex/AGENTS.md
npx promptopt install codex           # project AGENTS.md only

</details>

<details> <summary><b>🔧 opencode / Gemini CLI / anything else</b></summary>

npx promptopt install opencode   # opencode.json + AGENTS.md
npx promptopt install gemini     # .gemini/settings.json + GEMINI.md
npx promptopt install generic    # any MCP client: AGENTS.md + printed snippet

</details>

Verify & reverse

npx promptopt doctor       # health-check every registration
npx promptopt uninstall    # removes everything cleanly (marker-based, zero residue)

All instruction-file edits sit between <!-- promptopt:start vX --> and <!-- promptopt:end --> markers; JSON configs get .bak backups before touching them.


🧠 How it thinks

Injected once per session (~200 tokens) — the cheapest insurance you'll ever buy:

1. Think terse. Plan in ≤3 short sentences before acting. Never restate the task. 2. Ask or assume. If a request has ≥2 interpretations: adopt the assumption and say "Assuming X" in one line — unless a wrong guess forces a full rework, then ask ≤3 batched questions and stop. 3. Route cheap. Trivial subtasks go to promptopt-scout. Never spend frontier tokens on grep-level work. 4. Batch. Parallel tool calls. Read each file once. Never re-read unchanged files. 5. Output lean. Diffs over full files. Stop when done — no recap. 6. Big jobs. Before >5k output tokens of work, run optimize_prompt and follow its plan.

❓ Questions that answer themselves

Every prompt is intent-classified (question / build / plan / fix / add) and vague builds get multiple-choice menus instead of essay prompts:

questions (1) - ask these before acting:
  1. What should be built?
     choices: feature inside the existing app | standalone script | CLI tool |
              library / package | service / API endpoint | full new app
     default if unanswered: a feature integrated into the existing project

Three modes: hybrid (default — assume ≥70% confidence, ask the rest) · auto (assume everything) · ask (never assume).

🛠️ MCP tools

Tool Does
optimize_prompt Intent → compression → auto-assumptions → choice-based blockers → routing → usage report
route_prompt Cheapest capable model per provider, costed against always-flagship
token_audit Offline BPE token count + compression opportunities for any text
get_protocol Protocol text for agents that can't read instruction files

💸 Model routing

Tier Claude OpenAI Gemini
trivial claude-haiku-4-5 · $1/$5 gpt-5.4-nano · $0.20/$1.25 gemini-3.1-flash-lite · $0.25/$1.50
standard claude-sonnet-5 · $2/$10 gpt-5.1 · $1.25/$10 gemini-2.5-flash · $0.30/$2.50
complex claude-opus-5 · $5/$25 o3 · $2/$8 gemini-3-pro-preview · $2/$12

Prices verified against the public LiteLLM registry on 2026-08-21. Prices drift — pin yours current:

promptopt models --refresh   # re-syncs into ~/.promptopt/models.json (trusted 7 days)

Intent steers the tier: question demotes (explanations rarely need Opus), plan promotes to at least standard (wrong plans are the priciest mistake).

📊 Usage reports

Every optimize run writes to ./promptopt-report/ and prints the path:

report: C:\dev\myproject\promptopt-report\index.html

A dark-gradient, zero-JS, works-offline dashboard with stat cards and progress bars:

  • tokens saved — this run and cumulative
  • est. dollars saved vs the always-flagship baseline
  • budget used / % left (local budget, default $10)
  • the counterfactual bar: what you'd have burned without the plugin
  • latest run's before/after, assumptions, choices asked, routing table, last 20 runs
promptopt budget                       # usage + % left
promptopt budget --set-usd 25 --set-tokens 2000000
promptopt report --open                # print (and open) the static report
promptopt dashboard                    # LIVE dashboard on http://localhost:4739
promptopt "..." --no-report            # optimize without recording

Live dashboard

promptopt dashboard starts a local-only server (binds 127.0.0.1, never exposed to your network), auto-opens your browser, and keeps the page live: a tiny poll script detects new optimize runs and reloads the page automatically — leave it open in a tab and watch savings accumulate while you work.

promptopt dashboard              # http://localhost:4739
promptopt dashboard -p 8080      # custom port (auto-falls forward if taken)
promptopt dashboard --no-open    # serve without opening the browser

Endpoints: / (dashboard), /api/data (usage snapshot JSON), /api/ping. The served page re-renders from the ledger on every request — there is no state to refresh manually.

Add promptopt-report/ to .gitignore — local telemetry, your eyes only.

⌨️ CLI cheat sheet

promptopt "<prompt>"                     # optimize (hybrid mode + report)
promptopt init                           # interactive checkbox installer
promptopt "<prompt>" --mode ask          # all questions, zero assumptions
promptopt route "<prompt>"               # tier + cheapest model per provider
promptopt audit "$(cat big-log.txt)"     # token count + compression report
promptopt models                         # catalog + source
promptopt dashboard                      # live localhost usage dashboard
promptopt doctor                         # installation health check

🔒 Privacy & accuracy

  • Zero network calls at runtime. The only network event ever is npm fetching the package itself. No keys, no telemetry, no accounts.
  • Compression protects code blocks, URLs, and file paths verbatim; requirements are never dropped.
  • Token counts use offline cl100k_base BPE — Claude/Gemini actual counts vary ~±10%. Costs are estimates from public registry prices, not invoices.

<details> <summary><b>Why no URL link for Claude Desktop?</b></summary>

Claude Desktop accepts remote connectors by URL, but local stdio servers — like promptopt, which runs entirely on your machine — have no deep-link scheme. That's exactly why the <code>.mcpb</code> desktop-extension format exists: one file, double-click install, dependencies included. </details>

🤝 Contributing

PRs welcome — new compression rules, model catalog updates, new agent targets. See CONTRIBUTING.md.

git clone https://github.com/hawktuahcoin-hurhur/promptopt && cd promptopt
npm ci && npm run build && npm test && npm run test:smoke

CI

📄 License

MIT © promptopt contributors

<div align="center"> <br> <sub>stop burning tokens — <code>npx promptopt install</code></sub> </div>

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选