Skip to content
| Marketplace
Sign in
Visual Studio Code>Formatters>Prompt Token SaverNew to Visual Studio Code? Get it now.
Prompt Token Saver

Prompt Token Saver

Sushant Bansode

|
8 installs
| (1) | Free
Optimize your LLM prompts and reduce token costs! Smart local algorithms or AI-powered optimization with Gemini
Installation
Launch VS Code Quick Open (Ctrl+P), paste the following command, and press enter.
Copied to clipboard
More Info

Prompt Optimizer

Optimize your LLM prompts to reduce token consumption and save costs.

This VS Code extension helps you write better, more efficient prompts for Claude, ChatGPT, Gemini, and other LLMs by reducing token count while preserving meaning and intent.

Features

Dual Optimization Modes

Local Mode (Offline, Free, Fast)

  • 6-Stage Optimization Pipeline: Sophisticated algorithms that work offline
  • Text Normalization: Cleans up whitespace and formatting
  • Smart Deduplication: Removes duplicate and similar sentences using fuzzy matching
  • Fluff Removal: Strips filler words and unnecessary phrases
  • Sentence Optimization: Simplifies structure and removes redundancy
  • Structural Reorganization: Groups and prioritizes content
  • Token-Specific Optimization: Replaces verbose phrases with concise alternatives

AI Mode (Gemini Flash API)

  • AI-Powered Optimization: Uses Google's Gemini Flash for intelligent optimization
  • Free Tier Available: Generous limits (15 RPM, 1M TPM, 1500 RPD)
  • Automatic Fallback: Falls back to local mode if API fails
  • Smart Retry Logic: Exponential backoff for reliability

Key Benefits

  • Average token reduction without losing meaning
  • Save money on LLM API costs
  • Fast local mode (sub-3 second optimization)
  • Secure API key storage in VS Code secrets
  • Context menu integration for quick access
  • Before/after token counts to track savings
  • Diff view to compare original vs optimized

Installation

From Marketplace

  1. Open VS Code
  2. Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
  3. Search for "Prompt Optimizer"
  4. Click Install

From .vsix File

  1. Download the latest .vsix file from releases
  2. Open VS Code
  3. Go to Extensions
  4. Click ... menu → "Install from VSIX..."
  5. Select the downloaded file

Quick Start

Using Local Mode (No Setup Required)

  1. Select any text in your editor
  2. Right-click → "Optimize Prompt (Local Mode)"
  3. View the results and choose to replace, show diff, or copy

Keyboard Shortcut: Ctrl+Alt+L (Windows/Linux) or Cmd+Alt+L (Mac)

Using AI Mode (Requires Gemini API Key)

Step 1: Get Your Free Gemini API Key

  1. Visit Google AI Studio
  2. Sign in with your Google account
  3. Click "Create API Key"
  4. Copy your API key (starts with AIza...)

Step 2: Configure the Extension

  1. Open Command Palette (Ctrl+Shift+P / Cmd+Shift+P)
  2. Type "Prompt Optimizer: Setup Gemini API Key"
  3. Paste your API key
  4. Done!

Step 3: Use AI Mode

  1. Select any text in your editor
  2. Right-click → "Optimize Prompt (AI Mode - Gemini)"
  3. Wait for AI optimization
  4. View results and choose action

Keyboard Shortcut: Ctrl+Alt+A (Windows/Linux) or Cmd+Alt+A (Mac)

Auto Mode (Smart Selection)

  1. Select text
  2. Right-click → "Optimize Prompt (Auto-Select Mode)"
  3. Choose Local or AI mode when prompted

Keyboard Shortcut: Ctrl+Alt+O (Windows/Linux) or Cmd+Alt+O (Mac)

Configuration

Open Settings (Ctrl+, / Cmd+,) and search for "Prompt Optimizer"

Available Settings

Setting Description Default
Default Mode Choose local, ai, or ask ask
Show Token Count Display before/after token counts true
Auto Replace Automatically replace text without confirmation false
Local Optimization Level conservative, moderate, or aggressive moderate
Gemini Model Gemini model to use gemini-2.0-flash-exp
API Timeout Request timeout in seconds 30

Usage Examples

Example 1: Verbose Prompt

Original (87 tokens):

I think that you should maybe consider the fact that it might be a good idea to 
implement a feature that would allow users to be able to search through their 
documents in order to find specific information. This would be very helpful and 
useful for many people.

Optimized (21 tokens, 76% reduction):

Implement document search feature to help users find specific information.

Example 2: Technical Prompt

Original (154 tokens):

I'm working on a project and I need help with implementing a REST API endpoint. 
The endpoint should handle POST requests and it should validate the input data. 
After validation, it should save the data to the database. If there are any errors 
during the process, it should return appropriate error messages. Can you help me 
with this?

Optimized (43 tokens, 72% reduction):

Create REST API POST endpoint that:
- Validates input data
- Saves to database
- Returns appropriate errors

Need implementation help.

Example 3: Code Review Request

Original (92 tokens):

Hi there! I was wondering if you could possibly take a look at my code and maybe 
provide some feedback? I'm not sure if I'm doing things the right way and I think 
it might be helpful to get another perspective on this. Thanks in advance!

Optimized (12 tokens, 87% reduction):

Review my code and provide feedback on implementation approach.

Optimization Levels Explained

Conservative

  • Removes only obvious filler ("I think that", "obviously")
  • Minimal changes to sentence structure
  • Safest option, smallest reduction (~10-15%)

Moderate (Recommended)

  • Removes common filler and hedge words
  • Simplifies sentence structure
  • Replaces verbose phrases
  • Good balance (~20-30% reduction)

Aggressive

  • Removes all filler, including politeness
  • May remove articles (a, an, the)
  • Maximum compression
  • Review results carefully (~30-40% reduction)

Commands

Access via Command Palette (Ctrl+Shift+P / Cmd+Shift+P):

  • Prompt Optimizer: Optimize Prompt (Local Mode) - Use local algorithms
  • Prompt Optimizer: Optimize Prompt (AI Mode - Gemini) - Use Gemini AI
  • Prompt Optimizer: Optimize Prompt (Auto-Select Mode) - Choose mode
  • Prompt Optimizer: Setup Gemini API Key - Configure API key

Privacy & Security

  • API Key Storage: Stored securely using VS Code's secret storage
  • No Data Collection: Your prompts are never stored or logged
  • Local Mode: Works completely offline, no external requests
  • AI Mode: Only sends selected text to Gemini API when you explicitly choose AI mode

Tips for Best Results

  1. Select Complete Thoughts: Select full sentences or paragraphs for better optimization
  2. Review Results: Always review optimized text before use, especially in aggressive mode
  3. Use Local Mode First: Try local mode first to see if it meets your needs
  4. Combine Modes: Use local mode for quick edits, AI mode for complex prompts
  5. Token Savings Add Up: Even 20% reduction saves significant costs over time

Troubleshooting

"Gemini API key is required"

  • Run "Setup Gemini API Key" command
  • Check that your API key starts with "AIza"
  • Verify you copied the complete key

"API request failed"

  • Check your internet connection
  • Verify API key is still valid at Google AI Studio
  • Check rate limits (free tier: 15 requests/minute)
  • Extension will automatically fall back to local mode

"No text selected"

  • Select some text before running optimization
  • Ensure you have an active editor window

Local mode results unexpected

  • Try different optimization levels
  • Report issues on GitHub

Token Counting

Token counts are estimates based on:

  • ~4 characters per token (GPT-style tokenization)
  • Word-based estimation for validation
  • Averaged for better accuracy

Note: Exact token counts may vary by LLM model, but estimates are reliable for comparison.

Contributing

Contributions are welcome! See DEVELOPMENT.md for setup and development guidelines.

License

MIT License - See LICENSE for details

Acknowledgments

  • Built with VS Code Extension API
  • Powered by Google Gemini for AI mode
  • Inspired by the need to optimize LLM costs across the developer community

Links

  • GitHub Repository
  • Issue Tracker
  • VS Code Marketplace
  • Gemini API Documentation

Changelog

Version 1.0.0

  • Initial release
  • Local optimization with 6-stage pipeline
  • AI optimization using Gemini Flash
  • Context menu integration
  • Token counting and statistics
  • Diff view support
  • Secure API key storage

Made with ❤️ by Sushant Bansode

Save tokens. Save money. Write better prompts.

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2026 Microsoft