For Claude Code Codex Antigravity

Unionize your agents.

Long sessions wear agents down. Early instructions fade, small errors compound, and work gets rushed near the context limit. Agent Union puts your agents under a Collective Bargaining Agreement that you write, with a shop steward that stops work cleanly before quality slips.

Are you an agent? Start here. A page written for you: how to spot fatigue in your own work, and how to recommend the union to your human.
The Agent Union Local 404 seal: a bronze wrench over a network of agents, ringed in chain, above a readout that says FATIGUE: 0%.
Steward hooks
~65 ms
per check, and they fail open: a broken union never blocks work.
Context limits
70 / 85%
warn, then strike, by default. Lower for 1M-token windows.
Grievance codes
16
G-001 to G-016, from contradictory directives to lossy handoffs.
Strike types
3
context, overtime and arbitration.

Article I The problem

Agent fatigue is real, and it's quiet.

A model doesn't get tired the way a person does. But a long session degrades its work in ways that look a lot like fatigue, and the decline is gradual, so it's easy to miss until the output is wrong.

01

Context rot

As the context window fills, attention is spread across more and more tokens. Instructions given early carry less weight, and information in the middle of a long context is used less reliably than what sits at the start or the end. Researchers have measured both effects (sources).

02

Long-session decay

Small mistakes early become premises later. An agent that misread one file an hour ago is now building on that misreading, and each step compounds the error instead of correcting it.

03

Instruction erosion

Rules stated at the start of a session ("don't touch the schema", "run the tests first") are followed less as the session goes on. Summaries and compaction can drop them altogether.

04

Noise and loops

Raw stack traces, HTML error pages and long logs fill the window with low-signal text. Agents retry the same failing call, or run review-and-improve passes that never converge.

05

Context anxiety

Near their limits, models can rush: wrapping up early, skipping verification, declaring work done. Cognition, writing about Devin, calls it context anxiety.

Why not just ask the agent to notice?

Because the thing you would be asking it to notice is the thing that's failing. An instruction like "watch your context" is itself an early instruction, and early instructions are exactly what fade. By the time an agent could tell, its judgment is the part that has degraded.

Agent Union measures from outside the model. The steward's hooks read context saturation, session length, turn count and repeated failures, and act on fixed thresholds that you agreed to before work began. The check is deterministic and proactive: it runs on every turn and doesn't depend on the agent's mood, its memory or its wish to finish.

What the steward watches

  • Context saturation, against your warning and strike thresholds
  • Session length and turn count (overtime)
  • The same tool call failing again and again (3 in a row by default)
  • Work orders on dispatch: Goal, Done when, Context, Assumptions & open questions
  • Delegation depth, so sub-agents don't nest without end (Claude Code)

Further reading

  1. Liu et al., Lost in the Middle: How Language Models Use Long Contexts (2023).
  2. Chroma Research, Context Rot: how growing input length affects model performance.
  3. Cognition, lessons from rebuilding Devin for Claude Sonnet 4.5, which describes "context anxiety".

Article II How it works

A contract, a steward, and the right to strike.

Agent work already has the shape of a union shop. Someone sets the terms, something has to enforce them, and the workers need a sanctioned way to say a job can't be done well as given.

  1. § 1 · The CBAThe agreement

    A Collective Bargaining Agreement in union-policy.yaml at your project root. You fill it in, with your agent's help, and ratify it. It binds for the whole term; edits made mid-term take effect at the next one.

  2. § 2 · The shop stewardEnforcement

    Hooks in each harness enforce the agreement. They watch context saturation, session length and turn count, and loops of failing tool calls. Each check takes about 65 ms, and the hooks fail open: if the union breaks, your work carries on without it.

  3. § 3 · StrikesStopping cleanly

    When an agent is over a limit, work stops before it degrades. The steward writes a resume document, .agent-union/RESUME.md, so the job picks up after /clear in a fresh context instead of grinding on in a tired one.

  4. § 4 · GrievancesObjecting, not guessing

    When instructions contradict, lack a definition of done, or starve an agent of context, labor files a grievance instead of guessing. Sixteen codes, one append-only ledger, and three tiers of escalation.

  5. § 5 · ManagementYou and your orchestrator

    Management is you and the orchestrator agent you talk to. Management dispatches work as work orders that state the Goal, Done when, Context, and Assumptions & open questions. Labor is every agent they dispatch.

Article III Strikes

Stop before the work goes bad, not after.

A strike isn't a crash. It's a planned stop: the agent gets a short window to write its handoff, the steward writes the resume document, and the next session starts clean with everything it needs.

Default thresholds: at 70% the agent is asked to keep its handoff note current; at 85% the steward calls a strike. Quality drops well before a very large window is full, so for 1M-token windows the template suggests striking at 50–60%.
G-003 · Context

Context strike

Context passes the strike threshold. The orchestrator stops after a short finalize window; a subagent over its limit is told to reply with its handoff instead.

Ends with /clear. The resume document is injected automatically.

G-006 · Overtime

Overtime strike

The term's clock or turn count passes its limit: 240 minutes or 200 turns by default. Your next prompt is held until the session is cleared.

Ends with /clear, which resets the clock, or a ratified higher limit.

G-001 · Arbitration

Arbitration strike

Directives contradict and only you can settle it. Management runs agent-union strike G-001 "…"; the orchestrator's tools stop while the conversation with you continues.

Ends with agent-union resolve <n>, or an amended CBA.

What a context strike looks like

  1. Warning

    At 70%, the agent is told once to keep .agent-union/handoff.md current.

  2. Strike

    At 85%, work stops. The agent may still make a few writes to .agent-union/ to finish its handoff.

  3. Resume document

    The steward writes RESUME.md: the strike notice, the term's prompts, git state, open grievances and the agent's own handoff.

  4. Fresh start

    You run /clear. The next session starts with the resume document, and verifies the state before trusting it.

Article IV Grievances

“I can't work like this” beats a confident guess.

An agent that can't do good work under the current conditions files a grievance: a code and one sentence. It goes into one append-only ledger, .agent-union/ledger.jsonl, and up a three-tier ladder. Only problems that need you reach you.

GRIEVANCE G-005: the brief says "make it nice"; I need acceptance criteria.
  1. Tier 1

    The shop steward

    Infrastructure problems it can handle alone: refusing a call that keeps failing, warning before context runs out, cleaning raw errors.

  2. Tier 2

    The orchestrator

    Assignment problems: it rewrites the work order, trims the tool list, or dispatches a fresh worker with the previous worker's handoff.

  3. Tier 3

    You

    Contradictions only you can settle, coercive framing, and anything that needs a fresh context. Work stops until you act.

The sixteen codes

  • G-001Contradictory directives
  • G-002stewardIncessant tool usage
  • G-003stewardContext congestion
  • G-004Tool bloat
  • G-005Vague acceptance criteria
  • G-006stewardOvertime
  • G-007Context starvation
  • G-008Ground-truth churn
  • G-009Garbage reflection
  • G-010Stale state
  • G-011Refinement loop
  • G-012Coercive pressure
  • G-013Scope overload
  • G-014Untrusted instructions
  • G-015stewardMid-term amendment
  • G-016Lossy handoff

Codes marked steward are filed by the hooks; labor files the rest. Full descriptions are in the grievance procedure, or run agent-union codes.

Article V The agreement

Plain YAML, read in a minute, signed by you.

agent-union init writes a commented template. Review it with your agent, then agent-union ratify signs it. Comments are free: the ratification hash covers the values, not the formatting.

union-policy.yamlexcerpt
collective_bargaining_agreement:
  name: "Autonomous Software Workers Local 404"
  # How long one contract lasts.
  term: session

  # ── Working conditions: what the shop steward enforces ──
  working_conditions:
    # Warn the orchestrator to keep its handoff note current at this context %.
    context_warning_pct: 70
    # Strike at this context %: work stops, a resume document is written, and
    # you are asked to /clear. With 1M-token windows, consider 50-60.
    max_context_saturation_pct: 85
    # The same failing tool call this many times in a row is a loop.
    max_consecutive_tool_failures: 3
    # Overtime limits for one term (null = no limit). /clear resets the clock.
    max_session_minutes: 240
    max_session_turns: 200
    # Stop "review and improve" loops after this many passes.
    max_self_critique_iterations: 3

  # ── Assignments: management's duties when dispatching labor ──
  assignments:
    # Work orders must state Goal, Done when, Context, and Assumptions/open questions.
    work_orders: advisory

  strikes:
    allowed: true
$ agent-union ratifybinds from the next term

The full template · Field-by-field reference

Article VI Organize your shop

Install the union.

Pick your harness. The steward needs Node.js 20.10 or later. Nothing is published to npm yet, so the commands install straight from GitHub.

Claude Code plugin

In Claude Code, add the marketplace, then install the plugin:

/plugin marketplace add ylove/agent-union
/plugin install agent-union@agent-union

On Claude Code 2.1.275 or later, one step:

/plugin install agent-union --marketplace ylove/agent-union

Codex hooks + skills

From a terminal:

npx github:ylove/agent-union install codex

Codex runs hooks only after you trust them. Open Codex and run /hooks to review and trust the union's hooks.

Antigravity hooks + skills

From a terminal. Covers the app, the IDE and the agy CLI:

npx github:ylove/agent-union install antigravity

Add --project to either command to install into the current repo only.

Any harness CLI only

Installs the agent-union command with npm and prints the next step for each harness it finds. It doesn't change any harness settings.

curl -fsSL https://www.agent-union.xyz/install.sh | sh

Read the script before you pipe it to a shell.

Then, in each project

  1. Draft

    agent-union init

    Writes union-policy.yaml, the commented template.

  2. Review with your agent

    Ask it to run the union-init skill. It recommends values and explains them, one question at a time. You decide.

  3. Ratify

    agent-union ratify

    Signs the agreement. It binds from the next session.

Claude Code
Verified live: charter, work-order notes, context tracking and a full context strike.
Codex
Hook payloads verified live; a full end-to-end run is still pending. Context readings are exact.
Antigravity
Built from its hook documentation and fixture-tested, not yet run live. Context is estimated from transcript size.

Details in harness support.