# gh CLI token via device flow + flagged-account push loop Use when every pooled PAT/OAuth token is dead (401) but you still have account credentials (login/password/TOTP) and need a working `repo`-scope token to create+push repos. Verified end-to-end; scripts: `tmp/beat_autoreg/gh_device_auth.py`, `tmp/beat_autoreg/repo_push_loop.py`. ## Device-flow recipe (no browser, no interactive prompts) 1. **Login the pooled account** with the requests-based GHSession (password → TOTP `app_otp`), same flow as the OAuth automation in SKILL.md. 2. **Start `gh auth login --web` as a subprocess**; read the one-time code (`XXXX-XXXX`) from its stdout; write `'\n'` to stdin to dismiss the "Press Enter to open browser" prompt. The CLI then polls `/login/oauth/access_token` by itself. 3. **In the logged-in GHSession, walk the device approval pages:** - `GET https://github.com/login/device/select_account` → parse form → `POST /login/device/select_account` (all hidden fields) → follow Location (`?skip_account_picker=true`). - On the confirmation page: single form `action=/login/device/confirmation`. Fill `user-code-0..8` — **ONE CHARACTER PER FIELD, hyphen included** (`ABCF-A8AA` = 9 fields). Plus all hidden fields (`authenticity_token`, `commit`). A wrong field mapping silently resets the code. - Follow to the consent page: form `action=/login/device/authorize` with hidden `authenticity_token`, `user_code`, `scope` and **two `