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

Function Usage

src/components/Settings/Usage.tsx:174–265  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

172 }
173}
174export function Usage(): React.ReactNode {
175 const [utilization, setUtilization] = useState<Utilization | null>(null);
176 const [error, setError] = useState<string | null>(null);
177 const [isLoading, setIsLoading] = useState(true);
178 const {
179 columns
180 } = useTerminalSize();
181 const availableWidth = columns - 2; // 2 for screen padding
182 const maxWidth = Math.min(availableWidth, 80);
183 const loadUtilization = React.useCallback(async () => {
184 setIsLoading(true);
185 setError(null);
186 try {
187 const data = await fetchUtilization();
188 setUtilization(data);
189 } catch (err) {
190 logError(err as Error);
191 const axiosError = err as {
192 response?: {
193 data?: unknown;
194 };
195 };
196 const responseBody = axiosError.response?.data ? jsonStringify(axiosError.response.data) : undefined;
197 setError(responseBody ? `Failed to load usage data: ${responseBody}` : 'Failed to load usage data');
198 } finally {
199 setIsLoading(false);
200 }
201 }, []);
202 useEffect(() => {
203 void loadUtilization();
204 }, [loadUtilization]);
205 useKeybinding('settings:retry', () => {
206 void loadUtilization();
207 }, {
208 context: 'Settings',
209 isActive: !!error && !isLoading
210 });
211 if (error) {
212 return <Box flexDirection="column" gap={1}>
213 <Text color="error">Error: {error}</Text>
214 <Text dimColor>
215 <Byline>
216 <ConfigurableShortcutHint action="settings:retry" context="Settings" fallback="r" description="retry" />
217 <ConfigurableShortcutHint action="confirm:no" context="Settings" fallback="Esc" description="cancel" />
218 </Byline>
219 </Text>
220 </Box>;
221 }
222 if (!utilization) {
223 return <Box flexDirection="column" gap={1}>
224 <Text dimColor>Loading usage data…</Text>
225 <Text dimColor>
226 <ConfigurableShortcutHint action="confirm:no" context="Settings" fallback="Esc" description="cancel" />
227 </Text>
228 </Box>;
229 }
230
231 // Only Max and Team plans have a Sonnet limit that differs from the weekly

Callers

nothing calls this directly

Calls 7

useTerminalSizeFunction · 0.85
fetchUtilizationFunction · 0.85
jsonStringifyFunction · 0.85
useKeybindingFunction · 0.85
getSubscriptionTypeFunction · 0.85
logErrorFunction · 0.50

Tested by

no test coverage detected