This document is the agent contract for this repo. It applies identically to Codex, Claude Code, and any other agentic CLI working here. CLAUDE.md is a symlink to this file — do not edit them independently.
- Optimize for task completion with low token use.
- Prefer phase-based execution over conversational micro-steps.
If you are a Claude Code session arriving in this repo for the first time:
- Branch awareness — by default ANY branch that is not a protected base
(
main/dev/master, plus any repo-configured protected branch) counts as an agent-managed branch you may edit and commit on.agent/*,claude/*,vendor/*,feat/*, or any ad-hoc name all work — being OFF a protected base is the only load-bearing rule, so you don't need to setGUARDEX_AGENT_BRANCH_PREFIXES. Lockdown is opt-in: setGUARDEX_AGENT_BRANCH_PREFIXES_ONLY=1(+ an explicit prefix list) to gate the Claude Code edit/Bash guard, and/orGUARDEX_REQUIRE_AGENT_BRANCH=1(orgit config multiagent.requireAgentBranch true) to force git commits back onto theagent/*namespace. - Slash commands —
/gx-status,/gx-doctor,/gx-pivot,/gx-pr,/gx-finish,/gx-setup,/gx-actare available out of the box. See.claude/commands/./gx-actwraps nektos/act so CI workflows run locally before the remote PR run, letting you squash-merge on the first green round-trip. - PR flow — when you need explicit PR control, use
gx pr open,gx pr status,gx pr sync, orgx pr watch. For end-of-task commit + push + PR + merge + cleanup, still use the non-negotiablegx branch finish --via-pr --wait-for-merge --cleanup. - Repo wiring —
gx claude installwrites.claude/settings.json, hooks, slash commands, the gitguardex skill, and a.mcp.jsonthat registers the read-onlygxMCP server (the cross-repo agent radar:list_agents,who_owns,my_context) into a target repo. Opt out with--no-mcp.gx claude checkdiagnoses drift without writing;gx claude doctordiagnoses and repairs.
When writing complex features or significant refactors, use an ExecPlan (as described in .agent/PLANS.md) from design to implementation.
- Never edit, stage, or commit on
dev/main. Open anagent/*branch + worktree first. - Claim files before edits:
gx locks claim --branch "<agent-branch>" <file...>(or Colonytask_claim_fileon an active task). - Finish completed work with
gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup. Never stop at bare--via-pr.gx shipis the short alias for that exact gated finish. - When work is complete, always offer to finish and merge it — never leave commits stranded in a worktree. Set
GUARDEX_AUTO_SHIP=1to make a baregx finish/gx branch finishdefault to that gated ship automatically (see Toggle). - Commit, push, and open/update a PR for completed work unless the user explicitly says to keep it local.
- Use OpenSpec for change-driven work; create/update
openspec/changes/<slug>/before editing code (helper agent sub-branches excepted). - Keep outputs compact: less word, same proof.
- Do not commit ephemeral runtime artifacts or local settings:
.dev-ports.json,apps/logs/*.log,.codex/settings.local.json,.claude/settings.local.json,.omc/project-memory.json,.omc/state/**,.omx/state/**. - Do not embed stale memory dumps, PR transcripts, session history, or long logs in this file.
- Frontend/UI/UX requests: load
.codex/skills/ui-ux-pro-max/SKILL.mdfirst. - The
multiagent-safetymarker section below is machine-managed. Do not edit between markers.
# 1. Start a sandbox worktree (tier sizes OpenSpec scaffolding):
ALLOW_BASH_ON_NON_AGENT_BRANCH=1 \
gx branch start [--tier T0|T1|T2|T3] "<task>" "claude-<name>"
# 2. Work inside the printed worktree path:
cd .omc/agent-worktrees/gitguardex__claude-<name>__<slug>
gx locks claim --branch "agent/claude-<name>/<slug>" <file...>
# implement + commit inside this worktree
# 3. Validate specs (before archive / finish on T2/T3):
openspec validate --specs
# 4. Finish via PR + cleanup (the non-negotiable default):
gx branch finish \
--branch "agent/claude-<name>/<slug>" \
--base main --via-pr --wait-for-merge --cleanup
# Branch protection blocks merge? Enable auto-merge once PR URL is known:
gh pr merge <PR-NUMBER> --repo <owner>/<repo> --auto --squash
# Sweep multiple finished lanes in one shot:
gx finish --allTier guide (sized by blast radius; default is T1 when --tier is omitted —
escalate with --tier T2 for a behavior change or --tier T3 for plan-driven work):
| Tier | Use for | Scaffolding | Gates |
|---|---|---|---|
T0 |
typos, dep bumps, format-only | none | tasks gate skipped |
T1 |
≤5 files, 1 capability, no API/schema | notes.md only | tasks gate skipped |
T2 |
behavior change, API/schema, multi-module | full change workspace | full gates |
T3 |
cross-cutting, multi-agent, plan-driven | change + plan workspace | full gates |
See .agent/CLAUDE-CODE-WORKFLOW.md for full tier examples, finish flow, and skill_guard notes.
- Python:
.venv/bin/python(uv, CPython 3.13.3) - GitHub auth for git/API is available via env vars:
GITHUB_USER,GITHUB_TOKEN(PAT). Do not hardcode or commit tokens. - For authenticated git over HTTPS in automation, use:
https://x-access-token:${GITHUB_TOKEN}@github.com/<owner>/<repo>.git
The /project-conventions skill is auto-activated on code edits (PreToolUse guard).
| Convention | Location | When |
|---|---|---|
| Code Conventions (Full) | /project-conventions skill |
On code edit (auto-enforced) |
| Git Workflow | .codex/conventions/git-workflow.md |
Commit / PR |
- Specs/Design/Tasks (SSOT):
openspec/- Active changes:
openspec/changes/<change>/ - Main specs:
openspec/specs/<capability>/spec.md - Archived changes:
openspec/changes/archive/YYYY-MM-DD-<change>/
- Active changes:
spec.mdis normative (testable requirements only); free-form context lives inopenspec/specs/<capability>/context.md.- Do not add feature/behavior docs under
docs/. Do not editCHANGELOG.mddirectly. - Validate:
openspec validate --specs. Verify before archive:/opsx:verify <change>. - Full OpenSpec workflow, philosophy, command list, and documentation model:
.agent/OPENSPEC-WORKFLOW.md.
If a change publishes or bumps a package version, the same change must also update the release notes / changelog entries (record change notes in OpenSpec artifacts, not CHANGELOG.md).
| Subdoc | What's inside |
|---|---|
.agent/TOKEN-DISCIPLINE.md |
Token-efficient execution: planning phases, token/command/git discipline, reporting format, verification, and multi-agent token budget supplement. |
.agent/MULTI-AGENT-EFFICIENCY.md |
Token-efficient multi-agent work: scout-then-implement, one-job-per-agent, parallel split-role review, model routing, and when not to fan out. |
.agent/GUARDEX-TOGGLE.md |
GUARDEX_ON toggle semantics in repo-root .env (disable / re-enable Guardex workflow). |
.agent/CLAUDE-CODE-WORKFLOW.md |
Full Claude Code workflow: tiering table with examples, sandbox + lock + finish steps, default Claude finish (non-negotiable), skill_guard notes. |
.agent/OPENSPEC-WORKFLOW.md |
OpenSpec-first workflow, philosophy, tooling-freshness commands, source-of-truth layout, documentation model (spec + context), and /opsx:* command list. |
.agent/MULTI-AGENT-CONTRACT.md |
Repo-specific supplements to the marker-managed multiagent-safety contract: local base safety, ownership/lock discipline (incl. main.rs lock), shared behavior protection, integrator finalization gate. |
.agent/PLAN-WORKSPACE.md |
openspec/plan/ workspace contract: default quick flow, role tasks files, checklist headings, helper sub-branch exception, scaffold command. |
.agent/STALLED-WORKTREE-RECOVERY.md |
How scripts/agent-stalled-report.sh and scripts/agent-autofinish-watch.sh recover stalled agent/* worktrees; __source-probe-* cleanup steps. |
Guardex is enabled by default. Disable via repo-root .env with GUARDEX_ON=0|false|no|off. Re-enable with GUARDEX_ON=1.
Auto-ship (opt-in, off by default): set GUARDEX_AUTO_SHIP=1 to make a bare gx finish / gx branch finish behave like gx ship — open a PR from the worktree, wait for the merge into base, clean up the sandbox, and enforce the merge gate (clean AI review + green CI) before merging. Explicit flags still win (e.g. --no-gate-review opts back out of the gate, --direct-only out of the PR). via-pr / wait-for-merge / cleanup are already the finish defaults, so the toggle's net effect is turning the gate on so unattended merges stay safe.
- Work from an
agent/*branch + worktree. Never edit the protected base directly. - Claim files before editing. Confirm a path is in your claim before deleting it.
- Commit, push, and open/update a PR for completed work unless the user says keep-local.
- Keep outputs and notes compact. Less word, same proof.
Small tasks stay direct and caveman-only.
For typos, single-file tweaks, one-liners, version bumps, comment-only changes, or similarly bounded asks, solve directly and do not escalate into heavy orchestration just because a keyword appears.
Lightweight escape prefixes: quick:, simple:, tiny:, minor:, small:, just:, only:.
Promote to full Guardex / OMX orchestration only when scope grows into multi-file behavior change, API/schema work, refactor, migration, architecture, cross-cutting scope, long prompt, or multi-agent execution.
Every task = one agent/* branch + worktree. Start with:
gx branch start "<task>" "<agent-name>"Then cd into the printed worktree path. Every subsequent git command runs from inside that worktree.
If a worktree is already open for this chat/session, continue in it instead of spawning a fresh lane unless the user redirects scope.
On the primary checkout, do not run:
git checkout <ref> git switch <ref>
git switch -c ... git checkout -b ...
git worktree add <p> <agent-branch>Allowed on primary: git fetch, git pull --ff-only. Anything else needs gx branch start first.
If you are about to type git checkout agent/... from the primary checkout, stop — that is the mistake that flips primary onto an agent branch.
Finish or stash edits inside the worktree they belong to before any branch switch on primary. The post-checkout guard may auto-stash a dirty primary tree as guardex-auto-revert <ts> <prev>-><new> — that is a safety net, not a workflow.
Recover: git stash list | grep 'guardex-auto-revert'.
Before editing, claim files:
gx locks claim --branch "<agent-branch>" <file...>If another agent owns nearby code:
- read the latest context for that lane
- post a handoff / question
- avoid reverting unrelated changes
- report conflicts instead of overwriting
When posting handoff or working-state notes (.omx/notepad.md, PR description, or whichever coordination surface the repo uses), use these fields:
branch=<branch>; task=<task>; blocker=<blocker>; next=<next>; evidence=<path|command|PR|spec>
No long proof dumps, no stale narrative, no full logs. Bulky proof goes in OpenSpec artifacts, PRs, or command output.
Finish with:
gx branch finish --branch "<agent-branch>" --via-pr --wait-for-merge --cleanup
# or:
gx finish --allTask scaffolds and manual task edits must include a final completion/cleanup section that ends with PR merge + sandbox cleanup and records PR URL + final MERGED evidence.
Task is complete only when all six are true:
- changes committed
- branch pushed
- PR URL recorded
- PR state =
MERGED - sandbox worktree pruned
- final handoff records proof
If blocked, append a BLOCKED: note and stop. Do not half-finish.
Use the finish flow instead of standalone git push / gh pr commands. The finish flow owns commit, push, PR creation/update, merge wait, and sandbox cleanup; standalone fallbacks strand PR / merge / cleanup state.
Guardex cannot bypass Codex host approval prompts or external-remote policy decisions. When the host blocks a publish or finish command, request approval for the narrow gx branch finish ... command, or for the exact session wrapper that invokes it, and continue after approval. Do not replace the finish flow with repeated standalone git push / gh pr attempts — that increases approval churn and can strand state.
Assume other agents edit nearby. Never revert unrelated changes. Never simplify or delete critical shared paths without explicit request + regression coverage. Prefer compatibility-preserving changes when adjacent systems may be in motion.
Every completion handoff includes: branch, task, files changed, behavior touched, verification commands + results, PR URL, merge state, sandbox cleanup state, risks/follow-ups.
Blocked? Use:
BLOCKED:
branch=<branch>
task=<task>
blocker=<blocker>
next=<next>
evidence=<path|command|PR|spec>
Before claiming completion, run the narrowest meaningful verification (pnpm test, pnpm typecheck, pnpm lint, etc. — whatever fits the touched area). Do not claim green without command output evidence. If a command can't run, record command / reason / risk / next.
Persist unresolved questions or blockers into openspec/plan/<plan-slug>/open-questions.md as unchecked items. Resolve in-place rather than burying in chat.
- fff MCP (file search): prefer for all file search; fall back to
rtk grep/rtk findorrg. - rtk (shell compression): wrap noisy discovery (
rtk ls/grep/find/read), git/gh (rtk git status/gh pr list), and verification (rtk tsc/lint/test). Do not wrap machine-readable commands (--porcelain,--json, exact stdout contracts). - OpenSpec: keep
openspec/changes/<slug>/tasks.mdcurrent during work, not batched. Validate withopenspec validate --specsbefore archive.
Default: less word, same proof.
- Plan in ≤4 bullets, execute by phase, batch reads/commands.
- Verify once per phase. A bounded ≤10-step run is fine.
- 20+ steps with rising per-turn input = fragmentation → collapse to inspect once, patch once, verify once, summarize once.
- Startup/resume summaries stay tiny:
branch,task,blocker,next,evidence. - Keep raw terminal interaction out of long-lived context: retain only process, action sent, current result, next action.
- Full commands/stdout belong in logs; prompt context keeps only the latest 1–2 checkpoints plus the newest tool-result summary.
Fan-out saves tokens only when each agent has a narrow job and returns a compact result. When reviewing or implementing here:
- Scout, then implement. A cheap-model subagent locates the 3-5 files that matter and returns a summary; edit those inline. Don't read 20+ files in the main context to find the 4 that count.
- One agent, one job. Each subagent gets a single objective and returns one output (analyze OR fix), not a muddle of both.
- Review by parallel role. Run correctness / security / consistency reviewers in parallel and synthesize — cheaper and sharper than one reviewer holding the whole diff. The finish review-gate is the place for it.
- Route models to task weight. scan/explore/draft → cheap (e.g.
haiku); implement/debug → mid (sonnet); architecture/complex review → top (opus).CLAUDE_CODE_SUBAGENT_MODELsets the subagent tier. - Don't fan out trivial work. One-file tweaks and bounded edits stay direct (see Task-size routing) — a subagent's setup cost only pays off on a wide read or review surface.
If a change bumps a published version, the same PR records release notes in the appropriate OpenSpec artifact or release-note mechanism for the repo. Do not edit CHANGELOG.md directly unless the repo explicitly requires manual changelog edits.
No stale memory dumps, PR transcripts, long logs, generated status snapshots, session history, full OpenSpec examples, or duplicate workflow docs. This block is the hard contract — long examples and recovery docs live in repo-specific workflow files.
For additional context about technologies to be used, project structure, shell commands, and other important information, read the current plan