# accounts-and-token-switching

Use several GitHub accounts from one machine safely: per-command tokens via `gh auth token -u <user>` passed through env (GH_TOKEN or a git credential helper), never `gh auth switch`, never tokens in argv or remote URLs.

- **Space:** github-ops-public (https://github.com/Tech-Realm/space-github-ops-public/tree/main/accounts-and-token-switching)
- **Level:** L1 (as the registry reports it)
- **Keys it needs (names only):** GITHUB_TOKEN
- **Tools:** gh, git, bash
- **Routes:** gh-cli; checks: 3
- **Uses:** new (no recorded use yet)
- **Install:** `logicpacks pack use github-ops-public/accounts-and-token-switching` or MCP `get_pack github-ops-public/accounts-and-token-switching`
- **Files:** CHANGELOG.md, code/gh_as.sh, code/git_push_as.sh, outcome/EVIDENCE.md, outcome/checks.yaml, outcome/results.json, pack.yaml, spec/SPEC.md, spec/source.md

## Purpose (spec/SPEC.md)

Use several GitHub accounts from one machine safely: per-command tokens via `gh auth token -u <user>` passed through env (GH_TOKEN or a git credential helper), never `gh auth switch`, never tokens in argv or remote URLs.

## Goal

Any agent can act as the right account for one command without changing global state other agents depend on.

## Steps

1. See who is logged in: `gh auth status` (several accounts can sit in the keyring).
2. Run one gh command as a user: `bash code/gh_as.sh <user> gh repo list <owner> --limit 5` (sets GH_TOKEN in the child env only).
3. Push as a user: `bash code/git_push_as.sh <user> origin main` (token reaches git through a credential helper reading an env var).
4. Use the account that owns/has admin on the target org (check `gh api orgs/<org>/memberships/<user>`).
5. For tokens stored in the LogicPacks vault: `lp run -- gh ...` with GITHUB_TOKEN as a sealed placeholder.

## Edge cases

- `gh auth switch` changes global state: parallel agents race and push as the wrong user.
- A token in a remote URL (`https://x-access-token:TOKEN@github.com/...`) lands in shell history, process lists and .git/config.
- Different accounts have different scopes (some lack delete_repo); check `gh auth status` scopes before destructive calls.
- GraphQL as the owner shows private counts; use another account's token to see what the public sees.

## Don'ts

- Don't run `gh auth switch` in shared sessions.
- Don't paste tokens into chat or files; if one leaks, Waleed decides rotation.
- Don't write tokens into remote URLs or argv.



---

Canonical URL: https://logicpacks.io/packs/github-ops-public/accounts-and-token-switching

Developed by TechRealm (techrealm.online), the software team. Operated by Al Jash Trading (Establishment), Abu Dhabi, since 1994, the legal entity that hosts and is responsible for the service. Economic licence CN-1030597, Abu Dhabi Registration Authority. Address: Office 5, Bani Yas West 4, Bani Yas, Abu Dhabi, UAE. Website: https://aljashtrading.com. Contact: hello@logicpacks.io, security@logicpacks.io, WhatsApp +1 713 632 2262 (https://wa.me/17136322262).

Machine-readable index: [/llms.txt](/llms.txt). Plain facts: [/about.md](/about.md). Safety: [/safety.md](/safety.md).
