Repository navigation
hai login --key skips when a key is stored - #232
Merged
Merged
Conversation
adeprezh
approved these changes
Oct 5, 2026
abonneth
approved these changes
Oct 5, 2026
abonneth
left a comment
Collaborator
There was a problem hiding this comment.
LGTM, nice small unblock.
Two non-blocking nits:
- With a key already stored,
echo $KEY | hai login --keyis now silently skipped. Piping a key reads like "replace it", so maybe only skip when stdin is a TTY? - A revoked stored key skips login, then
hai runfails with a bare 401. Ahai login --forcehint on 401 would help.
Heads-up for the email snippets: the Python one fails even after hai login. Client() only reads HAI_API_KEY from the env, never ~/.config/hai/.env:
$ HOME=$T python -c 'from hai_agents import Client; Client()' # key stored in $T/.config/hai/.env
ApiError: The client must be instantiated be either passing in api_key or setting HAI_API_KEY
client.py is hand-written, so a fallback to the stored key is a small fix.
Idea for later: when no key is found in an interactive terminal, any command could run the login prompt itself. Then the snippets don't need a hai login line at all.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose
Temporary unblock for the onboarding emails while the
hai loginredesign is debated (hcompai/portal-h#865, Laura's review: https://github.com/hcompai/portal-h/pull/865#pullrequestreview-5393415333, and #229). Until every account can sign in through the browser, the marketing email snippets will start withhai login --keyinstead ofhai login, so they must be safe to paste more than once.Why
Today
hai login --keyalways prompts, even when a key is already stored, because the--keybranch runs before the "already signed in" check. A developer pasting a second snippet would be asked for a key again. Plainhai loginalready skips in that case.What changes
hai login --keychecks for a stored key first. With one present it prints "Already signed in. Pass --force to rotate the key." and exits 0, like plainhai login.--key --forcereplaces it.API key (create one at https://platform.hcompany.ai/settings/api-keys):, so the emails need no "create your key" preamble.Nine lines in
hai_agents_cli/app.pyplus tests. CLI package only, nothing generated. Independent of the login PRs; once they ship, the snippets drop--keyand this behaviour stays correct.Note
Low Risk
CLI-only login UX change; stored-key skip and validation behavior for new keys are unchanged aside from ordering and messaging.
Overview
hai login --keynow matches plainhai loginwhen credentials already exist: it exits successfully with “Already signed in. Pass --force to rotate the key.” instead of prompting again.--key --forcestill accepts a new key, validates it, and overwrites the stored value.The hidden paste prompt now tells users where to create a key (
API key (create one at …)), so onboarding snippets can omit extra setup text.Tests cover the no-op path (no validation when already signed in),
--forcereplacement, and adjusted validation tests so they run without a pre-stored key.Reviewed by Cursor Bugbot for commit 60b6371. Bugbot is set up for automated code reviews on this repo. Configure here.