GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - securiace-dev/gh-account: Fail-closed multi-account GitHub CLI router - built for anyone (human or AI agent) juggling multiple GitHub identities on one machine.

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
.github/workflows
.github/workflows
 
 
config
config
 
 
docs
docs
 
 
scripts
scripts
 
 
tests
tests
 
 
.gitignore
.gitignore
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 
gh-account
gh-account
 
 

Repository files navigation

gh-account

A fail-closed multi-account router for the GitHub CLI, built for anyone — human or AI agent — who works across more than one GitHub identity from the same machine.

The problem

If you have a personal account, a work/org account, and maybe a client account all authenticated in gh on the same box, it is very easy for something — a script, an AI coding agent, a stale PATH, an unset env var — to run gh pr create or git push under the wrong identity. The damage ranges from an embarrassing commit author to a real credential/data leak across an account boundary.

This gets sharply worse once an AI agent is the one driving gh/git unattended: it won't notice a wrong-account mistake the way a human glancing at a terminal prompt might, and a broken mid-operation state (partial auth switch, a crashed process holding a stale identity) can silently persist into the next unrelated task.

gh-account exists to make "wrong identity" and "stuck mid-switch" both structurally hard to hit, rather than something you have to remember to check for.

What makes it different

Compared to other multi-account gh tools, gh-account is built around a few non-negotiable guarantees rather than convenience UX:

  • Fail-closed, not fail-open. Every check defaults to refusing the operation on ambiguity — ownership mismatches, symlinked config paths, unsafe permissions/ACLs, an unexpected XDG_CONFIG_HOME/GH_CONFIG_DIR — rather than proceeding and hoping.
  • Guaranteed restore. exec/git-exec switch the active account under a per-UID lock, run the requested command, and restore the prior account afterward — including on crash or signal, verified, not assumed.
  • Atomic config mutation. Git identity/config changes go through a whole-file transaction journal, so an interrupted write can be recovered or cleanly refused on the next run instead of leaving a half-written config.
  • Secret-free, agent-safe diagnostics. doctor is read-only and reports findings (misconfiguration, unsafe permissions, auth state) without ever emitting a token, credential, or anything else unsafe for an AI agent to read back into its own context.
  • A real audit trail. Every mutating operation can emit a structured, secret-scrubbed JSONL event, with an optional analyzer (insights) for post-hoc pattern review.
  • Actually tested. A ~3,200-line hermetic test suite (500+ assertions) drives the tool against faked gh/git/ps/stat/lockf binaries in an isolated HOME for every case — no test ever touches a real account.

Installation

As a standalone script

curl -fsSL https://raw.githubusercontent.com/securiace-dev/gh-account/main/gh-account \
  -o ~/.local/bin/gh-account
chmod +x ~/.local/bin/gh-account

As a gh extension

gh extension install securiace-dev/gh-account
# then: gh account <subcommand> ...

Requirements: the GitHub CLI (gh), Git, jq, and bash (preferred; see below). Tested on macOS and Linux (Debian/Ubuntu, including user-private-group accounts).

Runtime and portability notes

  • bash is the validated runtime. The script is #!/bin/sh for installability, but it re-executes itself under bash when its pinned PATH provides one. Routed commands are supervised through a job-control process group, which needs set -m to work without a controlling terminal — bash does that, dash (Debian/Ubuntu's /bin/sh) does not. macOS's /bin/sh is bash, so nothing changes there. GH_ACCOUNT_SH=posix disables the re-exec for diagnosis; it is not a supported way to run routed commands.
  • User-private groups are understood. On systems where each user's primary group is a same-named group with no other members (the Debian/Ubuntu default, umask 002), a group-write bit is treated as owner-only. On shared primary groups (macOS staff, users, admin) it is still refused — there it really is shared.
  • Sticky-bit directories (/tmp, /var/tmp) are accepted as ancestors; world-writable directories without the sticky bit are not.
  • System-scope git config (git config --system) may live under a package prefix whose ancestry is admin-group-writable (Homebrew's /opt/homebrew); that ancestry is tolerated for system scope only. The file itself must still be owner- or root-owned and not writable by others.
  • Containers without an init (plain docker run) leave exited processes as zombies. The router's liveness checks account for that, so a crashed operation's lease can still be reclaimed there.

The full reasoning, with the experiments that proved each item, is in docs/portability-rca-2026-09-27.md.

Usage

gh-account list
gh-account current [REPO]
gh-account doctor [REPO] [--account USER] [--deep] [--json]
gh-account preflight USER [REPO] [--required-scopes LIST] [--json]
gh-account repair USER [REPO] [--dry-run] [--interactive]
gh-account reauth USER [--scopes LIST] [--json]
gh-account onboard USER [REPO] [--scopes LIST]
gh-account insights [ANALYZER_OPTIONS]
gh-account bind USER [REPO]
gh-account use USER [REPO]
gh-account auto [REPO]
gh-account exec USER [--] GH_ARGUMENTS...
gh-account git-exec USER REPO -- {fetch|push|ls-remote} origin [GIT_ARGUMENTS...]
  • doctor is read-only and emits secret-free findings for humans or agents.
  • preflight proves the routed account identity and restores the prior account afterward.
  • repair applies deterministic Git configuration fixes; --interactive may trigger a reauth.
  • reauth/onboard use native GitHub CLI browser/device authorization explicitly — this tool never handles credentials directly.
  • exec temporarily switches under a per-user lock, runs gh, and verifies restore before returning.
  • git-exec does the same for an HTTPS origin Git transport operation (fetch/push/ls-remote).

Typical agent-facing pattern

# Read-only, safe to run unattended for diagnosis:
gh-account doctor --json

# Route a specific mutating action through the right identity, with a
# guaranteed restore of whatever was active before:
gh-account exec work-account -- pr create --title "..." --body-file notes.md

Audit trail

Mutating commands append structured JSONL events to ~/.local/state/gh-account/events.jsonl by default (rotated automatically past 5 MiB). Run gh-account insights for a pattern-matched summary of recent events; gh-account insights --json for machine-readable output.

If you keep a broader personal audit log (e.g. ~/.ai-audit), set AIAUDIT_HOME to point insights at that root instead of the bundled analyzer's own event spool.

Security model

  • Distrusts inherited environment for anything security-relevant: XDG_CONFIG_HOME/GH_CONFIG_DIR overrides are detected and reported, but never trusted for the actual config path used.
  • Every filesystem location it writes to is validated end-to-end from $HOME down — ownership, symlink status, permission bits, ACLs — before use, not just at creation time.
  • list, current, doctor, and insights are the only commands that don't require a fully validated GitHub CLI context; everything else fails closed on an unsafe posture (EXIT_CONFIG, EXIT_NOPERM) before touching any account state.

Running the test suite

tests/run.sh

Requires bash, jq; shellcheck is used opportunistically if installed. Every test runs against an isolated HOME with faked gh/git/system binaries — nothing touches your real GitHub accounts or Git config.

License

MIT — see LICENSE.

About

Fail-closed multi-account GitHub CLI router - built for anyone (human or AI agent) juggling multiple GitHub identities on one machine.

Resources

Readme
MIT license
Activity
Custom properties

Stars

0 stars

Watchers

0 watching

Forks

0 forks
Report repository

Releases

Packages

Contributors

Languages

You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.