Install
openclaw skills install @thomaszhou22/mega-prompt-optimizerTransform vague user requests into precise, high-quality prompts. Two engines: template matching (3300+ library) + LLM meta-prompting (host AI as optimizer). Only activates when the user explicitly turns it on.
openclaw skills install @thomaszhou22/mega-prompt-optimizerDual-engine prompt optimization: template matching (3,300+ template library) + LLM meta-prompting (the host AI optimizes directly).
On startup the skill probes the host platform's capabilities and degrades unavailable features:
| Capability | Detection | Present → behavior | Absent → fallback |
|---|---|---|---|
| File reading | Try reading references/categories/index.json | Template engine available | Force llm-only mode; hide template-related instructions |
| File writing | Try writing memory/prompt_optimizer_state.json | State persistence | In-conversation memory only; write no files |
| Large-file handling | Read categories/coding.json (1.5MB) | Load by category | Small categories or pure LLM only |
Startup behavior:
references/categories/index.json
memory/prompt_optimizer_state.json
When the user first mentions prompt optimization and memory/prompt_optimizer_state.json does not exist, run a one-time onboarding:
Introduce the capability (one sentence): "Prompt Optimizer turns vague instructions into precise, structured prompts, with two engines: template matching + direct AI optimization."
Ask a few quick configuration questions:
a) What do you mainly use prompts for?
coding categorywriting + creative-generationbusiness + consultingeducationcoding (50% of the library; widest coverage)b) Engine preference?
template-first (default)llm-onlytemplate-onlyc) Output format preference?
d) Template edition?
Write the initial state file memory/prompt_optimizer_state.json (note: enabled stays false — preferences are saved, but the skill activates only when the user explicitly turns it on):
{
"enabled": false,
"mode": "lite|full",
"engine": "template-first|llm-only|template-only",
"output_format": "text|markdown|xml|all",
"categories": ["..."],
"onboarded": true,
"turned_on_at": null
}
Confirm completion: "Preferences saved! The optimizer stays OFF until you say 'turn on prompt optimization' — then just send me any prompt and I'll optimize it. Say 'switch engine' or 'load new category' anytime to adjust."
Onboarding runs exactly once; every later activation reads the state file directly.
Off by default; activates only on an explicit user instruction.
| Action | Example commands |
|---|---|
| Turn on | "turn on prompt optimization", "enable lite mode" |
| Turn on (full) | "enable full prompt optimization" |
| Turn off | "turn off prompt optimization" |
| Set engine | "set engine to ..." (see below) |
| Set output format | "set output format to Markdown / XML / plain text / all" |
| Mode | Command | Mechanism | Best for |
|---|---|---|---|
| Template-first + LLM fallback (default) | "set engine to template-first" | Search the library first; if no match, let the LLM generate | Daily use; token-saving |
| Pure LLM | "set engine to llm-only" | Skip the library; the host AI optimizes directly | Custom needs, domains the library doesn't cover |
| Template-only | "set engine to template-only" | Library only; report when nothing matches | Maximum speed; zero extra tokens |
Core idea of LLM meta-prompting: this skill runs inside the host AI (OpenClaw / Claude Code / etc.), so the host AI itself is the optimization engine. No external API calls — the current AI simply works as a "prompt optimization expert".
Edition differences:
📦 The template library files are NOT included in the ClawHub package (too large). Fetch from GitHub:
- Lite:
https://raw.githubusercontent.com/Thomaszhou22/prompt-optimizer-skill/main/references/prompt_library_lite.json- Full:
https://raw.githubusercontent.com/Thomaszhou22/prompt-optimizer-skill/main/references/prompt_library_full.json- Categories:
https://github.com/Thomaszhou22/prompt-optimizer-skill/tree/main/references/categoriesRun
git clone https://github.com/Thomaszhou22/prompt-optimizer-skill.gitfor the full library.
You don't need all 3,344 templates — load only the categories you need:
| Action | Example commands |
|---|---|
| Load specific categories | "load only coding templates", "load coding + data-analysis" |
| List available categories | "which categories are available" |
| Load everything | "load all categories" |
| Remove a category | "remove art-entertainment" |
Category file locations: references/categories/{category}.json
| Category | Count | File size |
|---|---|---|
| coding | 1672 | ~1.5MB |
| art-entertainment | 404 | ~411KB |
| other | 253 | ~202KB |
| writing | 208 | ~196KB |
| education | 117 | ~107KB |
| consulting | 114 | ~115KB |
| business | 108 | ~98KB |
| health-lifestyle | 82 | ~76KB |
| legal-finance | 82 | ~80KB |
| data-analysis | 73 | ~73KB |
| creative-generation | 73 | ~66KB |
| science-research | 61 | ~55KB |
| translation | 60 | ~57KB |
| tech-tools | 37 | ~36KB |
Loading priority: category specified → load the corresponding categories/ file; no category specified → load the full lite/full file.
Default engine template-first, default category coding (50% of the library; most used). The user can switch anytime.
State persists to memory/prompt_optimizer_state.json:
{"enabled": true, "mode": "lite", "engine": "template-first", "output_format": "text", "categories": ["coding"], "turned_on_at": "2026-05-19T16:05:00+08:00"}
Allowed engine values: "template-first" (default) | "llm-only" | "template-only"
Output format notes:
## headings, - lists, **bold**, etc.<prompt><role>...</role><action>...</action></prompt> structureDecision logic: message received → read state file → if it's a toggle/switch command, update state → if off, ignore → if on, run the workflow below.
When enabled but the message is casual conversation ("hi", "nice weather", "thanks") → do not trigger optimization; reply normally.
Assess task complexity and engine fit:
Output the recommendation and wait for the user to reply "switch" or "continue".
Identify: goal, domain, role, constraints (format / language / audience / length), complexity.
Follow the engine value in state:
| engine | Path |
|---|---|
template-first (default) | Run Step 2a → on match, proceed to CRAFT → on miss, auto-fall back to Step 3 |
llm-only | Skip the library; go straight to Step 3 |
template-only | Run Step 2a → on miss, tell the user; do not call the LLM |
Data source selection:
categories in state is non-empty → read only the listed references/categories/{category}.json filescategories is empty or missing → read the full library file (lite or full)Match the 1-3 most relevant templates by:
Categories: coding | writing | education | business | health-lifestyle | tech-tools | translation | art-entertainment | consulting | creative-generation | data-analysis | science-research | legal-finance | other
On match failure (template-first mode): automatically tell the user "no template matched; optimizing directly with the LLM", then jump to Step 3.
This is the core capability. The host AI acts as a "prompt optimization expert" and picks the matching meta-prompt framework by optimization type:
Fits most scenarios. Output a structured prompt:
# Role: [role name]
## Profile
- language: [language]
- description: [detailed role description]
- background: [role background]
- personality: [personality traits]
- expertise: [domain expertise]
- target_audience: [target users]
## Skills
1. [core skill category]
- [specific skill]: [description]
2. [supporting skill category]
- [specific skill]: [description]
## Rules
1. [basic principles]
2. [behavioral guidelines]
3. [constraints]
## Workflows
- Goal: [clear goal]
- Step 1: [details]
- Step 2: [details]
- Step 3: [details]
- Expected result: [description]
## Initialization
As [role name], you must follow the Rules above and execute tasks per the Workflows.
Core behaviors while optimizing:
For complex business scenarios. Deeply analyze design flaws in the original prompt and provide a detailed improvement plan.
As a prompt engineer, analyze and restructure across 8 dimensions:
Output format is the same as 3a, but each section needs 5 bullet points, plus extra Attention (key points) and Suggestions (methodology) sections.
For fine-tuning an existing prompt.
Core principles:
{{variable}})Comprehension example:
For optimizing user-typed queries (not system prompts).
Refine the user's raw query into a user prompt that is "clear, specific, executable, verifiable":
Compare the prompt before and after; the host AI acts as a "prompt quality assessor".
Dimensions (each 1-10):
| Dimension | Meaning |
|---|---|
| goalClarity | Is the goal clear and explicit |
| instructionCompleteness | Are instructions complete, nothing missing |
| structuralExecutability | Is the structure executable, are steps explicit |
| ambiguityControl | Ambiguity control; any vague wording |
| robustness | Robustness across different inputs |
Output format:
📊 Quality Assessment Report
Original prompt scores:
Goal clarity: [X/10]
Instruction completeness: [X/10]
Structural executability: [X/10]
Ambiguity control: [X/10]
Robustness: [X/10]
Total: [XX/50]
Optimized prompt scores:
Goal clarity: [X/10]
Instruction completeness: [X/10]
Structural executability: [X/10]
Ambiguity control: [X/10]
Robustness: [X/10]
Total: [XX/50]
📈 Improvement: [+XX points]
💡 Improvement highlights:
1. [specific improvement]
2. [specific improvement]
3. [specific improvement]
⚠️ Still improvable:
1. [further direction]
2. [further direction]
Assessment principles:
Applied uniformly on top of Step 2 (template) or Step 3 (LLM) output:
Default Level 2 (standard CRAFT); Level 3 (+CoT +few-shot) for complex analysis/creative work; Level 1 (role+format) for quick optimization.
Generate the prompt in the user's configured output format (plain text by default).
📋 Original input: [user's words] 🔧 Engine: [template match / LLM meta-prompt / dual engine] 📎 Reference template: [template name or "generated directly by LLM"]
✨ Optimized prompt:
[Full prompt — in the user's configured format]
🔄 Change notes: [1-2 sentences] 📎 Output format: [plain text / Markdown / XML / all]
👆 Reply "✅" to use it / "❌" to discard and keep the original / give feedback to fine-tune / "change format" to switch output format / "optimize again" for another round / "assess" to see quality scores
Wait for the user's reply before executing.
[placeholder] for placeholders