claude-flow icon indicating copy to clipboard operation
claude-flow copied to clipboard

🎯 PreToolUse Modification Hooks Plugin - First Claude Code Plugin with Intelligent Input Modification

Open ruvnet opened this issue 2 months ago • 0 comments

🎯 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 -i flag to rm commands 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/
  • Format hints - Suggests Prettier, ESLint, Black based on file type

⚡ Developer Productivity

  • Alias expansion: llls -lah, lals -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:

  1. Claude generates a command (e.g., rm test.txt)
  2. PreToolUse hook intercepts the JSON input
  3. Plugin analyzes and modifies (adds -i flag)
  4. Modified command executes (rm -i test.txt)
  5. 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.isTTY may 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

🎯 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

  1. Install the plugin: /plugin ruvnet/claude-flow
  2. Try it out with various commands
  3. Report any issues or suggestions below
  4. Share your experience with the community

For Contributors

  1. Review the implementation in PR #790
  2. Suggest additional hook ideas (memory injection, swarm coordination, etc.)
  3. Help with documentation and examples
  4. 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]

ruvnet avatar Oct 09 '25 22:10 ruvnet