Skip to content

Codebase intelligence for AI and humans: code health scores, auto-generated docs, git analytics, dead code detection, and architectural decisions via MCP.

feat(init): default the provider picker to the agent you use (#3171)

Raghav Chamadiya52c47995300b
diff --git a/docs/agent/CLAUDE_CODE_PROVIDER.md b/docs/agent/CLAUDE_CODE_PROVIDER.md
index 76a3712d2..640e2bb96 100644
--- a/docs/agent/CLAUDE_CODE_PROVIDER.md
+++ b/docs/agent/CLAUDE_CODE_PROVIDER.md
@@ -34,7 +34,7 @@ model: claude_cli/claude-haiku-5-5
```bash
# Install Claude Code, then authenticate once:
-claude login
+claude auth login
```
Any plan that can run `claude -p` works — Pro, Max, Team or Enterprise. Repowise
diff --git a/packages/cli/src/repowise/cli/commands/init_cmd/command.py b/packages/cli/src/repowise/cli/commands/init_cmd/command.py
index de19b1e64..ea2f0dcdb 100644
--- a/packages/cli/src/repowise/cli/commands/init_cmd/command.py
+++ b/packages/cli/src/repowise/cli/commands/init_cmd/command.py
@@ -61,6 +61,7 @@ from repowise.cli.ui import (
WARN,
MaybeCountColumn,
RichProgressCallback,
+ agent_providers_set_up,
interactive_advanced_config,
interactive_customize_offer,
interactive_fast_mode_offer,
@@ -1180,6 +1181,7 @@ def init_command(
reasoning,
repo_path=repo_path,
save_key=save_key,
+ prefer=agent_providers_set_up(repo_path),
)
provider_name = selection.provider_name
model = selection.model
diff --git a/packages/cli/src/repowise/cli/ui/__init__.py b/packages/cli/src/repowise/cli/ui/__init__.py
index c71638c2a..4def08d69 100644
--- a/packages/cli/src/repowise/cli/ui/__init__.py
+++ b/packages/cli/src/repowise/cli/ui/__init__.py
@@ -37,6 +37,7 @@ _LAZY: dict[str, str] = {
"ProviderSelection": "provider_selection",
"RepoScanInfo": "repo_scanner",
"RichProgressCallback": "progress",
+ "agent_providers_set_up": "provider_selection",
"banner_text": "mascot",
"build_completion_panel": "result_panels",
"build_contextual_next_steps": "result_panels",
diff --git a/packages/cli/src/repowise/cli/ui/provider_selection.py b/packages/cli/src/repowise/cli/ui/provider_selection.py
index bf63f1979..c42b359f6 100644
--- a/packages/cli/src/repowise/cli/ui/provider_selection.py
+++ b/packages/cli/src/repowise/cli/ui/provider_selection.py
@@ -28,7 +28,7 @@ from repowise.cli.ui.openai_compatible import (
from repowise.cli.ui.openai_compatible import (
prompt_setup as _prompt_openai_compatible_setup_values,
)
-from repowise.core.agents.identity import identity_for_provider
+from repowise.core.agents.identity import get_identity, identity_for_provider
from repowise.core.providers.llm.base import ProviderModelOption
from repowise.core.providers.llm.specs import PROVIDER_SPECS, ProviderSpec
from repowise.core.reasoning import ReasoningMode, normalize_reasoning
@@ -89,6 +89,31 @@ def _agent_cli_status(name: str) -> tuple[bool, bool]:
return True, agent.is_logged_in()
+def agent_providers_set_up(repo_path: Path | None) -> tuple[str, ...]:
+ """Agent-CLI providers whose agent is set up as a target here, in picker order.
+
+ The picker defaults to the first of these whose CLI is ready. Empty when
+ config.yaml already names a provider, so a re-init keeps today's default.
+ """
+ from repowise.cli.agent_targets.registry import get_target
+ from repowise.cli.helpers import load_config
+
+ if repo_path is not None and load_config(repo_path).get("provider"):
+ return ()
+ names: list[str] = []
+ for name, spec in _PICKER_SPECS.items():
+ agent = get_identity(spec.agent) if spec.agent else None
+ target = get_target(agent.cli_target_id) if agent else None
+ if target is None:
+ continue
+ try:
+ if target.is_present(repo_path) or target.detect(repo_path):
+ names.append(name)
+ except Exception:
+ continue
+ return tuple(names)
+
+
def ollama_base_url() -> str:
"""Where the picker expects to find Ollama."""
return os.environ.get("OLLAMA_BASE_URL") or _OLLAMA_DEFAULT_BASE_URL
@@ -178,7 +203,8 @@ def _agent_cli_setup_lines(name: str) -> list[str]:
else f"{agent.display_name} CLI not found on PATH."
)
lines = [
- f" [bold]{name}[/bold] uses the {agent.display_name} CLI's own login. No API key here.",
+ # The spec note, so an agent with no login (opencode) is not said to use one.
+ f" [bold]{name}[/bold] {PROVIDER_SPECS[name].note}. No API key here.",
f" Install: [{BRAND}]{agent.install_hint}[/]",
f" Set up: [{BRAND}]{agent.login_hint}[/]",
]
@@ -233,10 +259,12 @@ def _interactive_provider_name(
*,
repo_path: Path | None = None,
save_key: bool = True,
+ prefer: tuple[str, ...] = (),
) -> str:
"""Show provider table, handle selection + inline key entry + save.
- Returns the chosen provider name.
+ The first ready provider in *prefer* (see :func:`agent_providers_set_up`)
+ becomes the default. Returns the chosen provider name.
"""
providers = list(_PROVIDER_CHOICES) # gemini first
detected = _detect_provider_status()
@@ -285,6 +313,17 @@ def _interactive_provider_name(
if prov in detected:
default_idx = str(idx)
break
+ # The CLI of the agent set up here outranks a key: it is the user's own login.
+ recommended = next((name for name in prefer if name in detected), None)
+ if recommended is not None:
+ default_idx = str(providers.index(recommended) + 1)
+ agent = identity_for_provider(recommended)
+ assert agent is not None, recommended
+ console.print(
+ f" [dim]Default: {recommended}. {agent.display_name} is set up here, "
+ f"so indexing {_PICKER_SPECS[recommended].note}.[/dim]"
+ )
+ console.print()
chosen_idx = Prompt.ask(
" Select provider",
@@ -319,6 +358,7 @@ def _interactive_provider_name(
model_flag,
repo_path=repo_path,
save_key=save_key,
+ prefer=prefer,
)
env_var = _PROVIDER_ENV[chosen]
signup_url = _PICKER_SPECS[chosen].signup_url
@@ -341,6 +381,7 @@ def _interactive_provider_name(
model_flag,
repo_path=repo_path,
save_key=save_key,
+ prefer=prefer,
)
if chosen == "openai" and repo_path is not None:
@@ -590,6 +631,7 @@ def interactive_provider_config_select(
*,
repo_path: Path | None = None,
save_key: bool = True,
+ prefer: tuple[str, ...] = (),
) -> ProviderSelection:
"""Show provider/model/reasoning selection for interactive init.
@@ -601,6 +643,7 @@ def interactive_provider_config_select(
model_flag,
repo_path=repo_path,
save_key=save_key,
+ prefer=prefer,
)
if chosen == _OPENAI_COMPATIBLE_CHOICE:
return _interactive_openai_compatible_select(
diff --git a/packages/core/src/repowise/core/agents/identity.py b/packages/core/src/repowise/core/agents/identity.py
index fc3fd90ec..082c43a38 100644
--- a/packages/core/src/repowise/core/agents/identity.py
+++ b/packages/core/src/repowise/core/agents/identity.py
@@ -158,8 +158,13 @@ class AgentIdentity:
if not self.login_check:
return True
try:
+ # DEVNULL: an inherited Windows console stdin can block until the timeout.
result = subprocess.run(
- [command, *self.login_check], capture_output=True, text=True, timeout=10
+ [command, *self.login_check],
+ stdin=subprocess.DEVNULL,
+ capture_output=True,
+ text=True,
+ timeout=10,
)
except (OSError, subprocess.TimeoutExpired):
return False
@@ -174,8 +179,10 @@ CLAUDE_CODE = AgentIdentity(
hook_adapter="claude-code",
session_adapter="claude_code",
executable="claude",
+ #: Documented to exit 0 when signed in and 1 when not.
+ login_check=("auth", "status"),
install_hint="https://claude.com/claude-code",
- login_hint="claude login",
+ login_hint="claude auth login",
indexing_provider="claude_cli",
)
CODEX = AgentIdentity(
diff --git a/packages/core/src/repowise/core/providers/llm/claude_cli.py b/packages/core/src/repowise/core/providers/llm/claude_cli.py
index 2fb757e57..f98a61bad 100644
--- a/packages/core/src/repowise/core/providers/llm/claude_cli.py
+++ b/packages/core/src/repowise/core/providers/llm/claude_cli.py
@@ -2,7 +2,7 @@
Delegates generation to the authenticated local Claude Code CLI via ``claude -p``
(headless / print mode). Intended for users whose Claude subscription (Pro, Max,
-Team or Enterprise seat) is already configured by ``claude login``; it needs no
+Team or Enterprise seat) is already configured by ``claude auth login``; it needs no
ANTHROPIC_API_KEY. Shared subprocess handling lives in ``agent_cli``.
Two deliberate differences from the other agent-CLI providers:
diff --git a/tests/unit/agents/test_identity.py b/tests/unit/agents/test_identity.py
index fea2038c8..ca7c9689b 100644
--- a/tests/unit/agents/test_identity.py
+++ b/tests/unit/agents/test_identity.py
@@ -288,15 +288,17 @@ def test_login_runs_the_declared_check_and_reads_the_exit_code(monkeypatch) -> N
monkeypatch.setattr(shutil, "which", lambda name: name)
calls: list[list[str]] = []
- def fake_run(args: list[str], **_kwargs: object) -> subprocess.CompletedProcess[str]:
+ def fake_run(args: list[str], **kwargs: object) -> subprocess.CompletedProcess[str]:
calls.append(args)
+ assert kwargs["stdin"] is subprocess.DEVNULL
return subprocess.CompletedProcess(args, 1, stdout="Logged in", stderr="")
monkeypatch.setattr(subprocess, "run", fake_run)
assert not identity.CODEX.is_logged_in()
- assert calls == [["codex", "login", "status"]]
+ assert not identity.CLAUDE_CODE.is_logged_in()
+ assert calls == [["codex", "login", "status"], ["claude", "auth", "status"]]
# No cheap login query: installed is the most this can say.
- assert identity.CLAUDE_CODE.is_logged_in()
+ assert identity.OPENCODE.is_logged_in()
def test_identity_for_provider_follows_the_indexing_link() -> None:
diff --git a/tests/unit/cli/test_init_agent_backend.py b/tests/unit/cli/test_init_agent_backend.py
new file mode 100644
index 000000000..c4d1fd980
--- /dev/null
+++ b/tests/unit/cli/test_init_agent_backend.py
@@ -0,0 +1,133 @@
+"""Init's provider picker defaults to the CLI of the agent set up in the repo."""
+
+from __future__ import annotations
+
+import io
+from pathlib import Path
+from typing import Any
+
+import pytest
+from rich.console import Console
+
+from repowise.cli.agent_targets import registry
+from repowise.cli.commands.init_cmd.command import _interactive_gate
+from repowise.cli.ui import provider_selection as ui
+from repowise.core.agents.identity import identity_for_target_id
+
+
+class _Target:
+ def __init__(self, present: bool) -> None:
+ self.present = present
+
+ def is_present(self, repo_path: Path | None = None) -> bool:
+ return self.present
+
+ def detect(self, repo_path: Path | None = None) -> list[Any]:
+ return []
+
+
+def _set_up(monkeypatch: Any, *target_ids: str) -> None:
+ monkeypatch.setattr(
+ registry, "get_target", lambda target_id: _Target(target_id in target_ids)
+ )
+
+
+def _default_pick(
+ monkeypatch: Any, detected: dict[str, str], prefer: tuple[str, ...]
+) -> tuple[str, str]:
+ """The provider the picker offers as its default, and what it printed."""
+ monkeypatch.setattr(ui, "_detect_provider_status", lambda: detected)
+ seen: dict[str, str] = {}
+
+ def ask(*_a: object, default: str, **_k: object) -> str:
+ seen["default"] = default
+ return default
+
+ monkeypatch.setattr(ui.Prompt, "ask", ask)
+ buf = io.StringIO()
+ ui._interactive_provider_name(Console(file=buf, width=120), None, prefer=prefer)
+ return ui._PROVIDER_CHOICES[int(seen["default"]) - 1], buf.getvalue()
+
+
+def test_agent_set_up_here_lists_its_provider(tmp_path: Path, monkeypatch: Any) -> None:
+ _set_up(monkeypatch, "claude-code")
+ assert ui.agent_providers_set_up(tmp_path) == ("claude_cli",)
+
+
+def test_agent_without_indexing_provider_lists_nothing(tmp_path: Path, monkeypatch: Any) -> None:
+ identity = identity_for_target_id("cursor")
+ assert identity is not None and identity.indexing_provider is None
+ _set_up(monkeypatch, "cursor")
+ assert ui.agent_providers_set_up(tmp_path) == ()
+
+
+def test_configured_provider_suppresses_the_preference(tmp_path: Path, monkeypatch: Any) -> None:
+ _set_up(monkeypatch, "claude-code")
+ (tmp_path / ".repowise").mkdir()
+ (tmp_path / ".repowise" / "config.yaml").write_text("provider: gemini\n", encoding="utf-8")
+ assert ui.agent_providers_set_up(tmp_path) == ()
+
+
+def test_ready_agent_cli_beats_a_key_as_default(monkeypatch: Any) -> None:
+ detected = {"openai": "OPENAI_API_KEY", "claude_cli": "agent CLI"}
+ chosen, out = _default_pick(monkeypatch, detected, ("claude_cli",))
+ assert chosen == "claude_cli"
+ assert "uses your Claude Code login" in out.split("Provider Setup")[1].split("mock is")[1]
+
+
+def test_agent_cli_not_ready_leaves_default_alone(monkeypatch: Any) -> None:
+ detected = {"openai": "OPENAI_API_KEY"}
+ assert _default_pick(monkeypatch, detected, ("claude_cli",))[0] == "openai"
+
+
+def test_no_preference_keeps_first_ready_default(monkeypatch: Any) -> None:
+ detected = {"openai": "OPENAI_API_KEY", "claude_cli": "agent CLI"}
+ assert _default_pick(monkeypatch, detected, ())[0] == "openai"
+
+
[email protected]("provider_name", ["claude_cli", "gemini"])
+def test_explicit_provider_skips_the_picker(provider_name: str) -> None:
+ assert not _interactive_gate(
+ isatty=True, provider_name=provider_name, index_only=False, yes=False, resume=False
+ )
+
+
+def test_signed_out_claude_is_not_the_default(monkeypatch: Any) -> None:
+ import shutil
+ import subprocess
+
+ monkeypatch.setattr(shutil, "which", lambda name: name if name == "claude" else None)
+ monkeypatch.setattr(
+ subprocess, "run", lambda args, **_k: subprocess.CompletedProcess(args, 1, "", "")
+ )
+ monkeypatch.setattr(ui, "_detect_ollama_status", lambda: False)
+ monkeypatch.setenv("OPENAI_API_KEY", "sk-test")
+ monkeypatch.delenv("OPENAI_BASE_URL", raising=False)
+ detected = ui._detect_provider_status()
+ assert "claude_cli" not in detected
+ chosen, out = _default_pick(monkeypatch, detected, ("claude_cli",))
+ assert chosen != "claude_cli"
+ assert "Default:" not in out
+
+
+def test_opencode_reason_does_not_claim_a_login(monkeypatch: Any) -> None:
+ chosen, out = _default_pick(monkeypatch, {"opencode": "agent CLI"}, ("opencode",))
+ reason = out.split("mock is")[1]
+ assert chosen == "opencode"
+ assert "uses your opencode CLI setup" in reason
+ assert "login" not in reason
+
+
+def test_setup_text_for_a_missing_opencode_claims_no_login(monkeypatch: Any) -> None:
+ monkeypatch.setattr(ui, "_agent_cli_status", lambda _name: (False, False))
+ text = " ".join(ui._agent_cli_setup_lines("opencode"))
+ assert "uses your opencode CLI setup" in text
+ assert "login" not in text
+
+
+def test_setup_text_for_claude_names_the_auth_login(monkeypatch: Any) -> None:
+ monkeypatch.setattr(ui, "_agent_cli_status", lambda _name: (True, False))
+ text = " ".join(ui._agent_cli_setup_lines("claude_cli"))
+ assert "uses your Claude Code login" in text
+ assert "claude auth login" in text
+ assert "not logged in" in text
diff --git a/website/claude-cli.md b/website/claude-cli.md
index 753756da6..08754286e 100644
--- a/website/claude-cli.md
+++ b/website/claude-cli.md
@@ -24,7 +24,7 @@ Use Repowise with your Claude subscription via the `claude_cli` LLM provider. No
```bash
# 1. Install Claude Code, then authenticate once
-claude login
+claude auth login
# 2. Point Repowise at it
repowise init --provider claude_cli --yes
@@ -126,9 +126,9 @@ Otherwise the index keeps `embedder: mock` and search stays lexical.
**`Claude Code CLI not found`** — `claude` is not on `PATH`. Install it from
[claude.com/claude-code](https://claude.com/claude-code).
-**Authentication errors on the first page** — run `claude login`. Readiness
-detection stops at "is it installed", because the CLI keeps credentials in a
-keychain or OAuth store with no cheap way to probe login state.
+**Authentication errors on the first page** — run `claude auth login`, then
+check with `claude auth status`, which exits 0 when you are signed in. That is
+the check `repowise init` uses to show the provider as ready.
**Rate-limit failures partway through a run** — lower
`REPOWISE_CLAUDE_CLI_CONCURRENCY`, or scope the run with `--path`. Completed