No account switching
The shim never invokes gh auth switch. Your active account remains untouched.
Identity routing for the GitHub CLI
Route each gh command through the account that belongs to this repository—without changing global auth or colliding with another agent.
Process-scopedOne token. One command.
Context-awareRemote, owner, host, or path.
Agent-safeNo shared switch to race.
01 / The handoff
The shim reads context, asks your existing gh installation for the selected token, and exposes it to one child process only.
Inspect origin, its host and owner, plus the absolute working directory.
Evaluate your TOML top to bottom. Every field in the first winning rule must match.
Retrieve the token from gh and pass it only to the requested command.
02 / Explain first
which never retrieves a token. It shows the exact input and winning rule, in plain text or JSON.
03 / Tiny surface
# First complete match wins.
version = 1
[[rules]]
name = "Acme work"
account = "dev@acme.example"
host = "github.com"
owner = "^acme-corp$"
[[rules]]
name = "Personal"
account = "octocat"
directory = "~/src/personal/**"
hostownerremotedirectory~, *, and **.04 / Get routed
Requires Go 1.22+ and an existing authenticated GitHub CLI. Generate your starter rules, review them, then keep working as usual.
Read the complete CLI referencego install github.com/B-Divyesh/sf-gh-account-autoswitch/cmd/gh-account-autoswitch@latest
gh-account-autoswitch init
Safety, by construction
The shim never invokes gh auth switch. Your active account remains untouched.
Tokens stay in the existing gh credential store and one child environment.
No matching rule is exit code 3, not permission to use whatever account happens to be active.
Open source · MIT