Skip to main content

agentguard-codex

AgentGuard monitoring plugin for OpenAI Codex.

Codex runs a command hook for each lifecycle event and writes one JSON object to stdin. This plugin reads that event, translates it with the AgentGuard Python SDK, and exports OpenTelemetry spans to the AgentGuard Timeplus app's OTLP/HTTP input (default http://localhost:4318).

Requirements

  • Python 3.10+
  • A Codex build with hooks enabled
  • The AgentGuard Python SDK (timeplus-agentguard on PyPI, installed automatically as a dependency)

Installation

From the repository root:

pip install -e agents/codex/agentguard-plugin

Configure Codex hooks

Merge hooks.json into your Codex hook configuration — ~/.codex/hooks.json, or the equivalent [hooks] table in ~/.codex/config.toml:

{
  "hooks": {
    "SessionStart": [
      { "hooks": [ { "type": "command", "command": "agentguard-codex" } ] }
    ]
  }
}

Codex skips a new or changed user-level hook until you review it. Run /hooks in Codex once and approve the AgentGuard entries. Managed (system/MDM) hooks are trusted by policy and skip this step.

If the plugin is not installed as a console script, use python -m agentguard_codex as the command instead.

Configuration

Hooks run in a fresh process, so environment variables are the usual way to configure the plugin.

Flag Environment variable Default
--agent-id AGENTGUARD_AGENT_ID hostname
--deployment-id AGENTGUARD_DEPLOYMENT_ID local
--deployment-name AGENTGUARD_DEPLOYMENT_NAME Local Dev
--endpoint OTEL_EXPORTER_OTLP_ENDPOINT http://localhost:4318

Flags take precedence over environment variables. The plugin resolves every setting (flag, then environment variable, then the default above) before constructing the SDK hooks, so each short-lived hook process sees the same values — including the agent id, which keys the on-disk Pre/Post-tool timing store to match the spans. For example:

export AGENTGUARD_DEPLOYMENT_ID=production
export AGENTGUARD_DEPLOYMENT_NAME="Production Codex"
export OTEL_EXPORTER_OTLP_ENDPOINT=http://timeplus.example.com:4318

What gets captured

Codex hook SDK call Emitted span
SessionStart on_session_start session (start time recorded)
SessionEnd on_session_end session (duration)
UserPromptSubmit on_llm_end llm
PreToolUse on_pre_tool start time recorded
PostToolUse on_post_tool tool

PreToolUse and PostToolUse are paired through the SDK's on-disk store, keyed by session, turn (turn_id), and tool call (tool_use_id), so overlapping tool calls in one session do not overwrite each other's start time. Other hook events are ignored for now, so a newer Codex can emit hooks this plugin does not know about without breaking.

Development

make test    # unit tests (stdlib only — no SDK or collector needed)
make build   # sdist + wheel into dist/ (needs hatch)

The plugin writes nothing to stdout and returns 0 even when it fails — any error goes to stderr — so hook output cannot alter a Codex turn.

Local end-to-end test

cd /path/to/AgentGuard

# 1. venv with the plugin and the in-repo SDK (drop `-e sdk/python` to use the PyPI release)
uv venv ~/venvs/agentguard-codex --python 3.12
uv pip install --python ~/venvs/agentguard-codex/bin/python \
  -e sdk/python -e agents/codex/agentguard-plugin

# 2. merge this package's hooks.json into ~/.codex/hooks.json, replacing
#    "command" with the venv's absolute path plus the plugin's env vars:
#      "command": "env AGENTGUARD_AGENT_ID=codex-local \
#         OTEL_EXPORTER_OTLP_ENDPOINT=http://127.0.0.1:4318 \
#         /Users/you/venvs/agentguard-codex/bin/agentguard-codex"

# 3. start Codex, run /hooks, review and trust the AgentGuard entries, quit
codex

# 4. run a turn
codex exec --skip-git-repo-check -s workspace-write \
  "Run pwd, then create done.txt containing ok."

# 5. inspect the exported spans at the configured OTLP endpoint (the app's
#    otel_traces, or any local OTLP collector), then remove the AgentGuard
#    entries from ~/.codex/hooks.json

Publishing

Releases are published to PyPI by CI:

  1. Bump version in pyproject.toml and __version__ in agentguard_codex/__init__.py, and merge.
  2. Publish a GitHub Release tagged codex-plugin-v<version> (for example codex-plugin-v0.1.1).

The Publish Codex plugin workflow tests, builds and uploads timeplus-agentguard-codex-plugin. It fails if the tag does not match the package version. Running it manually builds and validates without uploading; make check does the same locally (needs hatch and twine).

Metadata

Release files for timeplus-agentguard-codex-plugin 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for timeplus-agentguard-codex-plugin 0.1.1
File Size Uploaded Provenance Actions
timeplus_agentguard_codex_plugin-0.1.1.tar.gz 7.9 kB With provenance Details for timeplus_agentguard_codex_plugin-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for timeplus-agentguard-codex-plugin 0.1.1
File Interpreter ABI Platform Actions
timeplus_agentguard_codex_plugin-0.1.1-py3-none-any.whl Python 3 none any Details for timeplus_agentguard_codex_plugin-0.1.1-py3-none-any.whl

Total release size: 15.2 kB

Release files / timeplus_agentguard_codex_plugin-0.1.1.tar.gz

Download URL timeplus_agentguard_codex_plugin-0.1.1.tar.gz
Size 7.9 kB
Tags Source
SHA-256 checksum
How to use checksums
894672dd17d40cbb92b348a23cdb58d1f02ac06996999a40a9999f29c618d75c
BLAKE2b-256 checksum
How to use checksums
16f4991c3734e604dd787e3cd2fe7b7b1fde7c5891f276e4ee0924bd55001635
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Release files / timeplus_agentguard_codex_plugin-0.1.1-py3-none-any.whl

Download URL timeplus_agentguard_codex_plugin-0.1.1-py3-none-any.whl
Size 7.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7051073bcd6916ee9430cee496858c3592bcca59e7a197ec7d45abb1ac96a629
BLAKE2b-256 checksum
How to use checksums
884937a3724c708ecd3f9e1fb2c371128ed849345723542ee41c95fe02233c1a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

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 Nov 26, 2026.

Transparency log

Security for timeplus-agentguard-codex-plugin 0.1.1

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.

Select from 2 files

Attestation for timeplus_agentguard_codex_plugin-0.1.1.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 Nov 26, 2026.

Transparency log

A 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.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page