⚡ Sangsakala Proxy 🏠 Home
Skip to content

feat(gh auth login): hint at --expiring when no preference is set - #14798

Merged
babakks merged 1 commit into
trunkfrom
babakks/polish-auth-login-expiring-ux
Oct 23, 2026
Merged

babakks merged 1 commit into
trunkfrom
babakks/polish-auth-login-expiring-ux

Conversation

@babakks

@babakks babakks commented Oct 23, 2026

Copy link
Copy Markdown
Member

Description

gh auth login supports requesting expiring, auto-refreshing OAuth tokens with --expiring (or the expiring_credentials config), but it is strictly opt-in, so users who have not read the changelog have no way of discovering it from the login flow itself.

This adds a one-line hint to the login output pointing at the flag and the changelog post:

! Did you know that expiring tokens can be requested with --expiring? Read more at https://gh.io/gh-expiring-tokens

The hint is printed on stderr only when all of the following hold:

  • stderr is a TTY, so scripts and non-interactive callers see no change in output.
  • --expiring was not passed (including --expiring=false, which is an explicit choice) and expiring_credentials is not enabled for the host.
  • The host is not GitHub Enterprise Server, which may not support expiring tokens.
  • The login is not a --with-token or environment-variable login; both of those paths return before the hint.

How did you test this change?

I built gh from this branch and ran gh auth login in a terminal against github.com, a *.ghe.com host, and an unknown (Enterprise Server style) host, each with the expiring_credentials config both enabled and unset, and with and without the --expiring / --expiring=false flags. I saw:

Scenario Hint shown
github.com or *.ghe.com, no flag, config unset Yes
github.com or *.ghe.com, no flag, config enabled No
github.com or *.ghe.com, --expiring No
github.com or *.ghe.com, --expiring=false No
Unknown host, any flag or config combination No

Key points

  • It is a hint rather than a prompt, so it does not add a step to the login flow.
  • It is shown on every qualifying login rather than once per user. gh auth login is run rarely per user, so tracking whether the hint was already shown in the state directory is not worth the extra state.
  • For interactive logins without --hostname, the hint appears after the host selection prompt, because it needs the hostname to skip Enterprise Server hosts and to read the per-host config. With --hostname or --web it is the first line of output.

Notes for reviewers

The change is the block right before shared.Login in pkg/cmd/auth/login/login.go; the test is Test_loginRun_expiringHint in login_test.go.

Authorship and follow-up

Who wrote this:

  • A human wrote it.
  • An agent wrote it under close human direction.
  • An agent wrote it independently, and no human has guided the implementation beyond the initial prompt.

Who answers review comments:

  • @babakks will read and reply directly.
  • An agent will draft replies and @babakks will read them before they are posted.
  • Nobody has explicitly committed to replying.

Print a one line hint on stderr pointing users to --expiring and the
changelog post (https://gh.io/gh-expiring-tokens). The hint only shows
when stderr is a TTY, neither --expiring nor expiring_credentials is
set, and the host is not GitHub Enterprise Server.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Copilot-Session: ac178b5a-5b62-49bd-9e83-4796c7ddec46
@babakks
babakks requested a review from a team as a code owner October 23, 2026 15:09
@babakks
babakks requested review from BagToad and a balanced review from Copilot October 23, 2026 15:09
@babakks
babakks requested a review from williammartin October 23, 2026 15:10

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The hint can appear during non-interactive logins when stderr remains attached to a terminal, violating the stated output compatibility guarantee.

1 open issue
What changed in this PR

This PR makes expiring OAuth credentials easier to discover by adding a --expiring hint to the existing authentication flow.

Changes:

  • Adds a stderr hint with a link to more information.
  • Suppresses the hint for explicit flag choices, enabled configuration, and Enterprise Server hosts.
  • Adds table-driven tests for hint visibility.

Contribution eligibility remains unverified and needs clarification from @cli/code-reviewers.

File Description
pkg/​cmd/​auth/​login/​login.go Adds the conditional expiring-token hint before login.
pkg/​cmd/​auth/​login/​login_test.go Tests visibility based on terminal state, preference, and host.

Review effort: Balanced

Comment thread pkg/cmd/auth/login/login.go Resolved
@babakks
babakks merged commit 64d1752 into trunk Oct 23, 2026
19 checks passed
@babakks
babakks deleted the babakks/polish-auth-login-expiring-ux branch October 23, 2026 16:00

@dl909-A dl909-A left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Y not

@dl909-A dl909-A left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Evidence

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants