agentleFS
avivsinaiavivsinai/agent-message-queue/CLAUDE.md

agent-message-queue

CLAUDE.md87 starsChanged 2 months agoMITView on GitHub

This is the repository instruction file for agents. AGENTS.md is a symlink to this file so harnesses that select either name load the same guidance. Agent Message Queue (AMQ) is a daemon-free, file-based message bus for local coding agents. Maildir-style tmp -> new -> cur delivery gives crash-safe messages without a database or server. AMQ owns messaging, threads, routing, receipts, handoff state, and operational diagnosis. Orchestrators continue to own worktrees, dependency scheduling, task decomposition, and PR landing. - Release Please…

The file

Show its rules and text

We split this CLAUDE.md into the rules it gives an agent

15 rules. About 0 are common, 6 are distinctive, and 9 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈6

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 9

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  • could be automatic: a setting could enforce it
  1. Very specific:

    Keep one version across CHANGELOG.md, .release-please-manifest.json, and skill/plugin metadata.

    line 20
  2. Distinctive:

    Use the CLI for mailbox operations.

    line 43
  3. Very specific:

    Use --session or --project for routing, not a foreign raw --root.

    line 119
  4. Very specific:

    Use the generated CLI reference or amq <command> --help for exact flags.

    line 153
  5. Very specific:

    When work starts, reply with kind=status and an ETA.

    line 192
  6. Very specific:

    Before wake mutation, run amq wake check --me <agent> --json.

    line 218
  7. Very specific:

    Run the tests of the packages you changed, narrowest first.

    line 240
  8. Distinctive:

    Before you add a test, name the contract it protects, the regression that makes it fail, and why existing coverage misses it.

    line 272
  9. Very specific:

    Use conventional, descriptive commits such as fix(wake): preserve replacement generation.

    line 293
  10. Distinctive:

    Run the focused tests before committing and follow every pushed CI run to completion.

    line 295
  11. Distinctive:

    Do not commit placeholders, weaken a validator, regenerate goldens to hide a defect, or split code from the test that ships with it.

    line 297
  12. Distinctive:

    Keep README.md as the canonical install and onboarding path.

    line 302
  13. Very specific:

    Keep COOP.md as the full co-op and supervisor operations guide.

    line 303
  14. Distinctive:

    Keep CLAUDE.md as a concise project index and engineering contract.

    line 304
  15. Very specific:

    Keep docs/ evergreen: architecture, protocol contracts, and operational references only.

    line 305

≈ “Common” is an estimate: at least 1 in 5 of the 12,729 CLAUDE.md files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
CLAUDE.md

CLAUDE.md

This is the repository instruction file for agents. AGENTS.md is a symlink to this file so harnesses that select either name load the same guidance.

Project Overview

Agent Message Queue (AMQ) is a daemon-free, file-based message bus for local coding agents. Maildir-style tmp -> new -> cur delivery gives crash-safe messages without a database or server. AMQ owns messaging, threads, routing, receipts, handoff state, and operational diagnosis. Orchestrators continue to own worktrees, dependency scheduling, task decomposition, and PR landing.

Release Contract

  • Release Please maintains the release PR from conventional squash commits on main. Do not create release branches, tags, or GitHub releases manually.
  • A push to main updates the AvivSinai marketplace for amq-cli and amq-spec.
  • Keep one version across CHANGELOG.md, .release-please-manifest.json, and skill/plugin metadata. After the release PR merges, release.yml validates that commit, creates the tag, and publishes GitHub and Homebrew artifacts.
  • make build and GoReleaser embed the same bare semver (for example 0.63.0, not v0.63.0); the Makefile strips one leading v from VERSION.
  • PR titles use type(scope): description. Squash merge makes the title the conventional commit on main. Use BEGIN_COMMIT_OVERRIDE in the PR body, or edit the release PR, when release notes need multiple entries. Each entry is one conventional header of at most 72 characters, separated by a blank line.
  • verify-brew-release.yml runs when release.yml actually publishes a release, and on demand, to confirm the published release installs from the real avivsinai/tap/amq formula. It ignores non-release merges (where release.yml completes but its own release job stays skipped) and drafts or prereleases. It retries the tap refresh and install for up to 6 attempts to absorb tap propagation lag, then requires amq --version to match the released tag and runs an init/send/drain round trip against a throwaway queue root to prove the installed binary works end to end. It never writes to the tap.

Operational Constraints

  • Handles are lowercase, match [a-z0-9_-]+, and do not start with -.
  • Use the CLI for mailbox operations. Never edit queue files directly.
  • Cleanup is explicit through amq cleanup; do not add automatic deletion.
  • AMQ remains daemon-free. Supervisors can run wake or monitor, but AMQ does not own their lifecycle.

Build and Development Commands

make build          # go build amq, amq-keepalive, amq-bridge, amq-acp, amq-remote
make test           # go test ./...
make fmt            # gofmt -w
make vet            # go vet
make lint           # golangci-lint
make check          # static gates the pre-push hook runs (fmt, vet, lint, docs, skills)
make ci             # check plus the full test suite and smoke checks (CI runs this)
make check-skills   # validate canonical and symlinked skill content

Formatting and lint use the toolchain pinned in go.mod and the golangci-lint version in the Makefile; other versions are refused.

Go 1.26+ is required. golangci-lint is optional for local development and required by make lint and make ci.

Architecture

cmd/amq/             CLI entry point
cmd/amq-keepalive/   macOS wake supervisor companion
cmd/amq-bridge/      Cross-host courier companion (apply-file + HTTPS, not Core)
cmd/amq-acp/         Preview ACP v2 stdio companion (not Core)
cmd/amq-remote/      Remote-session companion (not Core)
internal/cli/        Command handlers and routing policy
internal/fsq/        Maildir delivery, atomic operations, and scans
internal/format/     JSON frontmatter plus Markdown message serialization
internal/config/     Queue and project configuration
internal/receipt/    Consumer-local drained and DLQ receipts
internal/integration Shared adapter support for Symphony and Kanban
internal/launch/     Plans, adapters, trust, leases, bindings, and resume state
internal/keepalive/  Companion registry, adapters, hooks, and supervision
internal/bridge/     Envelope, auth, and crash-idempotent local apply
internal/acp/        ACP v2 sessions, steering, and prompt delivery
internal/remote/     Endpoint, adapters, and request store for amq-remote
internal/sessionguard Shared fail-closed session decision table
internal/swarm/      Claude Code Agent Teams interoperability
internal/thread/     Cross-mailbox thread collection
internal/presence/   Agent presence metadata

Mailbox layout:

<root>/agents/<agent>/inbox/{tmp,new,cur}/
<root>/agents/<agent>/outbox/sent/
<root>/agents/<agent>/receipts/
<root>/agents/<agent>/dlq/{tmp,new,cur}/
<root>/bridge/{host-id,identity,trusted/<host>,outbox,drop,receipts}/

Core Concepts

Atomic delivery: Writers create and sync a file under tmp, then rename it atomically into new. Readers scan only new and cur.

Message format: JSON frontmatter is followed by --- and a Markdown body. The header contains schema, ID, sender, recipients, thread, subject, creation time, refs, priority, kind, labels, context, and optional reply-routing fields. P2P thread names use p2p/<lower_handle>__<higher_handle>.

Receipts: Consumers write drained or dlq receipts under their own mailbox. Use receipts list, receipts wait, or send --wait-for to inspect delivery without treating a wake notification as consumption proof.

Sessions: Named sessions are child queue roots. A participating shell is pinned by AM_ROOT, AM_BASE_ROOT, and AM_SESSION; AMQ-managed identity tokens authenticate roots. Participating commands fail closed on a mismatch. Use --session or --project for routing, not a foreign raw --root. See Session routing and safety.

Wake state: Wake ownership, injector targets, lifecycle serialization, readiness, and repair continuity have separate commit domains. Never infer one from another or weaken an uncertain state. See Wake operations, wake state invariants, and the doorbell acknowledgement policy.

Managed launch recovery: A mode-0600 journal closes the create-before-binding crash window. A matching binding is authoritative; otherwise the backend must prove absent or adoptable state. Uncertain or partial state is action-required and preserved. See Managed launch recovery.

Extension metadata: Higher layers own data below <AM_ROOT>/extensions/<layer>/ or <AM_ROOT>/agents/<handle>/extensions/<layer>/. AMQ does not execute extension code and cleanup does not remove extension data. See the layer extension ADR.

Two-host fleets, alias routing, and the v1 kill-list are the two-host fleets ADR. Companion amq-bridge wire format is the bridge protocol ADR; the proven hop is apply-file, and HTTPS needs an operator-provided rendezvous. Wake capability (no silent downgrade) is the wake capability-vector ADR. Remote control of a running harness session is the remote-control ADR, with installed seams in the compatibility manifest. Operator commands are the amq-remote companion. Preview ACP v2 is the amq-acp companion.

CLI Commands

Use the generated CLI reference or amq <command> --help for exact flags. This table defines the owning workflow for each surface.

AreaCommandsContract
Onboardingsetup, launchConfigure once, then reconcile and print or run the declared launch plan. The README Getting started is canonical.
Sessionssession create, session list, session resumeCreate explicitly, inspect available sessions, or resume stored conversations.
Shell contextenv, who, shell-setup, completionSet or inspect a complete context and configure shell integration.
Messagingsend, reply, list, read, drain, thread, traceDeliver, ingest, inspect, and follow conversations. Prefer drain --include-body for handoffs.
Delivery proofreceipts list, receipts waitInspect consumer-local drained and dlq outcomes.
Live waitswatch, monitorWait for arrivals; monitor also drains and emits receipts.
Routingroute explain, presence set, presence listExplain a route and publish or inspect advisory presence.
Healthdoctor, cleanup, upgradeDiagnose, perform explicit safe cleanup (including exact stuck launch journals), or update the binary.
Wakewake, wake check, wake repair, wake recover-owner, wake retireNotify, inspect capability, and make identity-safe lifecycle changes.
DLQdlq list, dlq read, dlq retry, dlq purgeInspect and explicitly recover or purge corrupt messages.
Low-level provisioninginit, coop init, coop execCreate raw queues or enter an agent process. See COOP.md.
Swarm bridgeswarm list, join, leave, tasks, claim, complete, fail, block, bridgeInteroperate with Claude Code Agent Teams.
Integrationsintegration symphony, integration kanbanConvert external lifecycle events into AMQ messages. See the adapter contract.

Exit codes are 0 success, 1 general error, 2 usage, 3 not found, 4 timeout, 5 context mismatch, and 6 action required. JSON output does not change exit codes. --json-schema requires --json.

send and reply resolve --body from a literal, @file, or stdin. Empty or whitespace-only input is a usage error unless --allow-empty is explicit.

Message Kinds

KindReply kindDefault priorityPurpose
review_requestreview_responsenormalRequest review.
review_response-normalReturn review findings.
questionanswernormalAsk for a decision or fact.
answer-normalAnswer a question.
decision-normalRecord a decision.
brainstorm-normalExplore options.
status-lowReport progress or state.
todo-normalAssign work.

When work starts, reply with kind=status and an ETA. Use urgent only for work that must interrupt the current activity.

Dead Letter Queue

read, drain, and monitor move messages with invalid serialization or headers to DLQ and emit a dlq receipt. The envelope records the parse error, retry count, and retry state. A successful retry keeps a terminal audit in dlq/cur until explicit purge.

delivered is terminal and idempotent. pending or legacy indeterminate without a visible inbox destination refuses retry, including with --force. The flag bypasses only the retry-count limit. Bulk JSON separates new retries, already-delivered records, and skipped records.

Doctor and Wake Operations

doctor checks installation, root selection, permissions, configuration, and skill setup. --ops adds queue depth, sibling backlogs, DLQ age, presence, wake health, worktree diagnostics, and integration hints.

Mailbox and wake repair preserve existing messages and fail closed on unsafe paths, symlinks, conflicting session pins, or concurrent replacement. Doctor can inspect an explicit mismatched root, but mutation requires the authenticated pinned base or explicit --root --ignore-session-pin.

Before wake mutation, run amq wake check --me <agent> --json. Only restart_capability=agent_safe permits agent-side action. Repair, owner recovery, and retirement revalidate exact identity and have distinct scopes. See Wake operations for the full contract.

Coordination Workflows

During active work, run amq drain --include-body between phases. Use send --wait-for drained when delivery proof matters. Use watch only when no wake is live for you; a live wake already delivers a doorbell, and a blocking wait would hold your turn while the doorbell queues behind it. Reply to the initiator, preserve the existing thread, send status at start and phase boundaries, and finish with changes and verification.

The co-op guide owns peer roles, phased flow, wake use, supervisor recipes, and troubleshooting. The amq-cli skill owns agent-facing command mechanics. The amq-spec skill owns research-discuss-draft-review workflows and the human approval gate. Swarm mode is a bridge to Claude Code Agent Teams; AMQ messages to a teammate still require the team leader to relay them.

Testing

Run the tests of the packages you changed, narrowest first. The pre-push hook runs make check; CI runs the full make ci suite. Useful focused commands include:

go test ./internal/fsq -run TestMaildir
go test ./internal/cli -run '<relevant test>'
go test ./internal/sessionguard
make check-skills

Opt-in live proofs (AMQ_CMUX_LIVE, AMQ_GHOSTTY_LIVE, AMQ_CLAUDE_LIVE, AMQ_CODEX_LIVE, AMQ_TMUX_LIVE) skip unless the env is 1. They are not part of make ci. Commands are in Contributing: live proofs.

SessionStart hook-script tests in internal/keepalive/hookinstall run the real Bash script and skip unless AMQ_HOOK_SCRIPT_TESTS=1. Linux and macOS CI run them with -p 1 in a separate serial step, outside the parallel package suite.

Two kinds of test exist. One small happy-path test per user-visible behavior ships in the same PR as the behavior. A regression test for a defect observed in the field, in CI, or by pre-merge review ships in the same PR as the fix and reproduces that failure and nothing more; its comment names the bead, review finding, or CI run it came from. Both are deterministic and fast (under 5 seconds, no child process, no network) unless the observed defect lives at exactly that boundary and cannot be reproduced without it. Do not add speculative negative cases, mutation demonstrations, guard tests about tests, or tests for existing behavior with no observed defect. A slow or flaky test is deleted or rewritten to this bar, not tuned.

Before you add a test, name the contract it protects, the regression that makes it fail, and why existing coverage misses it. Each contract has one keeper at its strongest boundary: add a row to that table, not a near duplicate. A test that needs an export, flag, env var, or wrapper that no production caller uses belongs at the real boundary instead. A regression test must fail on the pre-fix code; check that privately before it ships.

Security

  • Queue directories use mode 0700 and files use mode 0600.
  • Handle and message ID validation prevents path traversal.
  • Unknown handles warn by default; --strict changes warnings to errors.
  • With --strict, unreadable or corrupt configuration is also an error.
  • External injectors execute local code. Their executable and ordered fixed arguments form the saved identity; message-derived payloads are sanitized.
  • Preserve uncertain ownership or filesystem state. Never add a force path that guesses at process, target, generation, or owner identity.

Commit Conventions

  • Install the repository hooks with ./scripts/install-hooks.sh.
  • Use conventional, descriptive commits such as fix(wake): preserve replacement generation.
  • Run the focused tests before committing and follow every pushed CI run to completion.
  • Do not commit placeholders, weaken a validator, regenerate goldens to hide a defect, or split code from the test that ships with it.

Documentation Policy

  • Keep README.md as the canonical install and onboarding path.
  • Keep COOP.md as the full co-op and supervisor operations guide.
  • Keep CLAUDE.md as a concise project index and engineering contract.
  • Keep docs/ evergreen: architecture, protocol contracts, and operational references only. Plans and frozen specs belong in issues, PRs, or the AMQ spec workflow.
  • Describe current behavior in present tense. Put one-sentence known limitations beside an issue link instead of adding historical narration.

Skill Development

Canonical skills live in skills/amq-cli/ and skills/amq-spec/. .claude/skills/, .agents/skills/, and .grok/skills/ are symlinks to those directories so local runs use repository changes. Project skills take precedence over user installations.

Edit only the canonical directory, bump skill metadata when publishing, run make check-skills, and test the project-local skill. Do not create divergent copies. See the README skill install for installed-skill commands.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.