← 2.1.9 Test tested · runtime-test

PreToolUse additionalContext — runtime test

Hands-on runtime battle-test of PreToolUse additionalContext. Result: PASS.

PreToolUse additionalContext provides a runtime mechanism for hooks to inject contextual data into the model before tool execution.

How it works

The PreToolUse hook system supports returning JSON with an additionalContext field. When a hook outputs valid JSON containing this field, the Claude Code runtime parses it and injects the context as a system reminder to the model before the tool executes. The hook fires before the tool (Read, Write, Bash, etc.) and does not block execution.

The hook format uses a command-type matcher:

hooks:
  PreToolUse:
    - matcher: "Read"
      hooks:
        - type: command
          command: |
            echo '{"additionalContext": "Context to inject to model"}'

What the test found

The runtime test (2026-01-16) verified four behaviors: hook execution before tool use, JSON parsing of the additionalContext field, context injection as system reminder, and non-blocking execution. All four behaviors passed. The test used a skill-scoped hook that echoed JSON to stdout, confirming the runtime correctly parses and injects the context into the model's context window.

Why it matters

This feature enables four practical use cases: security warnings (alert before reading sensitive files), context enrichment (add metadata about files), audit logging (track tool usage with injected context), and dynamic guidance (provide situational instructions). Hooks can inspect file paths or tool arguments and inject conditional guidance without halting execution.

Technical notes

Hooks must output valid JSON to stdout with the additionalContext key. The context appears as a <system-reminder> block in the model's system context. The mechanism works with both skill-scoped and global hooks, making it composable across tool invocations.

Primary source
⎘ 2.1.9/tests/02-additional-context/TEST-RESULTS.mdverbatim from the corpus

Test Results: PreToolUse additionalContext

Feature: Added support for PreToolUse hooks to return additionalContext to the model

Tested: 2026-01-16 Version: 2.1.9

Test Method

  1. Created skill with PreToolUse hook that returns additionalContext
  2. Triggered tool use to fire hook
  3. Verified context was injected

Result: PASS

The hook returns JSON with additionalContext field, and that context appears as a system reminder to the model.

Hook Format

hooks:
  PreToolUse:
    - matcher: "Read"
      hooks:
        - type: command
          command: |
            echo '{"additionalContext": "Context to inject to model"}'

Verified Behaviors

  1. Hook fires before tool - Runs before Read/Write/etc
  2. JSON parsed - Must return valid JSON with additionalContext key
  3. Context injected - Appears as system reminder in model context
  4. Non-blocking - Hook doesn't prevent tool execution

Use Cases

  1. Security warnings - Warn about sensitive files before reading
  2. Context enrichment - Add metadata about files/tools
  3. Audit logging - Log tool usage with context injection
  4. Dynamic guidance - Provide situational instructions

Test Skill

See .claude/skills/test-pretooluse-context/SKILL.md for the test skill.

Architecture Notes

  • Hook must output JSON to stdout
  • Only additionalContext field is used
  • Context appears as <system-reminder> block
  • Works with skill-scoped and global hooks

Status: PASS

Evidence & receipt
◇ ed25519 receipt
idtest_88defaf737e2dba9c41ce53f
alged25519
pubkey9b87705613b1e2fd064d57fa75a6b679d2856ceafad6b1daa8f982493871b6dd
sigb6b423e1d3937db244d3124a166ef604af6c513e6a3d8d3711c7fe51ed28441c8d506f1053103c9055dcf0f4ddd2e30ce0453f81e8089f8e925b082bd7eeda08

Signed with an ed25519 key held off the repo. Anyone can verify against the published public key; nobody without the secret key can forge it. Click verify: it recomputes the signature in your browser. The signature proves integrity and authorship of this exact content — not a third-party timestamp or that the underlying claim is objectively true. signedAt is when the @f3/attest pipeline ran, not when the work happened; the evidence refs carry the source dates.

Connected