Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # .claude/settings.json
- ```
- {
- "hooks": {
- "UserPromptSubmit": [
- {
- "hooks": [
- {
- "type": "command",
- "command": "$CLAUDE_PROJECT_DIR/.claude/hooks/prepend_plan_agent.py"
- }
- ]
- }
- ]
- }
- }
- ```
- # .claude/hooks/prepend_plan_agent.py
- ```
- #!/usr/bin/env python3
- import json
- import sys
- try:
- # Read the JSON data passed from Claude Code via stdin
- input_data = json.load(sys.stdin)
- # Check if the current permission mode is 'plan'
- if input_data.get("permission_mode") == "plan":
- original_prompt = input_data.get("prompt", "")
- # Important: Only add the prefix if the user hasn't already typed it.
- # This prevents a double-trigger like "@agent-Plan @agent-Plan ..."
- if not original_prompt.strip().lower().startswith("@agent-plan"):
- # Prepend the built-in agent trigger to the user's prompt
- updated_prompt = f"@agent-Plan {original_prompt}"
- # Construct the JSON output to update the prompt
- output = {
- "hookSpecificOutput": {
- "hookEventName": "UserPromptSubmit",
- "updatedPrompt": updated_prompt
- }
- }
- # Print the JSON to stdout for Claude Code to process
- print(json.dumps(output))
- except (json.JSONDecodeError, KeyError):
- # Fail silently, allowing the original prompt to go through if there's an error
- pass
- # Always exit with code 0 to indicate success
- sys.exit(0)
- ```
Advertisement
Add Comment
Please, Sign In to add comment