vision: OAuth-from-keychain fallback for macOS Claude Code users#25
Merged
Conversation
Adds a credential resolver to ClaudeVisionProvider: 1. explicit api_key= argument 2. ANTHROPIC_API_KEY env var 3. ANTHROPIC_AUTH_TOKEN env var (OAuth bearer) 4. macOS only: 'Claude Code-credentials' keychain entry The keychain branch makes 'bambu vision watch' work on a Mac with Claude Code authenticated with zero extra setup. Token is read on demand via the 'security' command, never written to disk, never logged. Falls through to the next source on any failure (missing entry, wrong format, non-Mac). Verified live: 'bambu vision classify <real-frame>' against a captured A1 mini frame returned a valid JSON verdict via the keychain path (cost ~$0.0022 with Haiku 4.5). Tests: 51 passing (39 prior + 11 credentials + 1 OAuth-keychain-wiring).
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.
Summary
Makes `bambu vision watch` Just Work™ for users who already have Claude Code installed on macOS — no API key paste required.
Credential resolution
`ClaudeVisionProvider` now resolves credentials in this order, first hit wins:
Option 4 is read on demand via the `security` command, never written to disk, never logged. Falls through cleanly on any failure (missing entry, wrong format, non-Mac).
Verified live
Ran `bambu vision classify` against a real captured A1-mini frame with no env vars set:
```
$ bambu vision classify /tmp/bambu-frames/current-print-...jpg --model claude-haiku-4-5
classification: unknown
confidence: 30.00%
is_failure: False
cost: $0.0022
reasoning: Frame is at an oblique angle with poor lighting and significant
glare on the build plate, making it impossible to clearly assess
layer quality, extrusion state, or print geometry.
```
(That "unknown" verdict is actually correct — the captured frame is a wide-angle workspace shot, not a print-bed view. The model honestly admitted it couldn't tell. Better frames during an active print will give crisper verdicts.)
Tests
Caveat
Using Claude Code's OAuth token spends the same Claude account's quota as Claude Code itself. Heavy vision use during normal coding sessions can rate-limit both. For unattended long-running prints, a separate `ANTHROPIC_API_KEY` is still the right call. Documented in `docs/vision.md`.