Skip to content

macOS: Session Usage shows 'no credentials' when OAuth token is in credentials file instead of keychain #236

Closed

Description

@bdbb

Bug

On macOS, the Session Usage widget displays "no credentials" even though a valid OAuth token exists in ~/.claude/.credentials.json.

Root Cause

In usage-fetch.ts, getUsageToken() has a platform-specific branch for macOS that only checks the keychain:

if (isMac) {
    const result = execSync(
        'security find-generic-password -s "Claude Code-credentials" -w 2>/dev/null',
        { encoding: 'utf8', stdio: ['pipe', 'pipe', 'pipe'] }
    ).trim();
    const token = parseUsageAccessToken(result);
    // ...
    return token;  // returns null — never falls back to credentials file
}

This fails for two reasons:

  1. GUID suffix mismatch — Claude Code stores the keychain entry under a name like "Claude Code-credentials-6248605b" (with a per-installation GUID suffix), but ccstatusline looks for the exact name "Claude Code-credentials" without the suffix.

  2. No file fallback — Even when the keychain entry exists (with the suffixed name), the password data may not be readable from a non-interactive shell context. The non-macOS code path reads from ~/.claude/.credentials.json, but on macOS this fallback is never reached.

Steps to Reproduce

  1. Install ccstatusline on macOS
  2. Be logged into Claude Code via OAuth (valid token in ~/.claude/.credentials.json)
  3. Add the Session Usage widget
  4. Observe it shows "no credentials"

Verification

# Keychain entry exists but with a GUID suffix:
security dump-keychain | grep "Claude Code-credentials"
# Output: "Claude Code-credentials-6248605b"

# The credentials file has a valid token:
python3 -c "import json; d=json.load(open('$HOME/.claude/.credentials.json')); print('has token:', bool(d.get('claudeAiOauth',{}).get('accessToken')))"
# Output: has token: True

Suggested Fix

On macOS, fall back to reading ~/.claude/.credentials.json when the keychain lookup fails:

if (isMac) {
    // Try keychain first (with prefix matching for GUID-suffixed entries)
    // ...existing keychain logic...

    // Fall back to credentials file (same as non-macOS path)
    if (!token) {
        const credFile = path.join(getClaudeConfigDir(), '.credentials.json');
        token = parseUsageAccessToken(fs.readFileSync(credFile, 'utf8'));
    }
}

Environment

  • OS: macOS Tahoe (Darwin 25.3.0)
  • Claude Code version: v2.1.75+
  • ccstatusline version: latest (via npx)
  • Model: Opus 4.6 (1M context)

Activity

  1. sirmalloc commented on Mar 15, 2026

    @sirmalloc
    Owner

    I saw this issue open and then close quickly. Is this still an issue? I've not seen a suffix on the keychain entry on macOS, nor have I seen Claude on macOS store credentials outside the keychain.

  2. reopened this on Mar 15, 2026
  3. bdbb commented on Mar 15, 2026

    @bdbb
    Author

    Yes, still an issue! Sorry about the close/reopen, that was accidental.

    Here's what I'm seeing on macOS (Claude Code v2.1.76):

    Keychain entry has a GUID suffix:

    $ security dump-keychain | grep -i "claude code-credentials"
        0x00000007 <blob>="Claude Code-credentials-6248605b"
        "svce"<blob>="Claude Code-credentials-6248605b"
    

    There is no entry for the exact name "Claude Code-credentials" (without suffix).

    Credentials file exists and has a valid token:

    $ python3 -c "import json; d=json.load(open('$HOME/.claude/.credentials.json')); print('has token:', bool(d.get('claudeAiOauth',{}).get('accessToken')))"
    has token: True
    

    Keychain entry exists but -w returns empty:

    $ security find-generic-password -s "Claude Code-credentials-6248605b" -w
    # (no output, no error)
    

    So the problem is two things:

    1. The keychain service name has a GUID suffix (-6248605b) that getUsageToken() doesn't account for
    2. Even with the correct name, -w returns nothing, and there's no fallback to ~/.claude/.credentials.json on macOS

    The non-macOS code path already reads from the credentials file. Adding a fallback on macOS would fix it.

  4. bdbb commented on Mar 15, 2026

    @bdbb
    Author

    Confirmed workaround: copying the credentials from ~/.claude/.credentials.json into the keychain under the exact service name "Claude Code-credentials" fixes the widget.

    security unlock-keychain ~/Library/Keychains/login.keychain-db && \
    security add-generic-password -s "Claude Code-credentials" -a "$USER" \
      -w "$(cat ~/.claude/.credentials.json)" -U

    This creates the keychain entry that getUsageToken() expects. Session Usage widget starts working immediately after.

    The underlying issue remains though — on macOS, Claude Code v2.1.76 stores the OAuth token in ~/.claude/.credentials.json and creates a keychain entry under "Claude Code-credentials-6248605b" (with a GUID suffix), but ccstatusline only checks for the exact name "Claude Code-credentials" and never falls back to the credentials file.

  5. sirmalloc commented on Mar 15, 2026

    @sirmalloc
    Owner

    I improved the lookup to first try an exact match of Claude Code-credentials, then fallback to any item starting with Claude Code-credentials (and if there are multiple it'll pick the most recently modified one), and failing that, it'll pull it from the credentials.json. This will go out when the next release is published.

  6. added a commit that references this issue on Mar 15, 2026
    5b49868
  7. bdbb commented on Mar 15, 2026

    @bdbb
    Author

    Amazing, thank you so much for your time!

  8. added a commit that references this issue on Mar 28, 2026
    6e17d56
  9. added a commit that references this issue on Oct 20, 2026
    90381d0
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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions