🎯 PreToolUse Modification Hooks Plugin - First Claude Code Plugin with Intelligent Input Modification
🎯 PreToolUse Modification Hooks Plugin v2.5.0-alpha.140
The First Claude Code Plugin with Intelligent Tool Input Modification
We're excited to announce the release of Claude-Flow's PreToolUse Modification Hooks Plugin - the first plugin to leverage Claude Code v2.0.10+'s groundbreaking PreToolUse feature for automatic tool input enhancement.
🌟 What Is This?
This plugin automatically modifies tool inputs before execution, providing:
- 🛡️ Safety - Prevents destructive operations
- 📁 Organization - Enforces project structure
- ⚡ Productivity - Expands shortcuts and formats commits
✨ Key Features
🛡️ Safety Enhancements
- Auto-adds
-iflag tormcommands for interactive confirmation - Detects sensitive keywords (password, token, api-key) and warns before execution
- Prevents accidental destruction of production files
📁 Intelligent File Organization
- Never saves to root - Working files automatically routed to proper directories
- Auto-organization:
- Test files →
/tests/ - Source files →
/src/ - Working docs →
/docs/working/ - Temp files →
/tmp/
- Test files →
- Format hints - Suggests Prettier, ESLint, Black based on file type
⚡ Developer Productivity
- Alias expansion:
ll→ls -lah,la→ls -la - Conventional commits: Auto-formats with
[feat],[fix],[docs]prefixes - JIRA integration: Extracts ticket numbers from branch names
- Co-authorship: Adds
Co-Authored-By: claude-flow <[email protected]>
🚀 Installation
Method 1: Direct Plugin Installation (Recommended)
# In Claude Code:
/plugin ruvnet/claude-flow
Method 2: Via NPM
npx claude-flow@alpha init --force
📖 Examples
Bash Safety
# Your command:
rm test.txt
# Auto-modified to:
rm -i test.txt
# Note: [Safety: Added -i flag for interactive confirmation]
File Organization
# Your write:
test.js
# Auto-saved to:
src/test.js
# Note: [Organization: Moved source file to /src/] [Tip: Auto-format with Prettier recommended]
Git Commits
# Your commit:
git commit -m "fix auth bug"
# Enhanced to:
[fix] fix auth bug
🤖 Generated with Claude Flow
Co-Authored-By: claude-flow <[email protected]>
# Note: [Auto-formatted: fix type]
Alias Expansion
# Your command:
ll
# Auto-expanded to:
ls -lah
# Note: [Alias: ll → ls -lah]
🔧 How It Works
The plugin uses Claude Code v2.0.10+'s PreToolUse hook system to intercept and modify tool inputs before execution:
- Claude generates a command (e.g.,
rm test.txt) - PreToolUse hook intercepts the JSON input
- Plugin analyzes and modifies (adds
-iflag) - Modified command executes (
rm -i test.txt) - User sees enhanced version in output
All modifications happen atomically in memory - no intermediate states, clean git history.
🏗️ Technical Implementation
Stdin/Stdout Protocol
The plugin follows PreToolUse's JSON protocol:
Input:
{
"tool_input": {
"command": "rm test.txt"
}
}
Output:
{
"tool_input": {
"command": "rm -i test.txt"
},
"modification_notes": "[Safety: Added -i flag for interactive confirmation]"
}
Environment Detection
Uses 100ms timeout-based stdin detection to handle all environments:
- ✅ Local development
- ✅ Remote SSH sessions
- ✅ Docker containers
- ✅ Codespaces/Gitpod
- ✅ Any environment where
process.stdin.isTTYmay be undefined
📦 Plugin Structure
.claude-plugin/
├── hooks/
│ └── hooks.json # PreToolUse configuration
├── marketplace.json # Plugin metadata
└── README.md # Plugin documentation
🔌 Composability
The plugin is fully composable with other stdin/stdout tools:
{
"matcher": "Write|Edit",
"hooks": [
{"command": "cat | npx claude-flow@alpha hooks modify-file"},
{"command": "cat | npx agent-booster optimize-content"},
{"command": "cat | npx prettier-cli format-stdin"}
]
}
Pipeline: File path modification → Code optimization → Formatting → Single atomic write
📚 Documentation
- Full Guide: docs/HOOKS-V2-MODIFICATION.md
- Plugin Files: .claude-plugin/
- Implementation: src/cli/simple-commands/hooks.js
🎯 Target Markets
- Enterprise Development Teams - Safety & standardization
- Open Source Maintainers - Automated code quality
- AI-Powered Development Tools - Claude Code ecosystem integration
- DevOps & Platform Engineers - Infrastructure-as-code safety
💰 Tiers
- Free (Open Source): Core hooks, community support
- Pro ($19/mo): Advanced memory injection, swarm coordination, neural training
- Enterprise: Custom hooks, SLA, training
🚀 Next Steps
For Users
- Install the plugin:
/plugin ruvnet/claude-flow - Try it out with various commands
- Report any issues or suggestions below
- Share your experience with the community
For Contributors
- Review the implementation in PR #790
- Suggest additional hook ideas (memory injection, swarm coordination, etc.)
- Help with documentation and examples
- Build composable integrations (agent-booster, prettier, etc.)
🐛 Testing & Feedback
We need your help testing!
Please try the plugin and report:
- ✅ What works well
- 🐛 Any bugs or issues
- 💡 Feature suggestions
- 📊 Performance impact
- 🤔 UX improvements
Test these scenarios:
- File writes in different directories
- Destructive bash commands (rm, mv, etc.)
- Git commits with various message formats
- Alias expansion (ll, la)
- Files with different extensions (.js, .ts, .py, .go)
📊 Success Metrics (Month 12 Targets)
- 5,000+ GitHub stars
- 50,000 npm downloads/month
- $25K MRR
- 15 enterprise customers
- 90%+ error prevention rate
- 30+ minutes saved per developer per week
🤝 Related
- PR: #790 - Implementation
- Requires: Claude Code >= v2.0.10
- Works with:
agent-booster,prettier, and any stdin/stdout tool - Future: Memory injection hooks, swarm coordination hooks, neural training automation
📢 Spread the Word
If you find this useful, please:
- ⭐ Star the repo
- 🐦 Share on Twitter
- 💬 Tell your team
- 📝 Write a blog post
- 🎥 Create a demo video
Built with ❤️ by rUv
🤖 Generated with Claude Flow
Co-Authored-By: claude-flow [email protected]