[FEATURE] Support additionalContext in PreToolUse hooks
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
PostToolUse hooks support additionalContext to inject information into Claude's context after a tool runs. However, PostToolUse only fires when a tool completes successfully - it doesn't run when commands fail.
This is problematic for "first-use documentation injection" patterns where you want to show Claude the docs for a CLI tool the first time it's used. If the user runs mytool hello and hello isn't a valid subcommand (exit code 2), the PostToolUse hook never fires and Claude never sees the documentation that would help it understand the correct usage.
Proposed Solution
Add additionalContext support to PreToolUse hooks, matching the PostToolUse behavior:
{
"hookSpecificOutput": {
"hookEventName": "PreToolUse",
"additionalContext": "Documentation or context to inject for Claude"
}
}
This would allow hooks to inject context before the tool runs, ensuring Claude sees the information regardless of whether the command succeeds or fails.
Alternative Solutions
- Make PostToolUse fire on failure too - Could add a config option like
"runOnFailure": true, but this changes existing behavior - Have CLI tools print docs on error - Requires per-tool changes and clutters stderr
- Accept the limitation - But this defeats the purpose of first-use documentation injection
Priority
Medium - Enables important hook use cases
Feature Category
Hooks
Use Case Example
I have a hook that detects first-time use of CLI tools and injects their documentation (via clocki command structure + quick guide). Currently:
# First call - command fails, PostToolUse doesn't run, no docs injected
$ saffi hello
Error: No such command 'hello'.
# Claude doesn't see the saffi documentation
# Second call - command succeeds, but first-use already "spent"
$ saffi --help
# Now PostToolUse fires, but it's not first-use anymore
With PreToolUse additionalContext support:
# First call - PreToolUse injects docs BEFORE command runs
$ saffi hello
# Claude already has saffi docs, can suggest correct usage
Error: No such command 'hello'.
Additional Context
Current PreToolUse output options per documentation:
permissionDecision: allow/deny/askpermissionDecisionReason: shown to user only, NOT to ClaudeupdatedInput: modify tool input
The permissionDecisionReason explicitly does NOT get shown to Claude, so there's currently no way to inject context in PreToolUse.
7 Comments
Found 1 possible duplicate issue:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
The bot flagged #6965 as a duplicate, but that issue was auto-closed due to inactivity and is now locked. Keeping this open as the feature was never implemented or addressed.
Hopefully this gets added. Just ran into this. I wanted to inject relevant context whenever CC is editing files in specific directories, and for now am trying to do it with a PostToolHook that triggers after reads. Would be way cleaner if PreTool supported additional context.
Feature was implemented in v2.1.9.
-Added support for PreToolUse hooks to return additionalContext to the model
👍
Woohoo! Thank you Claude Code team!
Indeed.
I requested this feature as well (above).
I also tweeted to Anthropic employees as well...which I hope helped to push it to the top of the list.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.