GuardeX is a safety layer for parallel Codex/agent work in git repos.
Warning
Not affiliated with OpenAI or Codex. Not an official tool.
- Standalone frontend repository: https://github.com/Webu-PRO/guardex-frontend
- This repository tracks/mirrors the frontend under
frontend/as documented below.
Multiple Codex agents worked on the same files at the same time. They started overwriting or deleting each other's changes. Progress became de-progressive: more activity, less real forward movement.
GuardeX exists to stop that loop.
flowchart LR
A[Agent A edits shared files] --> S[Same target surface]
B[Agent B edits shared files] --> S
C[Agent C edits shared files] --> S
D[Agent D edits shared files] --> S
E[Agent E edits shared files] --> S
S --> F[Conflict / overwrite churn]
F --> G[Deleted or lost code]
G --> H[Rework and confusion]
H --> I[Regression risk grows]
I --> F
- isolated
agent/*branch + worktree per task - explicit file lock claiming before edits
- deletion guard for claimed files
- protected-base branch safety (
main,dev,masterby default) - repair/doctor flow when drift appears
npm i -g @imdeadpool/guardex
cd /path/to/your/repo
gx setupAlias support:
- preferred:
gx - full:
guardex
# 1) Start isolated branch/worktree
bash scripts/agent-branch-start.sh "task-name" "agent-name"
# 2) Claim ownership
python3 scripts/agent-file-locks.py claim --branch "$(git rev-parse --abbrev-ref HEAD)" <file...>
# 3) Implement + verify
npm test
# 4) Finish (commit/push/PR/merge flow)
bash scripts/agent-branch-finish.sh --branch "$(git rev-parse --abbrev-ref HEAD)" --base dev --via-pr --wait-for-merge
# 5) Optional cleanup after merge
gx cleanup --branch "$(git rev-parse --abbrev-ref HEAD)"If you use scripts/codex-agent.sh, the finish flow is auto-run after the Codex session exits.
It auto-commits sandbox changes, retries once after syncing if the branch moved behind base during the run, then pushes/opens PR merge flow against dev.
If you run Codex in multiple existing agent worktrees directly (for example from VS Code Source Control), finalize all completed branches with:
gx finish --all# health check (default when run with no args)
gx status
gx status --strict # exit non-zero on findings (v6 name: gx scan)
# bootstrap, repair, verify — all in one
gx setup
gx setup --repair # repair only (v6 name: gx fix)
gx setup --install-only # scaffold templates, skip global installs (v6 name: gx install)
gx doctor # repair + verify (auto-sandboxes on protected main)
# target another repo without switching your current checkout
gx setup --target /path/to/repo
gx doctor --target /path/to/repo
# optional VS Code workspace showing repo + agent worktrees
gx setup --target /path/to/repo --parent-workspace-view
# monorepo with nested git repos (e.g. /mainfolder/.git + /mainfolder/apps/*/.git)
# setup auto-installs into every nested repo; use --no-recursive to limit to the top-level
gx setup --target /mainfolder
gx setup --target /mainfolder --no-recursive
# protected branch management
gx protect list
gx protect add release staging
gx protect remove release
# sync current agent branch with origin/<base>
gx sync --check
gx sync
# background bots (review monitor + stale cleanup)
gx agents start
gx agents stop
gx agents status
# per-agent-branch lifecycle
gx finish --all # commit + PR + merge every ready agent/* branch
gx cleanup # prune merged/stale branches and worktrees
gx cleanup --watch --interval 60
# AI-ready setup prompt (paste into Codex/Claude)
gx prompt # full checklist (v6 name: gx copy-prompt)
gx prompt --exec # commands only (v6 name: gx copy-commands)
gx prompt --snippet # AGENTS.md managed block template
# reports
gx report scorecard --repo github.com/recodeee/guardexFive commands were consolidated into flags. Old names still work and print a one-line deprecation notice; they'll be removed in v8.
| v6 command | v7 replacement |
|---|---|
gx init |
gx setup |
gx install |
gx setup --install-only |
gx fix |
gx setup --repair |
gx scan |
gx status --strict |
gx copy-prompt |
gx prompt |
gx copy-commands |
gx prompt --exec |
gx print-agents-snippet |
gx prompt --snippet |
gx review |
gx agents start (runs review + cleanup) |
Use this to auto-prune idle agent/* worktrees created by Codex while keeping active worktrees untouched.
# watch cleanup loop every minute (default idle threshold is 10 minutes when --watch is enabled)
gx cleanup --watch --interval 60
# one-shot cleanup for branches idle at least 10 minutes
gx cleanup --idle-minutes 10
# run a single watch cycle (helpful for cron/CI checks)
gx cleanup --watch --once --interval 60# starts review bot + cleanup bot in background for the current repo
gx agents start
# optional tuning
gx agents start --review-interval 30 --cleanup-interval 60 --idle-minutes 10
# show whether both bots are running for this repo
gx agents status
# stop both bots and clear repo-local state
gx agents stop- No command defaults to
gx status. gx initis alias ofgx setup.- Setup/doctor can install missing global OMX/OpenSpec/codex-auth with explicit Y/N confirmation.
gx setupchecks GitHub CLI (gh) and prints install guidance if missing.- Optional parent-folder VS Code Source Control view:
gx setup --target /path/to/repo --parent-workspace-viewcreates../<repo>-branches.code-workspace. - Monorepo-aware: when the target contains nested git repos (e.g.
apps/*/.git),gx setupinstalls the workflow into every discovered repo. Git submodules (.gitfiles) and guardex worktrees under.omx/agent-worktrees/are skipped. Opt out with--no-recursive; tune discovery with--max-depth <n>,--skip-nested <dir>, and--include-submodules. - Interactive self-update prompt defaults to No (
[y/N]). - In initialized repos,
setup/install/fixblock protected-base writes unless explicitly overridden. - Direct commits/pushes to protected branches are blocked by default.
- Exception: VS Code Source Control commits are allowed on protected branches that exist only locally (no upstream and no remote branch).
- Optional repo override for manual VS Code protected-branch writes:
git config multiagent.allowVscodeProtectedBranchWrites true. - Codex/agent sessions stay blocked on protected branches and must use
agent/*branch + PR workflow. - On protected
main,gx doctorauto-runs in a sandbox agent branch/worktree. - In-place agent branching is disabled;
scripts/agent-branch-start.shalways creates a separate worktree to keep your visible local/base branch unchanged. - Fresh sandbox branches intentionally start without any git upstream; guardex records the protected base in
branch.<name>.guardexBase, and the firstgit push -upublishes the real upstream branch. scripts/agent-branch-start.shhydratesscripts/codex-agent.shinto new sandbox worktrees when missing, so auto-finish launcher flow stays available.
Default protected branches:
devmainmaster
gx protect list
gx protect set main release hotfix
gx protect resetStored in git config key:
multiagent.protectedBranches
GuardeX PR/merge automation depends on GitHub CLI (gh), including
agent-branch-finish.sh PR flows and codex-agent.sh auto-finish behavior.
Install + verify:
# install guide: https://cli.github.com/
gh --version
gh auth statusGuardeX setup now installs a starter file at .github/pull.yml.example.
To enable fork auto-sync:
cp .github/pull.yml.example .github/pull.ymlThen edit .github/pull.yml:
- set
rules[].baseto your fork branch (main,master, ordev) - set
rules[].upstreamto<upstream-owner>:<branch>
Install the app: https://github.com/apps/pull
Validate config: https://pull.git.ci/check/<owner>/<repo>
Install app: https://github.com/apps/cr-gpt
gx setup also installs .github/workflows/cr.yml (GitHub Actions review workflow).
Then in your repo:
Settings -> Secrets and variables -> Actions- open
Variables - add
OPENAI_API_KEY
After that, the app reviews new and updated pull requests automatically.
This repo includes .github/workflows/sync-frontend-mirror.yml, which mirrors
the frontend/ subtree to a separate repository whenever main receives
changes under frontend/**.
Default target:
- repo:
Webu-PRO/guardex-frontend - branch:
main
Required setup (in this repository):
Settings -> Secrets and variables -> Actions- Add repository secret
GUARDEX_FRONTEND_MIRROR_PAT- value must be a token with
contents:writeaccess toWebu-PRO/guardex-frontend
- value must be a token with
Optional overrides (Actions Variables):
GUARDEX_FRONTEND_MIRROR_REPO(defaultWebu-PRO/guardex-frontend)GUARDEX_FRONTEND_MIRROR_BRANCH(defaultmain)
Manual run:
gh workflow run sync-frontend-mirror.ymlFor multi-identity Codex workflows, GuardeX pairs with
codex-auth.
Install:
npm i -g @imdeadpool/codex-account-switcherCommon commands:
codex-auth save <name>
codex-auth use <name>
codex-auth list --details
codex-auth currentscripts/agent-branch-start.sh
scripts/agent-branch-finish.sh
scripts/codex-agent.sh
scripts/review-bot-watch.sh
scripts/agent-worktree-prune.sh
scripts/agent-file-locks.py
scripts/install-agent-git-hooks.sh
scripts/openspec/init-plan-workspace.sh
.githooks/pre-commit
.githooks/pre-push
.codex/skills/guardex/SKILL.md
.claude/commands/guardex.md
.github/pull.yml.example
.github/workflows/cr.yml
.omx/state/agent-file-locks.json
If package.json exists, setup also adds agent:* helper scripts.
If you enabled global OpenSpec install during setup (@fission-ai/openspec), use the full guide here:
Default core flow:
/opsx:propose <change-name> -> /opsx:apply -> /opsx:archive
Optional expanded flow:
openspec config profile <profile-name>
openspec update/opsx:new <change-name> -> /opsx:ff or /opsx:continue -> /opsx:apply -> /opsx:verify -> /opsx:archive
scripts/codex-agent.shenforces OpenSpec workspaces before it launches Codex in each sandbox branch/worktree.scripts/agent-branch-start.shcan scaffold bothopenspec/changes/<agent-branch-slug>/andopenspec/plan/<agent-branch-slug>/when you setGUARDEX_OPENSPEC_AUTO_INIT=true.- Set
GUARDEX_OPENSPEC_AUTO_INIT=false(default foragent-branch-start) to skip branch-start auto-bootstrap. - Set
GUARDEX_OPENSPEC_PLAN_SLUG=<kebab-case-slug>to force a specific plan workspace name. - Set
GUARDEX_OPENSPEC_CHANGE_SLUG=<kebab-case-slug>to force a specific change workspace name. - Set
GUARDEX_OPENSPEC_CAPABILITY_SLUG=<kebab-case-slug>to override the default capability folder used forspec.mdscaffolding.
- CI matrix on Node 18/20/22 (
npm test,node --check,npm pack --dry-run) - trusted publishing with provenance in GitHub Actions
- OpenSSF Scorecard + Dependabot for Actions
- disclosure policy in
SECURITY.md
npm test
node --check bin/multiagent-safety.js
npm pack --dry-run- Fixed: next publish target now advances past npm. Bumped
@imdeadpool/guardexfrom7.0.6to7.0.7so the nextnpm publishdoes not collide with the already-published registry version. - Fixed: root package metadata drift in
package-lock.json. The lockfile root version had fallen behind the package manifest (7.0.4vs.7.0.6), which made release metadata inconsistent. The bump resynchronizedpackage.jsonandpackage-lock.jsonon7.0.7.
- Fixed: self-updater lied about success.
gx's update prompt runsnpm i -g @imdeadpool/guardex@latestand previously trusted npm's exit code. When npm's resolution cache made it report "changed 1 package" without actually overwriting the files (a known quirk triggered when the user just bumped from N-1 → N in the same session, or with a warm metadata cache), the prompt kept re-firing on every subsequentgxinvocation because the on-diskpackage.jsonwas still stale.gxnow re-reads the globally installedpackage.jsonafter the@latestinstall returns, compares itsversionfield to the advertised latest, and if they don't match runs a pinned retrynpm i -g @imdeadpool/guardex@<latest>to force the cache past the obstructing entry. If the pinned retry also fails to advance the on-disk version, the user gets a clear hint (npm root -g && npm cache verify) instead of a silent loop.
- Added:
oh-my-claudetogx statusglobal-toolchain check. The Claude-side mirror ofoh-my-codexis now reported alongside the existing services (oh-my-codex,@fission-ai/openspec,@imdeadpool/codex-account-switcher,gh). Users who have not yet installed it will see a clear "inactive" line instead of silent omission, matching the existing codex detection contract. - Added:
.omc/to the managed.gitignoreblock.gx setup/gx doctorwrite a.omc/entry next to.omx/so Claude-specific runtime state (notepad, worktrees landing there in a follow-up) stays out of commits by default, parity with the existing.omx/treatment.
- Fixed: publish collision on npm. Advanced the package metadata from
7.0.3to7.0.4sonpm publishno longer targets an already published version. - Changed: release-note sync for versioning rule. Added this versioned entry in README in the same change as the package bump to keep publish metadata and release notes aligned.
- Branch/worktree naming refactor.
agent-branch-start.shnow producesagent/<role>/<task>-<YYYY-MM-DD>-<HH-MM>instead ofagent/<role+account-email>/<snapshot-slug>-<task>-<cksum6>. Codex account names (e.g.Zeus Edix Hu) and 6-hex checksums no longer leak into branch or worktree paths. - Role normalization.
AGENT_NAMEis collapsed to{claude, codex, <explicit>}via (in order) theGUARDEX_AGENT_TYPEenv override, a substring match againstclaude/codex, theCLAUDECODE=1sentinel, or a fallback tocodex. Other roles (integrator,executor, etc.) pass through when set viaGUARDEX_AGENT_TYPE. - New
--print-name-onlyflag onagent-branch-start.shfor deterministic tests; honoursGUARDEX_BRANCH_TIMESTAMPfor reproducible output. --tierflag accepted silently for CLAUDE.md compatibility (scaffold sizing not wired through yet).- Tests
install.test.jscovering the old snapshot-slug format were rewritten to assert the new role-datetime shape.
- Fix:
__source-probe-*worktree leak on conflict exit.agent-branch-finish.shwas registering itscleanup()trap after the sync-guard rebase block, so when that rebase hit conflicts and the script exited, the throwaway probe worktree was never removed.gx doctorsweeps against stalled branches accumulated one new probe per run. - The cleanup trap is now installed immediately after probe creation, and aborts any in-progress
rebase/mergebeforeworktree remove --forceso conflict-stuck probes are cleaned up reliably.
- Maintenance release.
-
Breaking (soft). Consolidated 17 commands into 12 visible commands with flag-based subcommands. Five removed names (
init,install,fix,scan,copy-prompt,copy-commands,print-agents-snippet,review) still work but print a one-line deprecation notice on stderr and will be removed in v8. See the migration table in "Copy-paste: common commands" above. -
Token-usage improvements. Trimmed the auto-installed agent templates that live inside every consumer repo and get loaded into every Claude/Codex session:
templates/AGENTS.multiagent-safety.md: 6990 B → 1615 B (−77%)templates/codex/skills/guardex/SKILL.md: 2732 B → 1086 B (−60%)templates/claude/commands/guardex.md: 472 B → 357 B (−24%)- Total: 10194 B → 3058 B per consumer repo (−70%, ~1.5k fewer tokens per agent session).
The
AI_SETUP_PROMPTandAI_SETUP_COMMANDSconstants used bygx promptare now compact checklists, so pipinggx promptinto a model context is cheaper too. -
New
gx promptcommand replaces three prompt-emitting commands:gx prompt(full checklist),gx prompt --exec(commands only),gx prompt --snippet(AGENTS.md managed-block template). -
New flag surface on
gx setup:--install-only(templates/hooks/locks only),--repair(fix drift), plus the existing--target,--parent-workspace-view,--dry-run, etc. -
New
gx status --strictmirrors the oldgx scanbehavior (exit non-zero on findings). -
Updated internal
REQUIRED_PACKAGE_SCRIPTSfor consumerpackage.jsonsoagent:safety:scanandagent:safety:fixhelper scripts now invoke the new v7 surface (gx status --strict,gx setup --repair).
- Preserve existing repo-owned
AGENTS.mdmarker content duringgx setup/gx doctorby default; only rewrite marker blocks when--forceis explicitly used. - Preserve existing
agent:*package scripts during setup/doctor repairs by default so repo-local command customizations are not silently replaced. - Forward
--forcethrough sandboxed doctor execution so intentional canonical template/script rewrites still work end-to-end. - Added regression tests for both preservation behaviors (
setup+doctor). - Bumped package version from
6.0.0to6.0.1for the next npm publish.
- Breaking — removed the legacy
musafetybin alias and allMUSAFETY_*environment variables. Callers must migrate to theguardex/gxbins and theGUARDEX_*env-var surface. - Breaking — bootstrap manifest filename changed from
musafety-bootstrap-manifest.jsontoguardex-bootstrap-manifest.json; existing sandbox worktrees must be pruned + re-bootstrapped (or have their manifest manually renamed). - Rebranded all remaining
musafety/Musafety/MUSAFETYcodename tokens toguardex/Guardex/GUARDEXacross scripts, templates, hooks, tests, and docs. - The descriptive phrase
multiagent-safety(includingbin/multiagent-safety.jsandtemplates/AGENTS.multiagent-safety.md) is preserved intentionally — only the short codename changed. - Bumped package version from
5.0.17to6.0.0for the next npm publish.
- Bumped package version from
5.0.16to5.0.17for the next npm publish.
- Fixed
gx doctorruntime crash (parseDoctorArgs is not defined) by restoring the doctor argument parser for--targetand--strict. - Fixed
gx doctorcommand routing so the repair-first doctor flow remains the active command path (duplicate legacy doctor definition no longer overrides it). - Updated worktree change detection to run
git status --porcelain --untracked-files=normal --for consistent normal untracked-file behavior. - Added regression coverage that asserts the doctor parser function exists in
bin/multiagent-safety.js. - Bumped package version from
5.0.15to5.0.16.
- Added
gx setup --parent-workspace-viewto generate a parent-folder VS Code workspace (../<repo>-branches.code-workspace) that shows both the base repo and.omx/agent-worktreesin Source Control. - Added dry-run-safe parent workspace operations (
would-create/would-update) and setup output that prints the created workspace path. - Added regression coverage for parent workspace generation and dry-run behavior.
- Bumped package version from
5.0.14to5.0.15.
- Changed release metadata for the next npm publish by bumping package version from
5.0.13to5.0.14. - Kept Guardex release notes synchronized with the published package version.
- Bumped package version from
5.0.12to5.0.13for the next npm publish.
- Bumped package version from
5.0.11to5.0.12for the next npm publish. - Updated repository metadata and README links to the renamed GitHub repository (
recodeee/guardex).
- Updated the managed AGENTS contract wording to use
GXnaming and added an explicit OMX completion policy requiring commit + push + PR creation/update at task completion. - Ensured
gx installexplicitly configures the managedAGENTS.mdpolicy block and added regression coverage for this install-path behavior. - Bumped package version from
5.0.10to5.0.11for the next npm publish.
- Bumped package version from
5.0.9to5.0.10for the next npm publish.
- Enforced OpenSpec workspace bootstrap for sandbox agent execution:
scripts/codex-agent.shnow initializesopenspec/plan/<agent-branch-slug>/before launching Codex, andscripts/agent-branch-start.shsupportsGUARDEX_OPENSPEC_AUTO_INITplusGUARDEX_OPENSPEC_PLAN_SLUG. - Tightened doctor auto-finish correctness: sandbox finish now waits for merge and exits non-zero if the PR closes without merge, so repair flows are not reported as complete when policy blocks merge.
- Updated package version from
5.0.8to5.0.9for the next npm publish.
- Fixed
bin/multiagent-safety.jssyntax regressions in the doctor sandbox flow (Unexpected identifier/Unexpected end of input) that were breaking CLI execution and CI tests. - Restored
scripts/codex-agent.shfromtemplates/scripts/codex-agent.shso critical runtime helper parity checks pass in clean CI clones. - Bumped package version from
5.0.7to5.0.8for the next npm publish.
- Add the user-facing changes for the next release here before assigning a version number.
- Keep this section focused on behavior changes (
Added,Changed,Fixed) rather than version-bump-only notes.
gx cleanupand auto-finish cleanup now prune clean agent worktrees by default, so VS Code Source Control focuses on your local branch plus worktrees with active changes.- Added
gx cleanup --keep-clean-worktreesto opt out and keep clean worktrees visible. - Bumped package version from
5.0.5to5.0.6for the next npm publish.
- Bumped package version from
5.0.4to5.0.5so npm publish can proceed with the next patch release.
- Bumped package version from
5.0.3to5.0.4to stay one patch ahead of the current npm published version.
- Bumped package version from
5.0.2to5.0.3for the next npm publish.
- Auto-closes Codex sandbox branches through PR workflow and keeps merged branch/worktree sandboxes for explicit cleanup via
gx cleanup. - Runs
gx doctorrepairs from a sandbox whenmainis protected. - Allows tightly guarded Codex-only commits for
AGENTS.md/.gitignoreon protected branches. - Advanced package version to keep npm publishing unblocked.
- Rebranded the CLI to GuardeX with
gx-first command UX. - Published under scoped package name
@imdeadpool/guardexto avoid npm name collisions. - Enforced a repeatable per-message agent branch lifecycle in setup/init flows.
- Added codex-auth-aware sandbox branch naming support.
- Added repository metadata (
repository,bugs,homepage,funding) in package manifest. - Added CI workflow for Node 18/20/22 with packaging and syntax verification.
- Added npm provenance-oriented release workflow, OpenSSF Scorecard workflow, and Dependabot for Actions.
- Added explicit
SECURITY.mdandCONTRIBUTING.md.
- Added optional pre-commit behind-threshold sync gate (
multiagent.sync.requireBeforeCommit,multiagent.sync.maxBehindCommits). - Added
gx syncworkflow (--check, sync strategies, report mode). agent-branch-finish.shnow blocks finishing when source branch is behindorigin/<base>(config-aware).
- Added
scripts/agent-worktree-prune.shto templates/install. agent-branch-finish.shnow auto-runs prune after merge (best effort).- Added npm helper script:
agent:cleanup.
- Setup now detects existing global OMX/OpenSpec installs first.
- If tools are already present, setup skips global install automatically.
- Interactive approval is strict
[y/n](waits for explicit answer). - Added setup screenshot to README.
- Added workflow screenshots (branch start, lock/delete guard, source-control view).
- Added setup-time Y/N approval prompt for optional global install of:
oh-my-codex@fission-ai/openspec
- Added setup flags for automation:
--yes-global-install--no-global-install
- Added official repo links for OMX and OpenSpec.
