Skip to content

dcd login: reuse the last selected org instead of always asking #241

Closed

Description

@riglar

Problem

dcd login always shows the org picker when the user belongs to more than one org, even when they are signing in again to the org they used last time. That is the common case: access tokens last about an hour, so people re-run dcd login often.

The picker also needs a keypress. Where nobody can answer it, the login never completes:

  • a shell an AI agent runs (for example a Claude Code ! command)
  • a script

The browser sign-in succeeds, but the CLI sits at "Pick an organization", and nothing is saved.

The config already records the last choice: current_org_id and current_org_name in ~/.dcd/config.json. It survives dcd logout too, which only clears session.

Proposal

  1. Default to the last org. If current_org_id from the existing config is one of the orgs /me/orgs returns, preselect it in the picker. Pressing Enter then confirms it.
  2. Don't prompt when nobody can answer. When stdin or stdout isn't a TTY, use the last org without prompting, and print one line saying which org was chosen. If there is no previous org, or it's no longer in the list, fail with a clear error, not a hang.
  3. Add --org <id|name> to dcd login, to pick an org without the prompt, for scripts and CI. Fail if the user isn't a member of it.

dcd switch-org stays the way to change org on purpose.

Where

  • src/commands/login.ts: the call to pickOrg(orgs, …) after the claim.
  • src/utils/orgs.ts: pickOrg, which auto-selects only when there is exactly one org.
  • readConfig() already provides current_org_id.

Acceptance

  • Re-login with a remembered org and a TTY: the picker opens with that org selected.
  • Re-login without a TTY: no prompt, the remembered org is used, and one line says so.
  • Without a TTY and with no remembered org (or it's gone): a clear error and a non-zero exit, not a hang.
  • dcd login --org <id|name> selects that org, or errors if the user isn't a member.
  • Unit tests for the selection rules.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions