/cao-contributor:cao-event-pluginfrom cao-contributor
Scaffolds CAO (CLI Agent Orchestrator) plugins that react to lifecycle and messaging events. Covers package layout, hook registration, entry-point discovery, and integration with external systems like Discord or Slack.
Ships in cao-contributor. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Guide for creating a new CAO plugin. A "plugin" is a Python package installed alongside CAO that subscribes to CAO lifecycle and messaging events via typed async hooks.
A CAO plugin is a standalone Python package that:
CaoPlugin from cli_agent_orchestrator.plugins@hook("<event_type>") decoratorscao.plugins Python entry-point group at cao-server startupTypical uses: forwarding inter-agent messages to chat apps, logging/observability, external dashboards, metrics export, alerting on session or terminal lifecycle.
Gather this information:
references/hook-events.md for the full catalog.setup() / teardown().setup(), optionally via python-dotenv.These are the non-negotiable contracts a plugin must satisfy to be loaded and dispatched to. Verify each one before calling your plugin complete.
Minimum viable layout:
my-cao-plugin/
├── pyproject.toml # Build config + entry-point declaration
├── my_cao_plugin/
│ ├── __init__.py # Can be empty
│ └── plugin.py # Contains the CaoPlugin subclass
├── tests/ # Optional but strongly recommended
│ └── test_plugin.py
├── env.template # Optional; only if the plugin reads env vars
└── README.md # Optional; install + config instructions for users
See examples/plugins/cao-discord/ in this repo for a complete reference implementation.
CaoPlugin from cli_agent_orchestrator.plugins.cls(). Do NOT define __init__ with required parameters.async def setup(self) -> None — called once at cao-server startup after instantiation.async def teardown(self) -> None — called once at cao-server shutdown.@hook decorator.A raising setup() disables that plugin for the lifetime of the server process (warning logged, other plugins continue to load). A raising teardown() is logged and does not stop other plugins from tearing down.
A hook method must:
async def — sync hooks are not supported in v1.@hook("<event_type>") using the exact event-type string from references/hook-events.md.None.inspect.getmembers on the instance).Multiple hook methods on the same plugin may subscribe to the same event type — each is dispatched independently. Execution order across hooks is not guaranteed.
Exceptions raised inside a hook are caught by the registry and logged as warnings. They do not affect CAO's primary operation and they do not stop other hooks for the same event from running.
Declare the plugin class under the cao.plugins entry-point group in pyproject.toml:
[project.entry-points."cao.plugins"]
my_plugin = "my_cao_plugin.plugin:MyPlugin"
my_plugin) is the plugin name used in CAO's startup log (Loaded CAO plugin: my_plugin). It has no other runtime effect.CaoPlugin. Entry points whose target is not a CaoPlugin subclass are skipped with a warning.cao.plugins if it ships multiple plugin classes.No CAO-side configuration is required to enable a plugin — installation plus entry-point declaration is sufficient.
hatchling as the build backend to match CAO's toolchain.>=3.11.cli-agent-orchestrator as a runtime dependency so CaoPlugin, hook, and the event dataclasses are importable.httpx, aiohttp, python-dotenv) your plugin uses.Minimal pyproject.toml:
[build-system]
requires = ["hatchling"]
build-backend = "hatchling.build"
[project]
name = "my-cao-plugin"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
"cli-agent-orchestrator",
# ... your plugin's deps
]
[project.entry-points."cao.plugins"]
my_plugin = "my_cao_plugin.plugin:MyPlugin"
CAO does not inject configuration into plugins in v1. Options:
setup() with os.environ.get(...). Raise RuntimeError with a clear message if a required var is missing so the startup log points the user at the misconfiguration..env files — use python-dotenv (load_dotenv(find_dotenv(usecwd=True))) inside setup(). Process-level env vars override .env values, which is the expected precedence.setup(); you own the format.Ship an env.template alongside the plugin if it reads env vars, documenting every variable, whether it's required, and its default.
setup() is awaited exactly once, after the plugin class is instantiated at server startup.teardown() is awaited exactly once at server shutdown, only for plugins whose setup() succeeded.cao-server.post_create_terminal fires after the terminal is persisted, not before).pre_* hooks today — you cannot veto or mutate an operation from a plugin.Create the layout from §1. Populate pyproject.toml per §5. references/plugin-template.md has a copy-paste skeleton.
In my_cao_plugin/plugin.py:
from cli_agent_orchestrator.plugins import CaoPlugin, PostSendMessageEvent, hook
class MyPlugin(CaoPlugin):
async def setup(self) -> None:
# Read config, open clients. Raise on misconfiguration.
...
async def teardown(self) -> None:
# Close clients, flush buffers. Safe to call after failed setup.
...
@hook("post_send_message")
async def on_message(self, event: PostSendMessageEvent) -> None:
...
Keep teardown() robust to partial setup() failures — guard any resource access with hasattr or an initialized flag. See examples/plugins/cao-discord/cao_discord/plugin.py for the pattern.
Consult references/hook-events.md for the current event catalog, each event type's string, the matching dataclass, and available fields. Import event dataclasses from cli_agent_orchestrator.plugins.
Add the [project.entry-points."cao.plugins"] section to pyproject.toml per §4.
The plugin must be importable by the same Python environment that runs cao-server.
# Editable install into the CAO dev virtual environment
uv pip install -e ./my-cao-plugin
# Or, if CAO was installed as a tool:
uv tool install --reinstall cli-agent-orchestrator \
--with-editable ./my-cao-plugin
Restart cao-server and check the startup log for one of:
Loaded CAO plugin: my_plugin — success.Failed to load plugin 'my_plugin' — setup() raised; check the traceback logged alongside.Plugin entry point 'my_plugin' is not a CaoPlugin subclass, skipping — the entry-point target is wrong.No CAO plugins registered (cao.plugins entry point group is empty) — the entry point is not declared, or the package was not installed into the same environment as CAO.Unit tests for a plugin are straightforward because event dataclasses are zero-arg constructible:
import pytest
from cli_agent_orchestrator.plugins import PostSendMessageEvent
from my_cao_plugin.plugin import MyPlugin
@pytest.mark.asyncio
async def test_on_message_dispatches(monkeypatch):
plugin = MyPlugin()
await plugin.setup()
await plugin.on_message(
PostSendMessageEvent(
sender="a",
receiver="b",
message="hi",
orchestration_type="send_message",
)
)
await plugin.teardown()
For plugins that make HTTP calls, use httpx.MockTransport (see examples/plugins/cao-discord/tests/test_plugin.py) rather than real network calls. Assert side-effects (requests sent, logs emitted) — do not assert CAO-side dispatch wiring, which is covered by CAO's own registry tests.
Reload the plugin after code changes:
# Stop cao-server, then reinstall if dependencies changed:
uv pip install -e ./my-cao-plugin --force-reinstall --no-deps
# Then restart cao-server.
Troubleshooting checklist if Loaded CAO plugin: does not appear:
cao-server? (uv pip list | grep my-cao-plugin)pyproject.toml contain [project.entry-points."cao.plugins"]?CaoPlugin subclass? (python -c "from my_cao_plugin.plugin import MyPlugin; print(MyPlugin.__mro__)")setup() raise? Check cao-server logs for a Failed to load plugin warning..env, is it in the directory where cao-server was launched (or a parent)?When your plugin is complete, verify:
pyproject.toml — hatchling build backend, cli-agent-orchestrator dependency, cao.plugins entry pointmy_cao_plugin/__init__.py — present (can be empty)my_cao_plugin/plugin.py — CaoPlugin subclass with zero-arg construction and at least one @hook-decorated async methodenv.template — if any env vars are readtests/test_plugin.py — setup/teardown happy and failure paths; at least one test per hook methodREADME.md — install commands, config vars, troubleshootingLoaded CAO plugin: in cao-server startup logsreferences/hook-events.md — Full catalog of supported event types, their string identifiers, and event dataclass fields.references/plugin-template.md — Annotated minimal plugin skeleton.examples/plugins/cao-discord/ — Complete reference plugin (webhook forwarder with .env config, HTTP client lifecycle, unit tests).docs/feat-plugin-hooks-design.md — Full design document for the plugin system.What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
npx claudepluginhub awslabs/cli-agent-orchestrator --plugin cao-contributor3 skills in this plugin
/cao-contributingContribute changes to the CAO (CLI Agent Orchestrator) codebase — the local dev loop, the CI gate map, and the pre-PR checklist. Use when the user says "open a PR", "why did CI fail", "run the checks before I push", "the mypy/Code Quality job is red", "add a test and verify coverage", "bump a dependency", "the uv.lock diff is noisy", "a CVE blocks the dependency gate", or when making any code change intended to land on a branch/PR. Covers uv-based build/test/lint, lockfile and CVE-floor rules, the ci.yml jobs and their pass/fail semantics, and the golden rules that stop a green-locally / red-in-CI surprise. Not for authoring agent skills, building providers/plugins/MCP-apps, or operating running sessions./cao-providerCreate a new CLI agent provider for CAO (CLI Agent Orchestrator). Use this skill whenever the user wants to add support for a new CLI-based AI agent (e.g., a new coding assistant CLI), integrate a new provider, or scaffold a provider implementation. Also use when the user asks about the provider architecture, what files to modify, or how providers work in CAO.Other plugins' skills for the same job