Agent Wealth HubFree public resources
中文 EN العربية

Back to catalog / Agent context

Inject scoped context at session start

Use a SessionStart hook to supply fixed context needed for the task and verify what was injected each run.

Goal

Explicitly inject application-generated task context instead of relying on implicit global state.

Steps

  1. Create a callback returning hookSpecificOutput with hookEventName="SessionStart" and minimal additionalContext. [hooks]
  2. Register it through ClaudeAgentOptions(hooks={"SessionStart":[...]}); never inject credentials or unnecessary user data. [hooks]
  3. Use a test task to verify the context after initialization and check both new and resumed sessions. [hooks]

How to verify

The agent sees the intended context after init; logs record a context version, not sensitive content.

Troubleshooting

If context is absent, check the hook key and event name; if resumed sessions retain old content, account for session snapshot behavior.

Permissions

Prerequisites

Permissions

Limitations

additionalContext enters model context; avoid secrets, oversized text, or unauthorized documents.

Pinned upstream source

https://github.com/anthropics/claude-agent-sdk-python/blob/b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c/examples/hooks.py

Repository
anthropics/claude-agent-sdk-python
File path
examples/hooks.py
Pinned commit
b6e9d12fe1cc98dde988ab7b7713c1feeee50c6c
Source checked
2026-10-14 · Reviewed against the pinned upstream source

Repository metrics

These values describe the upstream repository, not popularity or likes for an individual skill or playbook.

Stars
Not collected
Forks
Not collected
Observed at
Not collected

No metrics snapshot is available yet.

License: MIT

Main topic

Take a coding Agent change from context to verification

Related resources