Skip to content

A hook system for Claude Code that automatically enhances user prompts with predefined templates.

License

Notifications You must be signed in to change notification settings

varienos/claude-code-prompt-enhancer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Claude Code Prompt Enhancer

A hook system for Claude Code that automatically enhances user prompts with predefined templates.

Overview

This tool intercepts user messages sent to Claude Code and injects them into customizable templates. This allows you to:

  • Apply consistent instructions to every task
  • Include project-specific guidelines automatically
  • Combine user input with structured frameworks
  • Ensure quality standards are always followed

How It Works

User Message --> Hook --> Template Injection --> Enhanced Prompt --> Claude
  1. User sends a message: "Add user authentication"
  2. Hook captures the message
  3. Template is loaded from .claude/prompt-template.md
  4. [PROMPT] placeholder is replaced with user's message
  5. Enhanced prompt is sent to Claude with full context

Requirements

  • Claude Code CLI
  • bash
  • Python 3.6+
  • jq (JSON processor)

Installing jq

# macOS
brew install jq

# Ubuntu/Debian
sudo apt-get install jq

# Windows (WSL)
sudo apt-get install jq

Installation

Step 1: Copy Hook Files

# Create hooks directory in your project
mkdir -p YOUR_PROJECT/.claude/hooks

# Copy the hook script
cp hooks/enhance-prompt.sh YOUR_PROJECT/.claude/hooks/

# Make it executable
chmod +x YOUR_PROJECT/.claude/hooks/enhance-prompt.sh

Note: The Python helper script is auto-generated by the shell script on first run.

Step 2: Create Your Template

# Copy an existing template
cp templates/basic-template.md YOUR_PROJECT/.claude/prompt-template.md

# Or create your own with [PROMPT] placeholder

Step 3: Configure Claude Code

Add to your .claude/settings.json:

{
  "hooks": {
    "UserPromptSubmit": [
      {
        "matcher": "",
        "hooks": [
          {
            "type": "command",
            "command": "bash ${CLAUDE_PROJECT_DIR}/.claude/hooks/enhance-prompt.sh"
          }
        ]
      }
    ]
  }
}

Template Format

Templates use a simple placeholder system. The [PROMPT] placeholder is replaced with the user's message:

## Task
[PROMPT]

---

## Instructions

1. Follow these guidelines
2. Use these best practices
3. Apply these standards

---

## Success Criteria

- [ ] Requirement 1
- [ ] Requirement 2

Included Templates

Template Description
basic-template.md Simple task structure with basic guidelines
advanced-template.md Multi-phase workflow with quality standards

Usage Examples

Basic Usage

Template (.claude/prompt-template.md):

## Task
[PROMPT]

Please follow best practices and write tests.

User Input:

Add user login

Result sent to Claude:

## Task
Add user login

Please follow best practices and write tests.

Advanced Workflow

Template:

## Task
[PROMPT]

## Workflow
1. Plan the implementation
2. Write clean code
3. Add tests
4. Document changes

## Success Criteria
- [ ] All tests passing
- [ ] Code reviewed
- [ ] Documentation updated

Configuration

Custom Template Location

Edit enhance-prompt.sh to change the template path:

TEMPLATE_FILE="${CLAUDE_PROJECT_DIR}/.claude/prompt-template.md"

Disable Hook Temporarily

Remove the hook configuration from .claude/settings.json or set an empty array:

{
  "hooks": {
    "UserPromptSubmit": []
  }
}

Skip Enhancement for Specific Messages

Modify enhance-prompt.sh to skip certain messages:

# Skip if message contains a flag
if echo "$USER_PROMPT" | grep -q "#skip"; then
  echo '{"continue": true}'
  exit 0
fi

Project Structure

claude-code-prompt-enhancer/
├── hooks/
│   └── enhance-prompt.sh    # Main hook script
├── templates/
│   ├── basic-template.md    # Simple template
│   └── advanced-template.md # Multi-phase template
├── examples/
│   └── settings.json        # Example configuration
├── docs/
│   ├── INSTALLATION.md      # Detailed installation guide
│   ├── USAGE.md             # Usage examples
│   └── CONTRIBUTING.md      # Contribution guidelines
├── LICENSE
└── README.md

Troubleshooting

Hook not working

  1. Check file permissions:

    chmod +x .claude/hooks/enhance-prompt.sh
  2. Verify template exists:

    ls -la .claude/prompt-template.md
  3. Test hook manually:

    echo '{"prompt": "test message"}' | bash .claude/hooks/enhance-prompt.sh
  4. Check jq is installed:

    which jq

Template not loading

  • Ensure the template file path is correct
  • Check file encoding (should be UTF-8)
  • Verify [PROMPT] placeholder exists in the template

Python errors

  • Verify Python 3 is installed: python3 --version
  • Check the auto-generated Python script at .claude/hooks/enhance-prompt.py

Use Cases

  • Team Standardization: Ensure all team members follow the same workflow
  • Quality Assurance: Automatically include testing and review requirements
  • Project Guidelines: Embed project-specific rules and standards
  • Onboarding: Guide new developers with structured task frameworks

Contributing

Contributions are welcome. Please:

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Submit a pull request

See CONTRIBUTING.md for details.

License

MIT License - see LICENSE for details.

About

A hook system for Claude Code that automatically enhances user prompts with predefined templates.

Resources

License

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages