typed-agent-hooks
typed-agent-hooks gives OpenAI Codex and Anthropic Claude Code hooks one set of typed events. A hook file handles shared events, such as ToolCallCompleted. The package parses the host payload, maps it to the shared event, calls the handler, and writes the output in the format of that host. A hook file never names a host.
The host files hold the native event, matcher, timeout and command. The package does not generate or install host configuration.
A hook file
Each hook is one executable PEP 723 file:
#!/usr/bin/env -S uv run --script
# /// script
# requires-python = ">=3.13"
# dependencies = ["typed-agent-hooks==0.3.0"]
# [tool.uv]
# exclude-newer = "2026-10-25T00:00:00Z"
# ///
"""Suggest the notebook when a Bash command runs inline Python."""
from typed_agent_hooks import shared
app = shared.HookApp(name="inline-python")
@app.on(shared.events.ToolCallCompleted)
def tool_completed(event: shared.events.ToolCallCompleted) -> shared.outputs.Result:
command = event.tool_input.get("command") if isinstance(event.tool_input, dict) else None
if not isinstance(command, str) or "python -c" not in command:
return None
return shared.outputs.AddContext(text="For multi-step Python work, use the notebook.")
if __name__ == "__main__":
app.main()
uv uses only uploads from before the exclude-newer date, for every package. Set it to a time after the upload of the pinned typed-agent-hooks release, or uv cannot find that release. The date also freezes the other dependencies. The date in the example comes from before the 0.3.0 upload; replace it when you pin a release.
Host files
The host files call the hook with the host name as the only argument. The command ends with || true, so that a failure before main() runs cannot block the action (see below). Codex, in .codex/hooks.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [{ "type": "command", "command": ".agent-hooks/inline-python.py codex || true", "timeout": 5 }]
}
]
}
}
Claude Code, in .claude/settings.json:
{
"hooks": {
"PostToolUse": [
{
"matcher": "Bash",
"hooks": [
{
"type": "command",
"command": "\"$CLAUDE_PROJECT_DIR\"/.agent-hooks/inline-python.py claude || true",
"timeout": 5
}
]
}
]
}
}
What main() does
app.main() reads the host from its first argument (codex or claude) and the payload from stdin. The payload's hook_event_name selects the event. main() calls the handler of that event and writes the host output to stdout.
- A handler that returns
Nonewrites nothing. Everything else that the process writes to stdout (aprintat import or in a handler, a child process, a C library) goes to stderr, so stdout holds only the host output. Text that Python wrote to stdout beforemain()runs and without a buffer (python -uorPYTHONUNBUFFERED) cannot be recalled. - A failure fails open: one line on stderr, nothing on stdout, exit 0. Failures include a payload that does not parse, an event that has no handler, an event that has no shared equivalent, a handler exception or
sys.exit, and an output that the event cannot carry. - A missing or unknown host argument is a programming error: a usage line on stderr and exit 1. Both hosts read exit 1 as a non-blocking error, so a wrong host file does not block a tool call or a prompt.
main() fails open only after the file runs. uv run --script can fail before that, for example when the uv cache is cold and the package index is not available. uv then exits 2, which both hosts read as a blocking error. The || true in the host command turns that exit into 0. main() reports every block and deny decision as JSON with exit 0, so no intended behavior depends on the exit code.
app.handle(host, payload) does the same work in the current process and raises on each failure. Use it in tests.
Check host files without a host
A test can load a hook file without running it and compare its events with the host files:
import runpy
import sys
from typed_agent_hooks import shared
sys.path.insert(0, ".agent-hooks") # for helper modules next to the hooks
app = runpy.run_path(".agent-hooks/inline-python.py")["app"]
for event_type in app.handlers:
print(shared.native_event_name(event_type, "codex"), shared.native_event_name(event_type, "claude"))
app.handlers maps each shared event type to its handler. shared.native_event_name(event_type, host) returns the native event name, or None when the host has no such event. Codex has no ToolCallFailed event. Claude Code sends a failed tool call as PostToolUseFailure. Codex sends a shell command that exits non-zero as PostToolUse, and sends no hook for some other failures, such as an MCP tool error. A hook that must see failed shell commands in both hosts handles ToolCallCompleted and ToolCallFailed.
Shared events
Shared event (shared.events) |
Codex | Claude Code |
|---|---|---|
SessionStarted |
SessionStart |
SessionStart |
PromptSubmitted |
UserPromptSubmit |
UserPromptSubmit |
ToolCallProposed |
PreToolUse |
PreToolUse |
PermissionRequested |
PermissionRequest |
PermissionRequest |
ToolCallCompleted |
PostToolUse |
PostToolUse |
ToolCallFailed |
none | PostToolUseFailure |
CompactionStarting |
PreCompact |
PreCompact |
CompactionFinished |
PostCompact |
PostCompact |
SubagentStarted |
SubagentStart |
SubagentStart |
SubagentStopped |
SubagentStop |
SubagentStop |
TurnStopped |
Stop |
Stop |
Every event carries event.context with the host, session ID, working directory and other session data.
Results
A handler returns one result from shared.outputs, or None. Each result is valid only on the events in this table. On any other event it raises SharedOutputError in both hosts, and main() fails open. The package does not guess a translation.
| Result | Valid events | Notes |
|---|---|---|
None |
every event | Writes nothing. |
AddContext |
SessionStarted, PromptSubmitted, ToolCallProposed, ToolCallCompleted, ToolCallFailed, SubagentStarted |
ToolCallFailed is Claude Code only. |
SystemMessage |
every event except CompactionStarting and CompactionFinished |
Claude Code ignores systemMessage on compaction events. |
Block |
PromptSubmitted, SubagentStopped, TurnStopped |
It carries no context: on a blocked prompt, Codex keeps the context for the next turn and Claude Code drops it. Not on ToolCallCompleted: Claude Code keeps the tool output next to the reason, and Codex replaces it. |
Stop |
PromptSubmitted, SubagentStopped, TurnStopped |
A stated host difference: Claude Code keeps stopReason in the conversation, so the model sees it if the conversation continues, while Codex does not give it to the model. Not on SessionStarted (Claude Code has no decision control there) or ToolCallCompleted (Codex turns it into model feedback and continues). |
AllowTool |
ToolCallProposed |
A stated host difference. Claude Code skips its permission prompt and applies updated_input when it is set. Codex only applies updated_input, and its normal approval still runs. Codex rejects an allow without updated_input, so that result raises for Codex. |
DenyTool |
ToolCallProposed |
|
AllowPermission, DenyPermission |
PermissionRequested |
The compaction events accept no result except None. For context after compaction, return AddContext from SessionStarted with source == "compact".
Host wire schemas
typed_agent_hooks.codex and typed_agent_hooks.claude_code hold the native schemas of each host, for the events in the table above. An input model declares only the fields that the shared events read. It ignores other fields, so a host change to a field that no hook reads cannot break a hook. Declared fields stay strictly typed. An output model holds only the fields that the shared results write, and it is closed and exact. A Claude Code event with no shared equivalent, such as Notification, is not modeled: parse_input raises ValueError, and main() fails open.
Development
uv run ruff format --check .
uv run ruff check .
uv run ty check
uv run pytest -q
Metadata
Release files for typed-agent-hooks 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| typed_agent_hooks-0.3.0.tar.gz | 16.3 kB | With provenance | Details for typed_agent_hooks-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| typed_agent_hooks-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for typed_agent_hooks-0.3.0-py3-none-any.whl |
Total release size: 39.2 kB
Release files / typed_agent_hooks-0.3.0.tar.gz
| Download URL | typed_agent_hooks-0.3.0.tar.gz |
|---|---|
| Size | 16.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
344dd64d87b8b76044b96dae9fa4f0ad2430f1ed1597520b7394058a85e83a55
|
|
BLAKE2b-256 checksum How to use checksums |
cc0e770d2d2cca62894fe170fc266f9b1fefbfde0e6ac03a8873a1ea5f6e33b4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logRelease files / typed_agent_hooks-0.3.0-py3-none-any.whl
| Download URL | typed_agent_hooks-0.3.0-py3-none-any.whl |
|---|---|
| Size | 22.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b41020aafc2c913da7f362dfd7570da1fc6b9039d403e8078ea5f5ece8ae5dd2
|
|
BLAKE2b-256 checksum How to use checksums |
de45b374fadf78a07adaf99649c3d054d43495dc0038593c3aafcf382397bc5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logSecurity for typed-agent-hooks 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
Both files in this release have been uploaded with provenance metadata.
Attestation for typed_agent_hooks-0.3.0.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Oct 27, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.