[FEATURE] Add "StartedToolUse" hook
Preflight Checklist
- [x] I have searched existing requests and this feature hasn't been requested yet
- [x] This is a single feature request (not multiple features)
Problem Statement
It would be great if there was a way to be notified when a tool use is _actually_ started, vs PreToolUse which happens before permissions are granted / other hooks. For Bash tool uses, it might be nice to also have the process id of the shell available, but that isn't strictly necessary for my immediate needs.
Proposed Solution
Add a new hook event, perhaps called StartedToolUse, which would look similar to PreToolUse, but would be triggered either right before actually making the tool call, or perhaps immediately after (which would have the benefit of allowing for conveying the process ID of the shell for Bash tool calls, if that's an acceptable special case -- having the pid might allow for other interesting integrations):
{
"session_id": "99dce4b4-...",
"transcript_path": "/Users/.../.claude/projects/.../99dce4b4-....jsonl",
"cwd": "/Users/cstrahan/src/project",
"permission_mode": "default",
"hook_event_name": "StartedToolUse",
"tool_name": "Bash",
"tool_input": {"command": "echo hello", "description": "Run echo"},
"tool_use_id": "toolu_017yme1zyeym1BuTevLyFRCy"
}
Alternative Solutions
_No response_
Priority
Critical - Blocking my work
Feature Category
CLI commands and flags
Use Case Example
For some motivating context, I have set up PreToolUse/PostToolUse/PostToolUseFailure hooks for Bash tool calls which invokes a script (claude-atuin-hook.py) that logs the commands to a shell history database managed by Atuin. With this setup, I can quickly perform a fuzzy reverse-history-search of commands Claude Code has run (I have the usual Ctrl+R set up for _my_ command history, with Ctrl+X Ctrl+R set up for searching through just commands Claude Code has run), which is very convenient when I know that there was a command that is identical (or very close) to what I would like to run (e.g. the helm upgrade commands it ran recently, or some arcane kubectl stuff while it was debugging something, etc).
However, this design has two undesirable quirks:
- If the user is prompted for permission, then the start time that is logged in Atuin's database reflects the time that the permission was requested, _not_ when the command was actually run.
- This then also throws off the time duration associated with the command, as the duration is considered to start at the initial request for permission (when the PreToolUse was handled) and ending at the time that the PostToolUse is triggered.
- If the user doesn't grant the tool use (or a hook denies the tool use) then we end up logging a command that wasn't actually run.
Additional Context
_No response_
This issue has 3 comments on GitHub. Read the full discussion on GitHub ↗