Repository navigation
Description
Client or integration
Claude Code
Area
Authentication and account pool
Summary
On macOS 27.0, the Claude Code Keychain reads in src/oauth/local-token-detect.ts (readClaudeKeychain, readClaudeKeychainAsync) and the probe in src/claude/auth-detect.ts (keychainProbe) run /usr/bin/security with a 5 s timeout. When the login keychain is locked, security blocks on the SecurityAgent unlock prompt, and the timeout kills it while the prompt is still open.
Killing a security process while its SecurityAgent query is pending hits a race in Apple's securityd: it logs Probable bug: error destroying Mutex: 16 / UNIX error exception: 16 and aborts (SIGABRT, std::terminate). When securityd restarts, the login keychain is locked again. The next request reads the keychain, gets killed after 5 s, and crashes securityd again, so the user sees an endless "security wants to use the login keychain" password prompt.
I expected OpenCodex not to kill a security that is blocked on a prompt, or to skip the read when the login keychain is locked.
The securityd race itself is Apple's bug, but other tools have hit the same trigger and stopped the loop by no longer killing blocked security calls:
- macOS: TUI spawns
/usr/bin/security~8×/s (uncached per-account Keychain reads every 3 s), triggering securityd crashes and prompt storms realiti4/claude-swap#496 - macOS: per-render
securitykeychain reads pile up unlock requests after a securityd restart and wedge securityd (screen unlock hangs) sirmalloc/ccstatusline#740 - https://developer.apple.com/forums/thread/844097
Reproduction
Intermittent, because it needs the login keychain to be locked first (one securityd crash, or a keychain whose password doesn't match the login password).
- Run
ocxas the launchd service with Claude Code signed in through the macOS Keychain. - Get the login keychain locked (for example after one
securitydcrash). - Send Claude requests through the proxy. Each read spawns
security find-generic-password -s "Claude Code-credentials" -w, which blocks on the unlock prompt and is killed after 5 s. securitydcrashes, the keychain locks again, and the prompts keep coming back.
What I observed: 62 security runs in 7 minutes, 16 of them with no normal exit, and 4 securityd crash reports (/Library/Logs/DiagnosticReports/securityd-*.ips), all with the same faulting MachServer stack.
Version
2.97.0 (2.96.0 behaves the same)
Operating system
macOS 27.0 (26A428), Apple Silicon
Provider and model
Claude (claude-cli adapter, Keychain credentials)
Logs or error output
securityd: [com.apple.securityd:SecurityAgentXPCQuery] SecurityAgentXPCQuery(...) dying
securityd: [com.apple.securityd:SecError] Probable bug: error destroying Mutex: 16
securityd: [com.apple.securityd:security_exception] UNIX error exception: 16
crash: EXC_CRASH (SIGABRT), abort() called, faulting thread "MachServer", std::terminate
Screenshots and supporting files
The prompt that keeps coming back: "security wants to use the 'login' keychain. Enter the keychain password."
Redacted configuration
Default service install; nothing relevant in the config.
Possible fix
The workaround I'm running locally checks the login keychain lock state without showing any UI (SecKeychainOpen + SecKeychainGetStatus through bun:ffi) and skips the security call when it is locked. The read returns null (or "unknown" for the probe) and falls back as it already does on a timeout. If anything fails, it returns "not locked", so the behaviour stays the same as now.
export function loginKeychainLocked(path = join(homedir(), "Library", "Keychains", "login.keychain-db")): boolean {
if (process.platform !== "darwin") return false;
// dlopen Security.framework: SecKeychainOpen, SecKeychainGetStatus; CoreFoundation: CFRelease
// return (status & kSecUnlockStateStatus) === 0; any error -> false
}Then call it at the start of readClaudeKeychain, readClaudeKeychainAsync and keychainProbe. Another option is to stop killing a blocked child: resolve null after 5 s but let the child exit on its own, and share a single in-flight read.
readMuseKeychain already waits 120 s for an interactive login, so I left it alone.
Checks
- I searched existing issues and documentation.
- I removed secrets, tokens, account details, request credentials, and personal data.
Activity
github-actions commentedon Nov 4, 2026
Automated translation bookkeeping — detected language: English.
docs(upstream): triage closed PRs lidge-jun#7614/lidge-jun#7618, issue …
Ingwannu commentedon Nov 7, 2026
Thanks for the precise report. Confirmed on
dev(aaa3c20f3f): all three Claude Code Keychain reads use the runtime's timeout, which kills the child:src/oauth/local-token-detect.ts:80-81: synchronousexecSync(... -w)withtimeout: 5000src/oauth/local-token-detect.ts:116: asyncexecFile(... -w)withtimeout: 5000src/claude/auth-detect.ts:208-210:spawnSyncmetadata probe withKEYCHAIN_TIMEOUT_MS, which is 1.5 s rather than 5 s (:40)The request path reads the credential through
readLocalIdentity(src/adapters/claude-cli/usage-admission.ts:37). That has a 60 s cache, but these reads bypass it:freshreadssrc/oauth/anthropic.ts:231,src/oauth/anthropic-continuity.ts:27,71)So a locked keychain can trigger repeated kills, which fits your 62 runs in 7 minutes.
Of your two options, the second is the better first step: it keeps the current process model and adds no
bun:ffibinding to Security.framework.securitychild. Returnnull(orunknownfor the probe) after the deadline and let the child exit on its own. The synchronousexecSyncreader can't time out without killing, so its callers would need to move to the async reader or reuse its cached result.securitystarts while one is still blocked.The FFI lock-state check could follow if prompts are still too frequent. It adds a native binding on the credential path, so it would need separate review. Validating any of this needs a real macOS host with a locked login keychain. Linux CI can only cover the non-darwin no-op and the in-flight sharing and backoff logic, through injected spawners.
fix(oauth): stop killing blocked Claude Keychain reads
fix(oauth): settle Keychain reads on close and decode stdout once
fix(oauth): release the Keychain slot only from its owning child
fix(oauth): stop killing blocked Claude Keychain reads (#8327)
lidge-jun commentedon Nov 10, 2026
Status on
dev(e9fdc00): partly fixed. #8327 (merge commit 80d79b5) stops the asynchronous request-path Keychain read from signalling a blockedsecuritychild, keeps one child per process and backs off for 60 s after a timeout. The synchronous paths still end a blocked child on timeout, at most once per backoff window:readSyncinsrc/oauth/claude-keychain-read.ts(execFileSyncwithtimeout) andprobeClaudeKeychaininsrc/claude/auth-detect.ts(spawnSyncwithtimeout). The remaining scope, bounding those waits without terminatingsecurity, is covered by the open #8337. Keeping this issue open until that lands.fix(claude): never spawn the Claude Keychain lookup synchronously (#8161