Guest User

explanation of hook

a guest
Oct 27th, 2025
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.40 KB | None | 0 0
  1. Here is a detailed explanation of this hook's use case.
  2.  
  3. ### High-Level Use Case
  4.  
  5. The primary use case of this hook is **to automatically make "Plan Mode" more powerful and efficient by default.**
  6.  
  7. It achieves this by ensuring that whenever a user is in the read-only "Plan Mode", their prompts are automatically handled by the specialized, fast, and efficient `Plan` subagent without the user needing to remember to invoke it manually.
  8.  
  9. ---
  10.  
  11. ### How It Works: Step-by-Step
  12.  
  13. 1. **Trigger Event**: The hook is configured in `settings.json` to run on the `UserPromptSubmit` event. This means the script executes *after* you type a prompt and press Enter, but *before* Claude starts processing it.
  14.  
  15. 2. **Mode Check**: The Python script (`prepend_plan_agent.py`) first checks if the current `permission_mode` is `"plan"`. If you are in any other mode (like `default` or `acceptEdits`), the script does nothing.
  16.  
  17. 3. **Prompt Modification**: If you are in "Plan Mode", the script takes your prompt (e.g., `"show me all API endpoints"`) and automatically prepends it with `@agent-Plan`.
  18.  
  19. 4. **Returning the New Prompt**: The script then returns a JSON object to Claude Code, instructing it to replace your original prompt with the new, modified one (e.g., `"@agent-Plan show me all API endpoints"`).
  20.  
  21. 5. **Subagent Invocation**: Claude Code receives this modified prompt and, seeing the `@agent-Plan` trigger, delegates the task to the built-in `Plan` subagent.
  22.  
  23. ### The "Why": Solving a User Experience Problem
  24.  
  25. From the changelog you provided (version 2.0.28), we know that Claude Code introduced a new, specialized `Plan` subagent.
  26.  
  27. > **Plan**: Fast agent specialized for exploring codebases. Use this when you need to quickly find files by patterns..., search code for keywords..., or answer questions about the codebase...
  28.  
  29. This subagent is optimized for the exact kind of read-only exploration that "Plan Mode" is designed for.
  30.  
  31. * **The Problem:** Without this hook, a user in Plan Mode would have to remember to manually type `@agent-Plan` before every single query to get the best performance. Forgetting to do so would mean the general-purpose agent handles the request, which might be slower or less efficient for exploration tasks.
  32.  
  33. * **The Solution (This Hook):** This hook automates that best practice. It creates a seamless experience where **Plan Mode is automatically powered by the Plan subagent**. The user can just focus on their questions, and the system ensures the best tool is used for the job behind the scenes.
  34.  
  35. ### Practical Example
  36.  
  37. **Without the Hook:**
  38.  
  39. 1. You enable Plan Mode (`Shift+Tab`).
  40. 2. You type: `find all files that import the 'requests' library`.
  41. 3. The main Claude agent processes this, searching the codebase.
  42. 4. To get better performance, you have to remember to type: `@agent-Plan find all files that import the 'requests' library`.
  43.  
  44. **With the Hook:**
  45.  
  46. 1. You enable Plan Mode (`Shift+Tab`).
  47. 2. You type: `find all files that import the 'requests' library`.
  48. 3. The hook intercepts this, automatically changes it to `"@agent-Plan find all files that import the 'requests' library"`.
  49. 4. The specialized, faster `Plan` subagent immediately takes over, giving you a more efficient result.
  50.  
  51. In short, this hook is a quality-of-life improvement that links the **"Plan Mode" feature** directly to the **`Plan` subagent**, making the experience smarter and more intuitive for the user.
Advertisement
Add Comment
Please, Sign In to add comment