Prompt Optimizer
A VS Code extension that converts loosely formatted markdown prompts into structured XML format optimized for Claude AI.
Features
- Smart Conversion: Automatically identifies and structures different prompt sections
- Multiple Trigger Methods: Command palette, keyboard shortcut, or context menu
- Flexible Text Selection: Works with selected text or entire document
- XML Structure: Converts to Claude-optimized XML with proper tags
Installation
Option 1: From VSIX Package (Recommended)
Build the extension package:
npm install
npm run compile
npm run package
Install the generated .vsix
file:
- Open VS Code
- Press
Ctrl+Shift+P
(or Cmd+Shift+P
on Mac)
- Type "Extensions: Install from VSIX"
- Select the generated
prompt-optimizer-1.0.0.vsix
file
Option 2: Development Mode
- Clone or download this repository
- Open the folder in VS Code
- Install dependencies:
npm install
- Compile the TypeScript:
npm run compile
- Press
F5
to launch a new Extension Development Host window
Usage
Converting Text
There are three ways to convert markdown prompts to XML:
1. Command Palette
- Press
Ctrl+Shift+P
(or Cmd+Shift+P
on Mac)
- Type "Prompt Optimizer: Convert to XML"
- Press Enter
2. Keyboard Shortcut
- Select text (optional) or place cursor in document
- Press
Ctrl+Shift+X
(or Cmd+Shift+X
on Mac)
- Right-click in the editor
- Select "Convert to XML" from the context menu
Text Selection Behavior
- With Selection: Converts only the selected text
- Without Selection: Converts the entire document
- Result: The original text is replaced with the XML version
Conversion Rules
The extension automatically identifies and converts different sections:
Markdown Pattern |
XML Output |
Main content |
<instructions> |
Bullet points (- , * , • ) |
<constraints> with <constraint> items |
Context:, Background:, Setting: |
<context> |
Example:, Examples:, Sample: |
<examples> with <example> items |
Format:, Output:, Return: |
<output_format> |
Requirements:, Must:, Should: |
<constraints> |
Examples
Create a Python function that processes CSV files
- Must handle missing values
- Should return pandas DataFrame
- Include error handling
Example: process_csv("data.csv") → DataFrame
Format: Return working code with docstring
Output (XML)
<prompt>
<instructions>
Create a Python function that processes CSV files
</instructions>
<constraints>
<constraint>Must handle missing values</constraint>
<constraint>Should return pandas DataFrame</constraint>
<constraint>Include error handling</constraint>
</constraints>
<examples>
<example>process_csv("data.csv") → DataFrame</example>
</examples>
<output_format>
Return working code with docstring
</output_format>
</prompt>
Development
Project Structure
prompt-optimizer/
├── package.json # Extension manifest
├── tsconfig.json # TypeScript configuration
├── src/
│ ├── extension.ts # Main extension entry point
│ └── converter.ts # Conversion logic
├── .vscode/
│ └── launch.json # Debug configuration
└── README.md # This file
Building and Testing
# Install dependencies
npm install
# Compile TypeScript
npm run compile
# Watch for changes during development
npm run watch
# Create package for distribution
npm run package
# Run linting
npm run lint
Debugging
- Open this project in VS Code
- Press
F5
to launch Extension Development Host
- Set breakpoints in the TypeScript files
- Test the extension in the new window
Requirements
- VS Code 1.60.0 or higher
- Node.js 16.x or higher (for development)
License
MIT License - see LICENSE file for details
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Changelog
1.0.0
- Initial release
- Basic markdown to XML conversion
- Command palette, keyboard shortcut, and context menu integration
- Smart section detection and structuring