Skip to content

Fix statusline to show actual current model instead of hardcoded Opus 4.5#1071

Open
thewoolleyman wants to merge 2 commits intoruvnet:mainfrom
thewoolleyman:fix/statusline-model-detection
Open

Fix statusline to show actual current model instead of hardcoded Opus 4.5#1071
thewoolleyman wants to merge 2 commits intoruvnet:mainfrom
thewoolleyman:fix/statusline-model-detection

Conversation

@thewoolleyman
Copy link

Problem

The claude-flow hooks statusline command was showing a hardcoded "Opus 4.5" model name regardless of which model the user was actually using in Claude Code. This caused confusion when users switched models (e.g., to Sonnet or Haiku) but the statusline continued to display "Opus 4.5".

Root Cause

In v3/@claude-flow/cli/src/commands/hooks.ts, the getUserInfo() function had:

const modelName = 'Opus 4.5';

There was no detection of the actual model from Claude Code's session state.

Solution

Updated the getUserInfo() function to:

  1. Read ~/.claude.json to find the current project's lastModelUsage
  2. Prefer the most specific path: When multiple project paths match, choose the longest (most specific) one
  3. Calculate total token usage: Include cache tokens (cacheReadInputTokens + cacheCreationInputTokens) to accurately determine the most-used model
  4. Parse model ID: Convert model IDs like claude-sonnet-4-5-20250929 to human-readable names like "Sonnet 4.5"
  5. Fallback gracefully: Show "Unknown" if detection fails

Changes

  • Added os import for accessing home directory
  • Replaced hardcoded const modelName = 'Opus 4.5' with let modelName = 'Unknown'
  • Added model detection logic that:
    • Finds the most specific matching project path
    • Calculates total token usage including cache tokens
    • Maps model IDs to display names (Opus 4.5, Sonnet 4.5, Sonnet 4, Haiku 4.5)

Testing

Tested with:

  • User switching from Opus to Sonnet → statusline correctly shows "Sonnet 4.5"
  • Nested project directories → correctly prefers specific project path over parent
  • Multiple models used in session → shows the most-used model by token count

Impact

  • Users will now see their actual current model in the statusline
  • Works correctly across all Claude models (Opus, Sonnet, Haiku)
  • Handles edge cases like nested project directories

Screenshot

Before:

▊ Claude Flow V3 ● user  │  ⎇ main  │  Opus 4.5

After (when using Sonnet):

▊ Claude Flow V3 ● user  │  ⎇ main  │  Sonnet 4.5

🤖 Generated with assistance from Claude Code

…s 4.5"

The statusline command was showing a hardcoded "Opus 4.5" model name
regardless of which model the user was actually using in Claude Code.

Root cause:
- getUserInfo() function had `const modelName = 'Opus 4.5'` hardcoded
- No detection of actual model from Claude Code's session state

Fix:
- Read ~/.claude.json to find the current project's lastModelUsage
- Prefer the most specific (longest) matching project path
- Calculate total token usage including cache tokens to find most-used model
- Parse model ID to human-readable name (Opus 4.5, Sonnet 4.5, Haiku 4.5)
- Fallback to "Unknown" if detection fails

Result:
- Statusline now correctly shows the actual model being used
- Works across all Claude models (Opus, Sonnet, Haiku)
- Handles nested project directories correctly

Fixes: User switching to Sonnet but statusline still showing Opus
Change 'Unknown' to 'Model unknown (no usage yet)' to better communicate
why the model isn't detected and that it will be once usage data is recorded.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant