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
- Open VS Code
- Go to Extensions (Ctrl+Shift+X / Cmd+Shift+X)
- Search for "Prompt Optimizer"
- Click Install
From .vsix File
- Download the latest
.vsix file from releases
- Open VS Code
- Go to Extensions
- Click
... menu → "Install from VSIX..."
- Select the downloaded file
Quick Start
Using Local Mode (No Setup Required)
- Select any text in your editor
- Right-click → "Optimize Prompt (Local Mode)"
- 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
- Visit Google AI Studio
- Sign in with your Google account
- Click "Create API Key"
- Copy your API key (starts with
AIza...)
- Open Command Palette (
Ctrl+Shift+P / Cmd+Shift+P)
- Type "Prompt Optimizer: Setup Gemini API Key"
- Paste your API key
- Done!
Step 3: Use AI Mode
- Select any text in your editor
- Right-click → "Optimize Prompt (AI Mode - Gemini)"
- Wait for AI optimization
- View results and choose action
Keyboard Shortcut: Ctrl+Alt+A (Windows/Linux) or Cmd+Alt+A (Mac)
Auto Mode (Smart Selection)
- Select text
- Right-click → "Optimize Prompt (Auto-Select Mode)"
- 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
- Select Complete Thoughts: Select full sentences or paragraphs for better optimization
- Review Results: Always review optimized text before use, especially in aggressive mode
- Use Local Mode First: Try local mode first to see if it meets your needs
- Combine Modes: Use local mode for quick edits, AI mode for complex prompts
- 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
Links
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.