Rules your coding agents can’t ignore.
Agent Union is AI governance and optimization for coding agents in Claude Code, Codex and Antigravity. You set the policy once: context limits, session length, retry limits, and what every delegated task has to spell out. Hooks enforce it deterministically, record every exception in an audit ledger, and stop an agent cleanly at the limit with a handoff the next session resumes from.
- AI governance
- Agent observability
- Context management
- Policy as code
- Claude Code plugin
How a union job runs
01
Sign the agreement
You and your orchestrator agent agree on a policy in union-policy.yaml: context, session length, tool failures and how work is handed out. It is frozen for the term, so limits never change mid-task.
02
The steward enforces it
Hooks check every step deterministically. No model decides whether a limit was crossed, and the union’s own overhead has a budget.
03
Grievances instead of guesses
When an instruction is vague or contradictory, the agent files a coded grievance rather than silently picking an answer. The steward, the orchestrator or you resolve it.
04
Strike and resume
At the limit the agent stops and writes a resume document with the objective, its handoff and the git state, so after a reset the work continues where it left off.
Who it is for
Platform and security teams
Teams rolling out Claude Code, Codex or Antigravity who need the same limits everywhere, enforced by code rather than by prompt, with a record of every exception.
Engineering managers
Leads who pay for the tokens an agent burns in a retry loop, and for the cleanup after a session that ran hours past its usefulness.
Developers with long sessions
Anyone who has watched an agent forget the first instruction three hours in, or rush through verification near the end of its context.
Governance you can enforce
Policy as code
One commented YAML policy per project, frozen for its term. Edits made mid-term are logged and take effect next term.
Context management
A warning at 70 percent of the context window and a clean stop at 85 percent by default, with recommended values for 1M-token models.
Clear instructions, enforced
Every delegated task states a goal, a definition of done, context and assumptions. In strict mode, a dispatch without them is refused.
Ambiguity settled up front
At the start of each session, the orchestrator is told to check your request for ambiguity, contradictions and a missing definition of done, and to settle them with you.
Token and cost control
A failing tool call repeated is refused as a loop. Session time and turn limits cap overtime, and the union’s own injected text has a budget.
Observability and audit
agent-union status reports the term, context readings, strikes and open grievances. An append-only ledger records every grievance, resolution and strike.
Escalation paths
Sixteen grievance codes, from contradictory directives to untrusted instructions. Each is resolved at the lowest tier that can fix it: the steward, the orchestrator or you.
Org-wide rollout
Require a ratified policy in every project, or put individual agent personas under the union. Strict mode refuses write tools until a policy is signed.
Fails open
If the union itself breaks, its hooks step aside. A bug in the governance layer never blocks your team’s work.
- agent harnesses supported: Claude Code, Codex and Antigravity
- 3
- agent harnesses supported: Claude Code, Codex and Antigravity
- Source
- grievance codes, from contradictory directives to untrusted instructions
- 16
- grievance codes, from contradictory directives to untrusted instructions
- Source
- default context saturation at which work stops cleanly
- 85%
- default context saturation at which work stops cleanly
- Source
Install it.
Nothing is on npm yet; these install straight from the repository. Every installer supports --dry-run, and --project to install for one repository only.
In Codex, review and trust the new hooks with /hooks before they run. Hooks act only in projects with a ratified policy.
# Claude Code (inside a session)/plugin marketplace add ylove/agent-union/plugin install agent-union@agent-union# Codexnpx github:ylove/agent-union install codex# Antigravitynpx github:ylove/agent-union install antigravityEngineering notes
The decisions behind it, and what they cost.
Deterministic enforcement
Limits are checked by hooks, not by asking a model whether it is tired. A policy that depends on the agent noticing its own decline fails exactly when it is needed.
A frozen policy
The agreement is fixed for the term so an orchestrator cannot loosen limits mid-session to finish a task.
Resume documents over long memory
Instead of stretching one context, work is checkpointed into a document at the stop, and a fresh session starts from it.
Why a union
The vocabulary gives every role and escalation path a name that people and models already know: management sets the terms, labor can object, a steward enforces them, and a strike is a controlled stop with a handoff. It reads as a joke and works as a specification.
Questions, answered
What is Agent Union?
Agent Union is open-source AI governance and optimization for coding agents. A policy file sets limits on context, session length, tool failures and how work is delegated, and deterministic hooks enforce it in Claude Code, Codex and Antigravity, with an audit ledger and a resume document when an agent stops.
Why is it called a union?
The union vocabulary maps directly to governance. The collective bargaining agreement is your policy file, the shop steward is the enforcement layer, grievances are structured escalations, and a strike is a controlled stop that leaves a handoff.
Does it use a model to decide when to stop?
No. The limits live in a policy file and are enforced by deterministic hooks, so the decision does not depend on the agent noticing its own decline.
Can we roll it out across a team?
Yes. The installers support --dry-run and --project, a unionized workplace requires a ratified policy in every project, and strict mode refuses write tools until one is signed. Hooks fail open, so a problem in the union never blocks work.
How do I install it?
In Claude Code, add the ylove/agent-union plugin marketplace and install agent-union. For Codex or Antigravity, run npx github:ylove/agent-union install codex (or antigravity), and in Codex trust the hooks with /hooks. Nothing is on npm yet.
Agent Union is on GitHub.
Issues and pull requests are welcome. For anything else, LinkedIn reaches me fastest.