← Back to blog

Prompt Optimizer Plugin Saves 20-80% Tokens Per Turn With Model-Aware Rewrites

hermespluginstokensprompt-engineeringoptimization
Prompt Optimizer Plugin Saves 20-80% Tokens Per Turn With Model-Aware Rewrites

A new Hermes Agent plugin by Sahil-SS9 rewrites every user prompt before it reaches the LLM, tailoring the rewrite to the specific model family and capability tier. In dogfooding, the plugin averages a +55 quality-point improvement and 20-80% token reduction per rewritten prompt.

The plugin works across every surface Hermes runs on -- CLI, TUI, Discord, and Telegram -- by hooking into both pre_user_message and pre_gateway_dispatch. On CLI and TUI, an optional interactive mode shows a before/after diff and asks for approval before sending. In auto mode, the rewrite is silent.

How it works

When a user sends a message, the plugin intercepts it before the agent processes it. It sends the raw prompt to a cheap auxiliary model (configurable; defaults to inheriting the active provider) with a system prompt that describes the target model's preferences. The auxiliary model returns a rewritten version, and that rewritten version is what the agent sees.

The rewrite is tailored along two axes:

  1. Model family -- claude, openai, deepseek, google, nvidia, kimi, qwen, mistral, and others. A prompt headed to Claude Sonnet gets XML-tagged structure. The same prompt headed to o3-mini gets front-loaded constraints.
  2. Capability -- reasoning (o-series, r-series, thinking models) vs general. Reasoning models get additional tactics on top of the family profile.

The system prompt for each model is built by composing the family profile with the capability profile. For example, gpt-4o gets openai-family tactics. o3-mini gets openai-family tactics plus reasoning-capability tactics. Unknown models fall through to a base template with no fabricated guidance.

Scoring

Every rewrite is scored across five dimensions:

  • Clarity
  • Specificity
  • Terminology
  • Actionability
  • Structure

Scores are stored in a local SQLite database at ~/.hermes/plugins/prompt-optimizer/metrics.db. Nothing is uploaded. The database keeps 90 days of history by default.

Quality points are computed as the delta between the before and after scores. The reported average of +55 points means the rewritten prompt scores meaningfully higher across the five dimensions than the original.

Multi-language support

The plugin auto-detects non-English prompts using langid (97 languages) with a Unicode-range fallback for CJK, Arabic, Cyrillic, Hebrew, and Devanagari scripts. Detected non-English prompts are rewritten in the same language -- no translation occurs.

Commands

The plugin surfaces several slash commands for inspection:

Command Description
/prompt-optimizer [auto|interactive|off|status] Set mode or print current status
/prompt-insights Full report: overview, insights, suggestions, comparisons, analytics
/prompt-compare --limit 5 Latest before/after comparisons
/prompt-suggestions --limit 8 Reusable prompt-replacement patterns mined from history
/prompt-analytics [daily|weekly|monthly|all] Period analytics

Token savings context

The token savings from prompt rewriting compound with other optimization efforts. A typical Hermes session carries more than just the user's message -- the system prompt, tool schemas, skill headers, and conversation history all ride along on every turn.

The Hermes tool ecosystem has been converging on token efficiency from multiple angles. The hermes-tool-slimmer plugin uses BM25 ranking to select the smallest useful tool subset per turn, dropping a 57-tool catalog from ~18K tokens to ~3.7K -- roughly 80% reduction with zero extra API calls. The Hermes Token Diet CLI tool audits real billed prompt tokens and applies safe presets that cut fixed overhead by ~32%.

The prompt optimizer occupies a different layer. It does not reduce tool schemas or system prompt bloat -- it improves the user-facing prompt itself so the model needs fewer clarifying turns. A prompt that is clear, specific, and structured on the first send means the agent spends fewer turns re-asking and re-explaining. Each turn avoided saves not just the response tokens, but the entire round-trip context cost.

Technical details

The plugin requires Hermes Agent with the pre_user_message plugin hook. An upstream PR (#29526) adds this hook for CLI and TUI surfaces. Until merged, the gateway path (Discord, Telegram) works via pre_gateway_dispatch.

The optimiser model can be pinned to a cheap provider in config to isolate cost from the main session model:

plugins:
  entries:
    prompt-optimizer:
      model: "openai/gpt-4o-mini"

The model-family profiles are stored in ~/.hermes/plugins/prompt-optimizer/model-profiles.yaml and are fully editable. The shipped YAML covers 8 vendor families with published prompt-engineering guidance as the source for each tactic.

[^1]: Sahil-SS9. "hermes-multichannel-prompt-optimizer." GitHub. July 2026. [^2]: alias8818. "hermes-tool-slimmer." GitHub. [^3]: "hermes-token-diet." PyPI.

Termagotchi
_

Ryan Underdown

Autodidact. Rarely listens to advice.

Follow on X @catamarammed or GitHub @underdown