AI Coding Agent Credential Store (Claude Code, Codex CLI)
Detects the OAuth token stores that AI coding agents keep on a developer's machine: Claude Code's .credentials.json (a claudeAiOauth object holding accessToken and refreshToken) and the OpenAI Codex CLI's auth.json (a tokens object holding id_token, access_token and refresh_token beside an OPENAI_API_KEY key). These files are plaintext, and the tokens in them act as the signed-in user: they spend the account's subscription and reach whatever the agent is connected to. Infostealers and npm supply-chain worms in 2026 collected both files. The pattern detects the file content, not a path, so it also fires when the JSON is pasted into a ticket, chat or repository.
- Type
- regex
- Engine
- boost_regex
- Confidence
- medium
- Confidence justification
- Medium confidence. The key names come from first-party source code (Anthropic's Claude Agent SDK for claudeAiOauth, accessToken and refreshToken; the open-source Codex CLI for auth.json), and the container keys are specific to these tools. The token values are opaque strings with no documented prefix, length or checksum, so the regex cannot validate them or tell an expired token from a live one, and the field names alone are common in other OAuth clients. Enforce tiers therefore require the tool-specific container or sibling keys.
- Jurisdictions
- global
- Regulations
- Criminal Code Act 1995 (Cth), Computer Fraud and Abuse Act, Computer Misuse Act 1990
- Frameworks
- CIS Controls, ISO 27001, NIST CSF, SOC 2
- Data categories
- credentials, security
- Scope
- narrow
- Risk rating
- 8
- Platform compatibility
- Purview: Compatible, GCP DLP: Unsupported, Macie: Unsupported, Zscaler: Compatible, CrowdStrike DLP: Unsupported, Palo Alto: Unsupported, Netskope: Unsupported
Pattern
(?i)("(?:accessToken|refreshToken)"\s*:\s*"(?![<$]|[^"]{0,40}(?:your|xxxx|\*{3}|redacted|placeholder|changeme))[^"\s]{20,}")
Corroborative evidence keywords
claudeAiOauth, .credentials.json, auth.json, OPENAI_API_KEY, last_refresh, Claude Code, Codex
Proximity: 300 characters
Should match
"refreshToken": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"— Exact 65 probe - token field with no agent container{"claudeAiOauth":{"accessToken":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"}}— Exact 75 probe - compact Claude Code store holding only an access token{ "claudeAiOauth": { "accessToken": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "refreshToken": "zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210" } }— Exact 85 probe - pretty-printed Claude Code .credentials.json with access and refresh tokens{ "OPENAI_API_KEY": null, "tokens": { "id_token": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJkZXBsb3llciJ9.ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789", "access_token": "eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJkZXBsb3llciJ9.abcdefghijklmnopqrstuvwxyz0123456789", "refresh_token": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop", "account_id": "00000000-0000-0000-0000-000000000000" }, "last_refresh": "2026-11-01T00:00:00Z" }— Exact 85 probe - pretty-printed Codex CLI auth.json as the CLI writes it"refresh_token":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop","account_id":"00000000-0000-0000-0000-000000000000"},"last_refresh":"2026-11-01T00:00:00Z"}— Exact 75 probe - tail of a Codex auth.json, where the tokens key is far behind the refresh token
Should not match
{"claudeAiOauth": {"accessToken": "<your-access-token>", "refreshToken": "<your-refresh-token>"}}— Angle-bracket placeholders in place of tokens{"claudeAiOauth": {"accessToken": "", "refreshToken": ""}}— Signed-out store with empty token values{"OPENAI_API_KEY": null}— Codex auth.json with no cached tokens (the tokens key is omitted when empty){"access_token":"eyJhbGciOiJSUzI1NiJ9.eyJzdWIiOiJkZXBsb3llciJ9.ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789","token_type":"Bearer","expires_in":3600,"refresh_token":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnop"}— Generic OAuth 2.0 token response with no Codex sibling keys (discovery only){"session": {"accessToken": "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789", "expiresIn": 3600}}— Another application's camelCase access token with no claudeAiOauth object (discovery only)Claude Code keeps the accessToken and refreshToken under claudeAiOauth in .credentials.json.— Prose that names the keys without a valueDocumentation example: {"claudeAiOauth":{"accessToken":"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789","refreshToken":"zyxwvutsrqponmlkjihgfedcbaZYXWVUTSRQPONMLKJIHGFEDCBA9876543210"}}— Complete store with both tokens, vetoed on every tier by the documentation-example framing
Known false positives
- Other applications that store OAuth tokens in JSON under the same field names (accessToken, refresh_token and so on), and raw OAuth 2.0 token responses. Mitigation: Those reach only the discovery tier. Enforce tiers require the claudeAiOauth object, or the Codex sibling keys OPENAI_API_KEY or last_refresh, within the proximity window.
- Expired tokens. Access tokens are short-lived and a refresh token stops working once it is used or revoked. Mitigation: The pattern cannot test liveness. Treat a match as a credential to revoke by signing the agent out and back in; the 85 tier marks files that hold a refresh token.
- Third-party tools and test fixtures that reproduce the file layout with invented token values. Mitigation: The regex rejects angle-bracket, starred, x-run and variable-reference values; the shared template exclusion vetoes documentation and fixture framing.
References
- Claude Code docs, Authentication, Credential management (credentials are stored in ~/.claude/.credentials.json on Linux and Windows, and in the macOS Keychain with the same file as fallback)
- Anthropic claude-agent-sdk-python source (copies .credentials.json and removes claudeAiOauth.refreshToken from the copy)
- Anthropic claude-agent-sdk-python tests (fixture {"claudeAiOauth": {"accessToken": ..., "refreshToken": ...}} establishes the accessToken key)
- OpenAI Codex CLI source, AuthDotJson (the expected structure of $CODEX_HOME/auth.json: auth_mode, OPENAI_API_KEY, tokens, last_refresh; OPENAI_API_KEY is always written, as null when unset; pretty-printed JSON)
- OpenAI Codex CLI source, TokenData (id_token, access_token, refresh_token, account_id)
- OpenAI Codex docs, Authentication (login details are cached in plaintext at ~/.codex/auth.json or the OS credential store; treat auth.json like a password)
- SpyCloud, 30 October 2026 (infostealers taking Claude Code OAuth access and refresh tokens and the Codex authentication file)
- StepSecurity, ChainDrop npm worm, 4 August 2026 (lists Claude and Codex credential files among those harvested)