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

Function runExtraUsage

src/commands/extra-usage/extra-usage-core.ts:18–118  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

16 | { type: 'browser-opened'; url: string; opened: boolean }
17
18export async function runExtraUsage(): Promise<ExtraUsageResult> {
19 if (!getGlobalConfig().hasVisitedExtraUsage) {
20 saveGlobalConfig(prev => ({ ...prev, hasVisitedExtraUsage: true }))
21 }
22 // Invalidate only the current org's entry so a follow-up read refetches
23 // the granted state. Separate from the visited flag since users may run
24 // /extra-usage more than once while iterating on the claim flow.
25 invalidateOverageCreditGrantCache()
26
27 const subscriptionType = getSubscriptionType()
28 const isTeamOrEnterprise =
29 subscriptionType === 'team' || subscriptionType === 'enterprise'
30 const hasBillingAccess = hasClaudeAiBillingAccess()
31
32 if (!hasBillingAccess && isTeamOrEnterprise) {
33 // Mirror apps/claude-ai useHasUnlimitedOverage(): if overage is enabled
34 // with no monthly cap, there is nothing to request. On fetch error, fall
35 // through and let the user ask (matching web's "err toward show" behavior).
36 let extraUsage: ExtraUsage | null | undefined
37 try {
38 const utilization = await fetchUtilization()
39 extraUsage = utilization?.extra_usage
40 } catch (error) {
41 logError(error as Error)
42 }
43
44 if (extraUsage?.is_enabled && extraUsage.monthly_limit === null) {
45 return {
46 type: 'message',
47 value:
48 'Your organization already has unlimited extra usage. No request needed.',
49 }
50 }
51
52 try {
53 const eligibility = await checkAdminRequestEligibility('limit_increase')
54 if (eligibility?.is_allowed === false) {
55 return {
56 type: 'message',
57 value: 'Please contact your admin to manage extra usage settings.',
58 }
59 }
60 } catch (error) {
61 logError(error as Error)
62 // If eligibility check fails, continue — the create endpoint will enforce if necessary
63 }
64
65 try {
66 const pendingOrDismissedRequests = await getMyAdminRequests(
67 'limit_increase',
68 ['pending', 'dismissed'],
69 )
70 if (pendingOrDismissedRequests && pendingOrDismissedRequests.length > 0) {
71 return {
72 type: 'message',
73 value:
74 'You have already submitted a request for extra usage to your admin.',
75 }

Callers 2

callFunction · 0.85
callFunction · 0.85

Calls 11

getGlobalConfigFunction · 0.85
saveGlobalConfigFunction · 0.85
getSubscriptionTypeFunction · 0.85
hasClaudeAiBillingAccessFunction · 0.85
fetchUtilizationFunction · 0.85
getMyAdminRequestsFunction · 0.85
createAdminRequestFunction · 0.85
openBrowserFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected