Skip to content

kirti/claude-cost-guard

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

claude-cost-guard

Unlike prompt-clarity tools, this one doesn't call an LLM to check your prompt — it tells you the token count and cost, across Claude/GPT/Gemini, before you spend it, for free, instantly, on every prompt, slash-command, and skill.

What it does

Runs automatically on every submission in Claude Code (UserPromptSubmit + UserPromptExpansion hooks). 100% local, zero API calls, zero added latency by default. Shows:

  • Token count
  • Cost estimate across 6 models (Claude Sonnet/Opus/Haiku, GPT-5/mini, Gemini 2.5 Pro)
  • Flags for: duplicate paragraphs, oversized pastes, structured requests (list/compare/table) with no output format specified

Never blocks. Informational only — this is a deliberate design decision, not a missing feature. See "Design decisions" below.

Optional: optimized rewrite

Add #optimize anywhere in your prompt to get a trimmed rewrite. This is the only thing in this plugin that costs money or adds latency, and it only runs when you explicitly ask for it:

Please review this whole file and tell me what's wrong with it #optimize

The #optimize tag is stripped before analysis. Requires ANTHROPIC_API_KEY in your environment — if it's not set, the check still runs (free), and optimize just tells you it was skipped, no charge.

Install

/plugin marketplace add YOUR_GITHUB_USERNAME/claude-cost-guard
/plugin install claude-cost-guard

Or test locally without installing:

claude --plugin-dir /path/to/claude-cost-guard

Manual check (no live session needed)

Ask Claude to use the cost-guard-check skill on any text — useful for checking a draft before you've decided where to send it.

Or run the engine directly:

echo "your prompt text" | node engine/layer1.js --check

Design decisions (why it works this way)

  • Non-blocking by default. An earlier design always paused for confirmation on every submission — that means every prompt costs a minimum of two submissions, which fights the tool's own purpose. Informational, always-visible, never-blocking is the actual default.
  • Optimize is opt-in per prompt, not automatic. A tool whose pitch is "reduce spend" can't itself add a guaranteed API call to every single prompt. Layer 1 (free) always runs; Layer 2 (paid) only runs on request.
  • Skills and slash-commands are checked too, not bypassed — same guard as freeform prompts, since that's where real token cost also accumulates.
  • Claude Code only for V1. GitHub Copilot Chat has no public API for automatic pre-send interception (only opt-in @mention chat participants, or an unofficial local proxy) — revisit once this has real usage.

Project structure

claude-cost-guard/
├── .claude-plugin/
│   ├── plugin.json        # plugin manifest
│   └── marketplace.json   # makes it installable via /plugin marketplace add
├── hooks/
│   ├── hooks.json         # registers UserPromptSubmit + UserPromptExpansion
│   └── guard.js           # thin dispatcher, non-blocking
├── engine/
│   ├── layer1.js          # free/local checks (token count, flags) + CLI mode
│   ├── layer2-optimize.js # paid rewrite, only called on #optimize
│   └── pricing.json       # per-model $/1M token estimates, update periodically
├── skills/
│   └── cost-guard-check/SKILL.md  # manual on-demand check
└── tests/run.sh           # lightweight regression check

Status

Layer 1 and Layer 2 logic are implemented and tested standalone (all paths: normal input, short input, malformed input, missing API key, invalid API key — see tests/run.sh). Not yet verified inside a live Claude Code session — that's the next real-world test before calling this done end-to-end.

Roadmap (not built)

  • Configurable hard-block threshold (opt-in, off by default)
  • GitHub Copilot support
  • CI/CD repo-context auditing (CLAUDE.md/.cursorrules hygiene) — deferred, different problem than this plugin solves

Releases

Packages

Contributors

Languages