MCPcopy Create free account
hub / github.com/claude-code-best/claude-code / authStatus

Function authStatus

src/cli/handlers/auth.ts:236–323  ·  view source on GitHub ↗
(opts: {
  json?: boolean
  text?: boolean
})

Source from the content-addressed store, hash-verified

234}
235
236export async function authStatus(opts: {
237 json?: boolean
238 text?: boolean
239}): Promise<void> {
240 const { source: authTokenSource, hasToken } = getAuthTokenSource()
241 const { source: apiKeySource } = getAnthropicApiKeyWithSource()
242 const hasApiKeyEnvVar =
243 !!process.env.ANTHROPIC_API_KEY && !isRunningOnHomespace()
244 const oauthAccount = getOauthAccountInfo()
245 const subscriptionType = getSubscriptionType()
246 const using3P = isUsing3PServices()
247 const loggedIn =
248 hasToken || apiKeySource !== 'none' || hasApiKeyEnvVar || using3P
249
250 // Determine auth method
251 let authMethod: string = 'none'
252 if (using3P) {
253 authMethod = 'third_party'
254 } else if (authTokenSource === 'claude.ai') {
255 authMethod = 'claude.ai'
256 } else if (authTokenSource === 'apiKeyHelper') {
257 authMethod = 'api_key_helper'
258 } else if (authTokenSource !== 'none') {
259 authMethod = 'oauth_token'
260 } else if (apiKeySource === 'ANTHROPIC_API_KEY' || hasApiKeyEnvVar) {
261 authMethod = 'api_key'
262 } else if (apiKeySource === '/login managed key') {
263 authMethod = 'claude.ai'
264 }
265
266 if (opts.text) {
267 const properties = [
268 ...buildAccountProperties(),
269 ...buildAPIProviderProperties(),
270 ]
271 let hasAuthProperty = false
272 for (const prop of properties) {
273 const value =
274 typeof prop.value === 'string'
275 ? prop.value
276 : Array.isArray(prop.value)
277 ? prop.value.join(', ')
278 : null
279 if (value === null || value === 'none') {
280 continue
281 }
282 hasAuthProperty = true
283 if (prop.label) {
284 process.stdout.write(`${prop.label}: ${value}\n`)
285 } else {
286 process.stdout.write(`${value}\n`)
287 }
288 }
289 if (!hasAuthProperty && hasApiKeyEnvVar) {
290 process.stdout.write('API key: ANTHROPIC_API_KEY\n')
291 }
292 if (!loggedIn) {
293 process.stdout.write(

Callers 1

runFunction · 0.85

Calls 11

getAuthTokenSourceFunction · 0.85
isRunningOnHomespaceFunction · 0.85
getSubscriptionTypeFunction · 0.85
isUsing3PServicesFunction · 0.85
buildAccountPropertiesFunction · 0.85
getAPIProviderFunction · 0.85
jsonStringifyFunction · 0.85
getOauthAccountInfoFunction · 0.50
writeMethod · 0.45

Tested by

no test coverage detected