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
- Create a callback returning
hookSpecificOutputwithhookEventName="SessionStart"and minimaladditionalContext. [hooks] - Register it through
ClaudeAgentOptions(hooks={"SessionStart":[...]}); never inject credentials or unnecessary user data. [hooks] - 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
- Python 3.10+, SDK, and task context generated and reviewed by the application.
Permissions
- Limit context to data the user may access and redact it before injection.
Limitations
additionalContext enters model context; avoid secrets, oversized text, or unauthorized documents.
Pinned upstream source
- 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