Skill v1.0.1
currentAutomated scan100/100~2 modified
name: "gh-auth-isolation" description: "Safely manage multiple GitHub identities (EMU + personal) in agent workflows" domain: "security, github-integration, authentication, multi-account" confidence: "high" source: "earned (production usage across 50+ sessions with EMU corp + personal GitHub accounts)" tools:
- name: "gh"
description: "GitHub CLI for authenticated operations" when: "When accessing GitHub resources requiring authentication" metadata: version: "1.0.1"
Context
Many developers use GitHub through an Enterprise Managed User (EMU) account at work while maintaining a personal GitHub account for open-source contributions. AI agents spawned by Squad inherit the shell's default gh authentication — which is usually the EMU account. This causes failures when agents try to push to personal repos, create PRs on forks, or interact with resources outside the enterprise org.
This skill teaches agents how to detect the active identity, switch contexts safely, and avoid mixing credentials across operations.
Patterns
Detect Current Identity
Before any GitHub operation, check which account is active:
gh auth status
Look for:
Logged in to github.com as USERNAME— the active accountToken scopes: ...— what permissions are available- Multiple accounts will show separate entries
Extract a Specific Account's Token
When you need to operate as a specific user (not the default):
# Get the personal account token (by username)gh auth token --user personaluser# Get the EMU account tokengh auth token --user corpalias_enterprise
Use case: Push to a personal fork while the default gh auth is the EMU account.
Push to Personal Repos from EMU Shell
The most common scenario: your shell defaults to the EMU account, but you need to push to a personal GitHub repo.
# Push as the personal account for this one command: gh's credential helper hands git the# token from GH_TOKEN, so it never appears in a URL, a remote or the command lineGH_TOKEN="$(gh auth token --user personaluser)" \git -c credential.helper= -c 'credential.helper=!gh auth git-credential' \push https://github.com/personaluser/repo.git branch-name
Why this works: gh auth token --user reads from gh's credential store without switching the active account. The token lives only in that one command's environment: credential.helper= clears the stored (EMU) helper for this command, and gh auth git-credential answers git's credential request with GH_TOKEN. Never put a token in a git URL: it shows up in shell history, process listings, tool logs and .git/config.
Create PRs on Personal Forks
When the default gh context is EMU but you need to create a PR from a personal fork:
# Option 1: Use --repo flag (works if token has access)gh pr create --repo upstream/repo --head personaluser:branch --title "..." --body "..."# Option 2: Temporarily set GH_TOKEN for one command$env:GH_TOKEN = $(gh auth token --user personaluser)gh pr create --repo upstream/repo --head personaluser:branch --title "..."Remove-Item Env:\GH_TOKEN
Config Directory Isolation (Advanced)
For complete isolation between accounts, use separate gh config directories:
# Personal account operations$env:GH_CONFIG_DIR = "$HOME/.config/gh-public"gh auth login # Login with personal account (one-time setup)gh repo clone personaluser/repo# EMU account operations (default)Remove-Item Env:\GH_CONFIG_DIRgh auth status # Back to EMU account
Setup (one-time):
# Create isolated config for personal accountmkdir ~/.config/gh-public$env:GH_CONFIG_DIR = "$HOME/.config/gh-public"gh auth login --web --git-protocol https
Shell Aliases for Quick Switching
Add to your shell profile for convenience:
# PowerShell profilefunction ghp { $env:GH_CONFIG_DIR = "$HOME/.config/gh-public"; gh @args; Remove-Item Env:\GH_CONFIG_DIR }function ghe { gh @args } # Default EMU# Usage:# ghp repo clone personaluser/repo # Uses personal account# ghe issue list # Uses EMU account
# Bash/Zsh profilealias ghp='GH_CONFIG_DIR=~/.config/gh-public gh'alias ghe='gh'# Usage:# ghp repo clone personaluser/repo# ghe issue list
Examples
✓ Correct: Agent pushes blog post to personal GitHub Pages
# Agent needs to push to personaluser.github.io (personal repo)# Default gh auth is corpalias_enterprise (EMU)$env:GH_TOKEN = gh auth token --user personalusergit -c credential.helper= -c 'credential.helper=!gh auth git-credential' push origin mainRemove-Item Env:GH_TOKEN # the token never touches the remote URL
✓ Correct: Agent creates a PR from personal fork to upstream
# Fork: personaluser/squad, Upstream: github/squad# Agent is on branch contrib/fix-docs in the fork clonegit push origin contrib/fix-docs # Pushes to fork (may need token auth)# Create PR targeting upstreamgh pr create --repo github/squad --head personaluser:contrib/fix-docs `--title "docs: fix installation guide" `--body "Fixes #123"
✗ Incorrect: Blindly pushing with wrong account
# BAD: Agent assumes default gh auth works for personal reposgit push origin main# ERROR: Permission denied — EMU account has no access to personal repo# BAD: Hardcoding tokens in scriptsgit push https://personaluser:ghp_xxxxxxxxxxxx@github.com/personaluser/repo.git main# SECURITY RISK: Token exposed in command history and process list
✓ Correct: Check before you push
# Always verify which account has access before operationsgh auth status# If wrong account, hand git the personal token for this one push:GH_TOKEN="$(gh auth token --user personaluser)" \git -c credential.helper= -c 'credential.helper=!gh auth git-credential' \push https://github.com/personaluser/repo.git main
Anti-Patterns
- ❌ Hardcoding tokens in scripts, environment variables, or committed files. Use
gh auth token --userto extract at runtime. - ❌ Assuming the default `gh` auth works for all repos. EMU accounts can't access personal repos and vice versa.
- ❌ Switching `gh auth login` globally mid-session. This changes the default for ALL processes and can break parallel agents.
- ❌ Storing personal tokens in `.env` or
.squad/files. These get committed by Scribe. Usegh's credential store. - ❌ Ignoring token cleanup after inline HTTPS pushes. Always reset the remote URL to avoid persisting tokens.
- ❌ Using `gh auth switch` in multi-agent sessions. One agent switching affects all others sharing the shell.
- ❌ Mixing EMU and personal operations in the same git clone. Use separate clones or explicit remote URLs per operation.