Skip to content

Commit 0822e4f

Browse files
committed
fix(terminal): support claude-sonnet-4-5 model name formatting
Updated the model name regex pattern to properly handle version numbers with hyphens (e.g., claude-sonnet-4-5-20250929). Previously, only single digit versions were supported (e.g., claude-sonnet-4-20250514). Changes: - Modified regex from /claude-(\w+)-(\d+)-\d+/ to /claude-(\w+)-([\d-]+)-(\d{8})/ - Added [\d-]+ pattern to match multi-part version numbers like "4-5" - Updated JSDoc examples to include claude-sonnet-4-5-20250929 format - Added test cases for Claude 4.5 and mixed version formats Fixes the issue where claude-sonnet-4-5-20250929 was being displayed as "sonnet-4" instead of "sonnet-4-5" in usage reports.
1 parent 18a88a9 commit 0822e4f

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

packages/terminal/src/table.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -318,14 +318,15 @@ export function formatCurrency(amount: number): string {
318318
/**
319319
* Formats Claude model names into a shorter, more readable format
320320
* Extracts model type and generation from full model name
321-
* @param modelName - Full model name (e.g., "claude-sonnet-4-20250514")
322-
* @returns Shortened model name (e.g., "sonnet-4") or original if pattern doesn't match
321+
* @param modelName - Full model name (e.g., "claude-sonnet-4-20250514" or "claude-sonnet-4-5-20250929")
322+
* @returns Shortened model name (e.g., "sonnet-4" or "sonnet-4-5") or original if pattern doesn't match
323323
*/
324324
function formatModelName(modelName: string): string {
325325
// Extract model type from full model name
326326
// e.g., "claude-sonnet-4-20250514" -> "sonnet-4"
327327
// e.g., "claude-opus-4-20250514" -> "opus-4"
328-
const match = modelName.match(/claude-(\w+)-(\d+)-\d+/);
328+
// e.g., "claude-sonnet-4-5-20250929" -> "sonnet-4-5"
329+
const match = modelName.match(/claude-(\w+)-([\d-]+)-(\d{8})/);
329330
if (match != null) {
330331
return `${match[1]}-${match[2]}`;
331332
}
@@ -970,5 +971,14 @@ if (import.meta.vitest != null) {
970971
const models = ['custom-model', 'claude-sonnet-4-20250514'];
971972
expect(formatModelsDisplayMultiline(models)).toBe('- custom-model\n- sonnet-4');
972973
});
974+
975+
it('formats Claude 4.5 models correctly', () => {
976+
expect(formatModelsDisplayMultiline(['claude-sonnet-4-5-20250929'])).toBe('- sonnet-4-5');
977+
});
978+
979+
it('formats mixed model versions', () => {
980+
const models = ['claude-sonnet-4-20250514', 'claude-sonnet-4-5-20250929', 'claude-opus-4-1-20250805'];
981+
expect(formatModelsDisplayMultiline(models)).toBe('- opus-4-1\n- sonnet-4\n- sonnet-4-5');
982+
});
973983
});
974984
}

0 commit comments

Comments
 (0)