Skip to content

Guard logged-out Claude CLI usage - #2070

Merged
steipete merged 4 commits into
steipete:mainfrom
BearHuddleston:fix/guard-logged-out-claude-cli-runtime
Jul 11, 2026
Merged

steipete merged 4 commits into
steipete:mainfrom
BearHuddleston:fix/guard-logged-out-claude-cli-runtime

Conversation

@BearHuddleston

Copy link
Copy Markdown
Contributor

Summary

  • reuse Claude's existing auth status --json preflight for CodexBar CLI runtime in both Auto and explicit CLI source modes
  • route planned Claude CLI steps through the base strategy's availability check instead of treating them as unconditionally available
  • add Linux regression coverage proving a logged-out CLI receives only the auth-status probe and never reaches the interactive usage fetch

Root cause

#1742 added a fail-closed auth preflight for native-app background Auto refreshes, but intentionally left CLI runtime unchanged. Two conditions kept the command-line path unguarded:

  1. ClaudeCLIFetchStrategy.isAvailable only preflighted app/background/Auto.
  2. ClaudePlannedFetchStrategy returned true for CLI-runtime planned CLI steps without calling the base strategy's availability check.

On Linux with Claude Code 2.1.207 logged out (loggedIn: false, authMethod: none), CodexBar 0.42.0 therefore started the interactive claude --allowed-tools session and waited through usage-probe retries instead of returning promptly.

This change fails closed when CLI runtime cannot prove Claude is logged in. Native-app explicit CLI selection and user-initiated app behavior remain unchanged. Older or wrapped Claude CLIs that do not support a usable auth status --json response will now be unavailable to CodexBar CLI runtime rather than launching an interactive process.

Validation

  • RED: swift test --filter PlatformGatingTests reached the interactive fetch override, recorded the CLI strategy available, and issued no auth-status command
  • GREEN: swift test --filter PlatformGatingTests — 9 tests passed, including Auto and explicit CLI logged-out cases
  • ./Scripts/lint.sh lint-linux — portable checks passed; SwiftLint found 0 violations in 1,374 files
  • swift test --parallel — 121 tests passed across 19 suites
  • swift build -c release --product CodexBarCLI --static-swift-stdlib
  • exact release-artifact smoke with a fake logged-out Claude whose interactive branch sleeps 60 seconds:
    • Auto exited in 15 ms
    • explicit CLI exited in 13 ms
    • invocation log contained only two auth status --json calls and no interactive probe marker
  • git diff --check

No UI changes; screenshots are not applicable.

@clawsweeper clawsweeper Bot added proof: sufficient Contributor real behavior proof is sufficient. rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR. P2 Normal priority bug or improvement with limited blast radius. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. labels Jul 11, 2026
@clawsweeper

clawsweeper Bot commented Jul 11, 2026 •

Copy link
Copy Markdown

Codex review: needs maintainer review before merge. Reviewed July 11, 2026, 5:16 PM ET / 21:16 UTC.

Summary
Extends Claude CLI authentication preflight to command-line Auto and explicit CLI usage, with regression coverage for logged-out and authenticated fixtures.

Reproducibility: yes. The owner reports a current-main black-box control where a logged-out fake Claude reached the interactive path and timed out, while the repaired release CLI exited promptly after only the authentication-status probe; source inspection matches both paths.

Review metrics: 3 noteworthy metrics.

  • Patch scope: 4 files, +100/-23. The production change is limited to one Claude availability path, two focused fixture files, and a maintainer-owned release note.
  • Runtime modes covered: 2 CLI source modes. The parameterized regression test exercises both Auto and explicit CLI runtime while logged out.
  • Post-review delta: 1 test file changed. The latest force-push only isolates a temporary Linux fixture and leaves previously reviewed production behavior unchanged.

Root-cause cluster
Relationship: canonical
Canonical: #2070
Summary: This PR is the canonical remaining fix for the CLI-runtime portion of the logged-out interactive Claude fallback; the earlier merged PR covers the same root cause in unattended app refreshes.

Members:

Proposal only: this assessment does not dispatch repair, suppress jobs, mutate sibling items, close, or merge anything.

Merge readiness
Overall: 🦞 diamond lobster
Proof: 🦞 diamond lobster
Patch quality: 🦞 diamond lobster
Result: ready for maintainer review.

Overall follows the weaker of proof and patch quality, so missing proof can cap an otherwise strong patch.

Risk before merge

  • [P1] Older or wrapped Claude CLI installations without a usable auth status --json response will become unavailable in CodexBar CLI runtime; the repository owner explicitly accepted this fail-closed compatibility change.
  • [P1] The required exact-head Linux builds and macOS test shards were still pending during review, so merge remains gated on their completion.

Maintainer options:

  1. Merge the approved fail-closed contract (recommended)
    Accept that unsupported or wrapped Claude CLIs will be unavailable in CLI runtime and merge after all exact-head checks pass.
  2. Revisit wrapper compatibility
    Pause only if maintainers want a distinct compatibility mode for wrappers that cannot return usable authentication-status JSON.

Next step before merge

  • [P2] No contributor repair remains; maintainers should let the required exact-head checks finish and then handle the merge normally.

Security
Cleared: The patch reuses a local authentication-status probe and adds fixtures without new dependencies, downloads, permissions, secret exposure, or supply-chain execution.

Review details

Best possible solution:

Retain the shared non-interactive authentication preflight for all Claude CLI runtime usage, with regression coverage proving logged-out rejection and authenticated success.

Do we have a high-confidence way to reproduce the issue?

Yes. The owner reports a current-main black-box control where a logged-out fake Claude reached the interactive path and timed out, while the repaired release CLI exited promptly after only the authentication-status probe; source inspection matches both paths.

Is this the best way to solve the issue?

Yes. Reusing ClaudeCLIAuthStatusProbe in the planned and base availability checks is the narrowest maintainable fix, and the repository owner has explicitly approved the fail-closed compatibility boundary.

AGENTS.md: found and applied where relevant.

Codex review notes: model internal, reasoning high; reviewed against 68c3c760e1ef.

Label changes

Label justifications:

  • P2: This is a bounded provider bug fix for logged-out CLI hangs with limited blast radius.
  • merge-risk: 🚨 compatibility: Mandatory authentication proof makes older or wrapped Claude CLIs without usable auth-status output unavailable in CLI runtime.
  • merge-risk: 🚨 auth-provider: The patch changes the authentication gate that determines whether Claude CLI usage may execute.
  • rating: 🦞 diamond lobster: Overall readiness is 🦞 diamond lobster; proof is 🦞 diamond lobster and patch quality is 🦞 diamond lobster.
  • status: 👀 ready for maintainer look: ClawSweeper has no concrete contributor-facing blocker left for this PR. Sufficient (logs): The PR provides after-fix release-CLI timings, invocation logs showing only auth status --json, a real authenticated CLI probe, and a current-main timeout control that directly demonstrate the changed behavior.
  • proof: sufficient: Contributor real behavior proof is sufficient. The PR provides after-fix release-CLI timings, invocation logs showing only auth status --json, a real authenticated CLI probe, and a current-main timeout control that directly demonstrate the changed behavior.
Evidence reviewed

What I checked:

Likely related people:

  • steipete: Authored the merged fallback guard, repaired the branch fixtures and release note, and explicitly approved the fail-closed Claude CLI runtime contract. (role: feature introducer, recent area contributor, and policy decision owner; confidence: high; commits: f63d43f021bc, 05475115182f, 0b5aaf0afc95; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift, Tests/CodexBarTests/ClaudeWebFetchDeadlineTests.swift, TestsLinux/PlatformGatingTests.swift)
  • afarwind: Contributed the merged background-refresh authentication guard that established the non-interactive auth-status pattern reused by this PR. (role: adjacent behavior contributor; confidence: medium; commits: e486c6c5f0ef, 05475115182f; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift)
  • janpollak: Recently changed the surrounding Claude Auto fallback behavior for MCP-only Keychain state, making them relevant to interactions in the same planning path. (role: recent adjacent contributor; confidence: medium; commits: 99c3d94d4313; files: Sources/CodexBarCore/Providers/Claude/ClaudeProviderDescriptor.swift)
What the crustacean ranks mean
  • 🦀 challenger crab: rare, exceptional readiness with strong proof, clean implementation, and convincing validation.
  • 🦞 diamond lobster: very strong readiness with only minor maintainer review expected.
  • 🐚 platinum hermit: good normal PR, likely mergeable with ordinary maintainer review.
  • 🦐 gold shrimp: useful signal, but proof or patch confidence is still limited.
  • 🦪 silver shellfish: thin signal; proof, validation, or implementation needs work.
  • 🧂 unranked krab: not merge-ready because proof is missing/unusable or there are serious correctness or safety concerns.
  • 🌊 off-meta tidepool: rating does not apply to this item.

Shiny media proof means a screenshot, video, or linked artifact directly shows the changed behavior. Runtime, network, CSP, and security claims still need visible diagnostics.

How this review workflow works
  • ClawSweeper keeps one durable marker-backed review comment per issue or PR.
  • Re-runs edit this comment so the latest verdict, findings, and automation markers stay together instead of adding duplicate bot comments.
  • A fresh review can be triggered by eligible @clawsweeper re-review comments, exact-item GitHub events, scheduled/background review runs, or manual workflow dispatch.
  • PR/issue authors and users with repository write access can comment @clawsweeper re-review or @clawsweeper re-run on an open PR or issue to request a fresh review only.
  • Maintainers can also comment @clawsweeper review to request a fresh review only.
  • Fresh-review commands do not start repair, autofix, rebase, CI repair, or automerge.
  • Maintainer-only repair and merge flows require explicit commands such as @clawsweeper autofix, @clawsweeper automerge, @clawsweeper fix ci, or @clawsweeper address review.
  • Maintainers can comment @clawsweeper explain to ask for more context, or @clawsweeper stop to stop active automation.
Review history (2 earlier review cycles)
  • reviewed 2026-07-11T20:30:29.772Z sha 8199f2d :: found issues before merge. :: [P3] Remove the release-owned changelog entry
  • reviewed 2026-07-11T20:54:30.256Z sha 6374107 :: needs maintainer review before merge. :: none

@steipete
steipete force-pushed the fix/guard-logged-out-claude-cli-runtime branch from 8199f2d to 6374107 Compare July 11, 2026 20:50
@steipete

Copy link
Copy Markdown
Owner

Maintainer repair complete at 6374107d8.

Policy decision: CodexBar CLI runtime now intentionally fails closed when Claude cannot prove authentication through auth status --json. This matches the existing unattended background-app guard and prevents restoring the interactive hang for old or incompatible wrappers.

Changes beyond the original head:

  • preserved Bear's production and Linux-test commit under Bear's authorship
  • moved the release note to a separate maintainer-owned commit
  • repaired the stale macOS web-deadline fixture to provide an authenticated fake CLI and clean up both temporary executables

Proof:

  • current main black-box control: fake logged-out Claude reached the interactive path twice and timed out after 4.16 seconds
  • repaired release CLI: isolated Auto and explicit CLI both completed under one second, called only auth status --json, and never called --allowed-tools or /usage
  • real Claude Code 2.1.207 auth-status contract: supported
  • redacted real-account explicit CLI probe: usage returned with a primary window and no error
  • swift test --filter PlatformGatingTests: 9/9
  • swift test --filter ClaudeWebFetchDeadlineTests: 8/8
  • make check: SwiftFormat clean; SwiftLint 0 violations
  • make test: 611 selections, 51/51 groups, zero failures, retries, or timeouts
  • autoreview: clean, no accepted/actionable findings (0.94 confidence)

Thanks @BearHuddleston!

@clawsweeper clawsweeper Bot added rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. and removed rating: 🐚 platinum hermit Good normal PR readiness with ordinary maintainer review expected. labels Jul 11, 2026

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 78d0cb9808

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

context.sourceMode == .auto &&
ProviderInteractionContext.current == .background)
guard requiresAuthPreflight else { return true }
guard let binary = ClaudeCLIResolver.resolvedBinaryPath(environment: context.env) else { return false }

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve the explicit missing-CLI error

When a CLI invocation explicitly selects Claude CLI and claude is not installed, this guard now marks the only strategy unavailable, so ProviderFetchPipeline returns the generic ProviderFetchError.noAvailableStrategy and the CLI exits with the default failure code. Before this change the strategy stayed available and loadViaPTY/loadViaDirectCLI threw ClaudeUsageError.claudeNotInstalled, which includes the install URL and maps to exit code 2; keep explicit CLI requests available when the binary is missing so users still get the actionable installer error while using the auth preflight once a binary is present.

Useful? React with 👍 / 👎.

@steipete
steipete merged commit 57d09ce into steipete:main Jul 11, 2026
8 checks passed
@steipete

Copy link
Copy Markdown
Owner

Landed via 57d09cefcc4b80983edbabed1c013b053141d648 — thank you @BearHuddleston!

Final proof on exact head 78d0cb9808caf6c1176d3ec3f889472944a1adc6:

  • make check: SwiftFormat clean; SwiftLint 0 violations.
  • make test: 611/611 selections across 51/51 groups, zero retries or timeouts.
  • Live CLI validation: logged-out Auto and explicit CLI modes completed promptly after only claude auth status --json, without starting the interactive /usage probe; a real logged-in Claude Code session still returned usage successfully.
  • CI: Linux x64/arm64, both macOS shards, lint, aggregate gate, and GitGuardian all passed.
  • Independent autoreview: clean, no actionable findings.

chriscoveries pushed a commit to chriscoveries/CodexBar that referenced this pull request Oct 12, 2026
* fix: guard logged-out Claude CLI usage

* docs: note logged-out Claude CLI guard

* test: authenticate Claude CLI deadline fixture

* test: isolate Claude CLI platform fixture

---------

Co-authored-by: Peter Steinberger <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

merge-risk: 🚨 auth-provider 🚨 Merging this PR could break OAuth, tokens, provider routing, model choice, or credentials. merge-risk: 🚨 compatibility 🚨 Merging this PR could break existing users, config, migrations, defaults, or upgrades. P2 Normal priority bug or improvement with limited blast radius. proof: sufficient Contributor real behavior proof is sufficient. rating: 🦞 diamond lobster Very strong PR readiness with only minor maintainer review expected. status: 👀 ready for maintainer look ClawSweeper has no concrete contributor-facing blocker left for this PR.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants