MCPcopy
hub / github.com/codeaashu/claude-code / authStatus

Function authStatus

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

Source from the content-addressed store, hash-verified

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