Claude Code Prompt Improver
This file provides guidance to Claude Code when working with code in this repository.
Overview
A UserPromptSubmit hook plugin that enriches vague prompts before Claude Code executes them. Uses skill-based architecture with hook-level evaluation for efficient prompt clarity assessment.
Core functionality:
- Intercepts prompts via UserPromptSubmit hook
- Evaluates clarity using conversation history
- Clear prompts: proceeds immediately with minimal overhead
- Vague prompts: invokes prompt-improver skill for research and clarification
- Uses AskUserQuestion tool for targeted clarifying questions (1-6 questions)
Build & Development Commands
Testing:
- Run all tests:
pytest tests/ or python -m pytest
- Run specific test suite:
- Hook tests:
pytest tests/test_hook.py
- Skill tests:
pytest tests/test_skill.py
- Integration tests:
pytest tests/test_integration.py
Installation:
- Add marketplace:
claude plugin marketplace add severity1/severity1-marketplace
- Via marketplace:
claude plugin install prompt-improver@severity1-marketplace
- Local dev:
claude plugin marketplace add /path/to/claude-code-prompt-improver/.dev-marketplace/.claude-plugin/marketplace.json then claude plugin install prompt-improver@local-dev
- Manual hook:
cp scripts/improve-prompt.py ~/.claude/hooks/ && chmod +x ~/.claude/hooks/improve-prompt.py
Architecture
Hook Layer (scripts/improve-prompt.py):
- Evaluation orchestrator - reads stdin JSON, writes stdout JSON
- Handles bypass prefixes:
* (skip), / (slash commands), # (memorize)
- Wraps prompts with evaluation instructions for clarity assessment
- Claude evaluates clarity using conversation history
- If vague: instructs Claude to invoke prompt-improver skill
Skill Layer (skills/prompt-improver/):
SKILL.md: Research and question workflow
- 4-phase process: Research, Questions, Clarify, Execute
- Assumes prompt already determined vague by hook
- Links to reference files for progressive disclosure
references/: Detailed guides loaded on-demand
question-patterns.md: Question templates and effective patterns
research-strategies.md: Context gathering strategies
examples.md: Real prompt transformations
Directory structure:
scripts/ - Hook implementation
skills/prompt-improver/ - Skill and reference files
tests/ - Test suite (hook, skill, integration)
hooks/ - Hook configuration (hooks.json, auto-discovered)
.claude-plugin/ - Plugin metadata
Code Conventions
Hook output format:
- JSON structure following Claude Code specification
- Format:
{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}
- Exit code 0 for all success paths
- Hook commands use
python3 || python fallback for Windows compatibility
Bypass prefixes:
* prefix: Skip evaluation entirely, strip prefix from prompt
/ prefix: Slash commands bypass automatically
# prefix: Memorize commands bypass automatically
File paths:
- Use forward slashes (Unix-style) per Claude Code standards
- All paths in plugin configuration use forward slashes
Skill structure:
- YAML frontmatter with name and description
- Skill name: lowercase, hyphens, max 64 chars
- Description: under 1024 chars, includes activation triggers
- Reference files: self-contained, one-level deep
- Writing style: imperative/infinitive form (avoid "you/your")
Testing:
- Tests use pytest-compatible functions (no test classes)
- Hook tests run the script via subprocess and validate JSON output
- Skill tests validate file structure, frontmatter, and references
- Integration tests verify end-to-end flow and architecture separation
- Python standard library only (json, sys, subprocess, pathlib, re)
Detected Patterns
Progressive disclosure:
- Clear prompts: evaluation only, no skill load
- Vague prompts: evaluation + skill load + references
- Reference materials load only when needed
- Zero context penalty for unused reference materials
Evaluation flow:
- Hook wraps prompt with evaluation instructions
- Claude evaluates using conversation history
- If clear: proceed immediately
- If vague: invoke prompt-improver skill, then research, questions, execute
Research and questioning:
- Create dynamic research plan via TodoWrite
- Research what needs clarification (not just the project)
- Ground questions in research findings (not generic assumptions)
- Support 1-6 questions for complex scenarios
- Use conversation history to avoid redundant exploration
Git Insights
Key architectural decisions:
- Migrated from hook-only to skill-based architecture for significant token reduction on clear prompts
- Hook auto-discovery:
hooks/hooks.json at standard location removes need for hooks field in plugin.json
- Plugin distributed via severity1-marketplace for easy installation
- Progressive disclosure pattern chosen to minimize context overhead for the common case (clear prompts)
Evolution:
- Started as embedded evaluation logic in hook script
- Extracted skill layer to separate evaluation (hook) from enrichment (skill)
- Added marketplace support for distribution
Best Practices
- Keep hook script minimal - it runs on every prompt submission
- Never add heavy imports or network calls to the hook script
- Reference files should be self-contained so they work when loaded independently
- Test bypass prefixes whenever modifying hook logic to prevent breaking slash commands
- When adding new bypass prefixes, update both the hook script and the conventions section
Design Philosophy
- Rarely intervene - Most prompts pass through unchanged
- Trust user intent - Only ask when genuinely unclear
- Use conversation history - Avoid redundant exploration
- Max 1-6 questions - Enough for complex scenarios, still focused
- Transparent - Evaluation visible in conversation
1---2name: 082-claude-a046bde93description: Claude Code Prompt Improver4---5# Claude Code Prompt Improver67This file provides guidance to Claude Code when working with code in this repository.89<!-- AUTO-MANAGED: project-description -->10## Overview1112A UserPromptSubmit hook plugin that enriches vague prompts before Claude Code executes them. Uses skill-based architecture with hook-level evaluation for efficient prompt clarity assessment.1314**Core functionality:**15- Intercepts prompts via UserPromptSubmit hook16- Evaluates clarity using conversation history17- Clear prompts: proceeds immediately with minimal overhead18- Vague prompts: invokes prompt-improver skill for research and clarification19- Uses AskUserQuestion tool for targeted clarifying questions (1-6 questions)20<!-- END AUTO-MANAGED -->2122<!-- AUTO-MANAGED: build-commands -->23## Build & Development Commands2425**Testing:**26- Run all tests: `pytest tests/` or `python -m pytest`27- Run specific test suite:28 - Hook tests: `pytest tests/test_hook.py`29 - Skill tests: `pytest tests/test_skill.py`30 - Integration tests: `pytest tests/test_integration.py`3132**Installation:**33- Add marketplace: `claude plugin marketplace add severity1/severity1-marketplace`34- Via marketplace: `claude plugin install prompt-improver@severity1-marketplace`35- Local dev: `claude plugin marketplace add /path/to/claude-code-prompt-improver/.dev-marketplace/.claude-plugin/marketplace.json` then `claude plugin install prompt-improver@local-dev`36- Manual hook: `cp scripts/improve-prompt.py ~/.claude/hooks/ && chmod +x ~/.claude/hooks/improve-prompt.py`37<!-- END AUTO-MANAGED -->3839<!-- AUTO-MANAGED: architecture -->40## Architecture4142**Hook Layer (scripts/improve-prompt.py):**43- Evaluation orchestrator - reads stdin JSON, writes stdout JSON44- Handles bypass prefixes: `*` (skip), `/` (slash commands), `#` (memorize)45- Wraps prompts with evaluation instructions for clarity assessment46- Claude evaluates clarity using conversation history47- If vague: instructs Claude to invoke prompt-improver skill4849**Skill Layer (skills/prompt-improver/):**50- `SKILL.md`: Research and question workflow51 - 4-phase process: Research, Questions, Clarify, Execute52 - Assumes prompt already determined vague by hook53 - Links to reference files for progressive disclosure54- `references/`: Detailed guides loaded on-demand55 - `question-patterns.md`: Question templates and effective patterns56 - `research-strategies.md`: Context gathering strategies57 - `examples.md`: Real prompt transformations5859**Directory structure:**60- `scripts/` - Hook implementation61- `skills/prompt-improver/` - Skill and reference files62- `tests/` - Test suite (hook, skill, integration)63- `hooks/` - Hook configuration (hooks.json, auto-discovered)64- `.claude-plugin/` - Plugin metadata65<!-- END AUTO-MANAGED -->6667<!-- AUTO-MANAGED: conventions -->68## Code Conventions6970**Hook output format:**71- JSON structure following Claude Code specification72- Format: `{"hookSpecificOutput": {"hookEventName": "UserPromptSubmit", "additionalContext": "..."}}`73- Exit code 0 for all success paths74- Hook commands use `python3 || python` fallback for Windows compatibility7576**Bypass prefixes:**77- `*` prefix: Skip evaluation entirely, strip prefix from prompt78- `/` prefix: Slash commands bypass automatically79- `#` prefix: Memorize commands bypass automatically8081**File paths:**82- Use forward slashes (Unix-style) per Claude Code standards83- All paths in plugin configuration use forward slashes8485**Skill structure:**86- YAML frontmatter with name and description87- Skill name: lowercase, hyphens, max 64 chars88- Description: under 1024 chars, includes activation triggers89- Reference files: self-contained, one-level deep90- Writing style: imperative/infinitive form (avoid "you/your")9192**Testing:**93- Tests use pytest-compatible functions (no test classes)94- Hook tests run the script via subprocess and validate JSON output95- Skill tests validate file structure, frontmatter, and references96- Integration tests verify end-to-end flow and architecture separation97- Python standard library only (json, sys, subprocess, pathlib, re)98<!-- END AUTO-MANAGED -->99100<!-- AUTO-MANAGED: patterns -->101## Detected Patterns102103**Progressive disclosure:**104- Clear prompts: evaluation only, no skill load105- Vague prompts: evaluation + skill load + references106- Reference materials load only when needed107- Zero context penalty for unused reference materials108109**Evaluation flow:**1101. Hook wraps prompt with evaluation instructions1112. Claude evaluates using conversation history1123. If clear: proceed immediately1134. If vague: invoke prompt-improver skill, then research, questions, execute114115**Research and questioning:**116- Create dynamic research plan via TodoWrite117- Research what needs clarification (not just the project)118- Ground questions in research findings (not generic assumptions)119- Support 1-6 questions for complex scenarios120- Use conversation history to avoid redundant exploration121<!-- END AUTO-MANAGED -->122123<!-- AUTO-MANAGED: git-insights -->124## Git Insights125126**Key architectural decisions:**127- Migrated from hook-only to skill-based architecture for significant token reduction on clear prompts128- Hook auto-discovery: `hooks/hooks.json` at standard location removes need for `hooks` field in `plugin.json`129- Plugin distributed via severity1-marketplace for easy installation130- Progressive disclosure pattern chosen to minimize context overhead for the common case (clear prompts)131132**Evolution:**133- Started as embedded evaluation logic in hook script134- Extracted skill layer to separate evaluation (hook) from enrichment (skill)135- Added marketplace support for distribution136<!-- END AUTO-MANAGED -->137138<!-- AUTO-MANAGED: best-practices -->139## Best Practices140141- Keep hook script minimal - it runs on every prompt submission142- Never add heavy imports or network calls to the hook script143- Reference files should be self-contained so they work when loaded independently144- Test bypass prefixes whenever modifying hook logic to prevent breaking slash commands145- When adding new bypass prefixes, update both the hook script and the conventions section146<!-- END AUTO-MANAGED -->147148<!-- MANUAL -->149## Design Philosophy150151- **Rarely intervene** - Most prompts pass through unchanged152- **Trust user intent** - Only ask when genuinely unclear153- **Use conversation history** - Avoid redundant exploration154- **Max 1-6 questions** - Enough for complex scenarios, still focused155- **Transparent** - Evaluation visible in conversation156<!-- END MANUAL -->