跳转到主内容

Claude 代码

非官方测试版翻译

本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →

功能

显示 Claude 代码会话信息,包括当前 AI 模型、令牌用量、费用和工作区详情。 通过可视化上下文窗口用量指示器和格式化的费用/令牌信息,方便您监控 Claude 使用情况。

该组件与 Claude 代码的状态行功能 集成,可在提示符中提供实时会话数据。

示例配置

{
"type": "claude",
"style": "diamond",
"leading_diamond": "",
"trailing_diamond": "",
"foreground": "#FFFFFF",
"background": "#FF6B35",
"template": " 󰯉 {{ .Model.DisplayName }}  {{ .TokenGauge }} "
}

模板 (信息)

默认模板
\udb82\udfc9 {{ .Model.DisplayName }} \uf2d0 {{ .TokenGauge }}

选项

NameTypeDefaultDescription
gauge_marked_charstringCharacter used for filled blocks in gauge visualizations
gauge_unmarked_charstringCharacter used for empty blocks in gauge visualizations

属性

NameTypeDescription
.CWDstringCurrent working directory; same value as .Workspace.CurrentDir
.SessionIDstringUnique identifier for the Claude session
.SessionNamestringCustom session name; empty when absent
.TranscriptPathstringPath to the conversation transcript file
.ModelModelAI model information
.WorkspaceWorkspaceWorkspace directory information
.VersionstringClaude Code version
.OutputStyleOutputStyleCurrent output style information
.EffortEffortReasoning effort information
.ThinkingThinkingExtended thinking state
.CostCostCost and duration information
.ContextWindowContextWindowToken usage information
.Exceeds200KTokensboolWhether the most recent API response exceeded 200K total tokens
.VimVimVim mode information; empty when absent
.AgentAgentAgent information; empty when absent
.WorktreeWorktreeClaude Code worktree information; empty when absent
.FastModeboolWhether fast mode is enabled; false when absent or unsupported
.TokenUsagePercentPercentagePercentage of context window used (0-100)
.TokenGaugestringGauge showing remaining context capacity using configured characters (e.g., ▰▰▰▱▱)
.TokenGaugeUsedstringGauge showing used context capacity using configured characters (e.g., ▰▰▱▱▱)
.FiveHourGaugestringGauge showing 5-hour rate limit usage using configured characters
.SevenDayGaugestringGauge showing 7-day rate limit usage using configured characters
.FiveHourResetsAttime.Time5-hour rate limit window reset time
.SevenDayResetsAttime.Time7-day rate limit window reset time
.FiveHourResetsIntime.Durationtime until 5-hour resets; 0=unavailable, neg=past
.SevenDayResetsIntime.Durationtime until 7-day resets; 0=unavailable, neg=past
.FormattedCoststringFormatted cost string (e.g., "$0.15" or "$0.0012")
.FormattedTokensstringHuman-readable token count (e.g., "1.2K", "15.3M")
.FormattedDurationstringTotal session duration (e.g., "2m 5s")
.FormattedAPIDurationstringAPI wait time (e.g., "0m 45s")
.FiveHourUsagePercentage5-hour rolling rate limit usage (0-100)
.SevenDayUsagePercentage7-day rate limit usage (0-100)

模型属性

NameTypeDescription
.IDstringTechnical model identifier
.DisplayNamestringHuman-readable model name (e.g., "Claude 3.5 Sonnet")

工作区属性

NameTypeDescription
.CurrentDirstringCurrent working directory; same value as .CWD
.ProjectDirstringDirectory where Claude Code was launched; may differ from .CurrentDir
.AddedDirs[]stringAdditional directories added via /add-dir or --add-dir
.GitWorktreestringPath to the linked git worktree, empty when not inside a linked git worktree

OutputStyle Properties

NameTypeDescription
.NamestringName of the current output style

Effort Properties

NameTypeDescription
.LevelstringReasoning effort level (low, medium, high, xhigh, max); empty when absent or unsupported

Thinking Properties

NameTypeDescription
.EnabledboolWhether extended thinking is enabled; false when absent

Vim Properties

NameTypeDescription
.ModestringCurrent vim mode; empty when vim mode is disabled

Agent Properties

NameTypeDescription
.NamestringAgent name; empty when no agent is active

Worktree Properties

NameTypeDescription
.NamestringName of the active Claude Code worktree
.PathstringAbsolute path to the worktree directory
.BranchstringGit branch name for the worktree; empty when absent
.OriginalCWDstringDirectory Claude Code was in before entering worktree
.OriginalBranchstringBranch checked out before entering worktree; empty when absent

费用属性

NameTypeDescription
.TotalCostUSDfloat64Total cost in USD
.TotalDurationMSDurationMSTotal session duration in milliseconds (formats as "Xm Ys")
.TotalAPIDurationMSDurationMSTime spent waiting for API responses (formats as "Xm Ys")
.TotalLinesAddedintLines of code added in the session
.TotalLinesRemovedintLines of code removed in the session

上下文窗口属性

NameTypeDescription
.TotalInputTokensintTotal input tokens used in the session
.TotalOutputTokensintTotal output tokens generated in the session
.ContextWindowSizeintMaximum context window size for the model
.CurrentUsageCurrentUsageCurrent message token usage

当前用量属性

NameTypeDescription
.InputTokensintInput tokens for the current message
.OutputTokensintOutput tokens for the current message

速率限制属性

仅当 Claude 代码提供速率限制数据时可用(Pro/Max 订阅者)。通过 .RateLimits 访问。

NameTypeDescription
.FiveHourRateLimitWindow5-hour rolling window
.SevenDayRateLimitWindow7-day rolling window

速率限制窗口属性

NameTypeDescription
.UsedPercentage*float64Usage percentage (0-100), nil if unknown
.ResetsAt*int64Unix epoch seconds when window resets

百分比方法

Percentage 类型(由 .TokenUsagePercent.FiveHourUsage.SevenDayUsage 返回)提供了额外方法,可直接在模板中使用:

MethodReturnsDescription
.GaugestringVisual gauge showing remaining capacity using hardcoded / characters
.GaugeUsedstringVisual gauge showing used capacity using hardcoded / characters
.StringstringNumeric percentage value (e.g., "75" for use in templates)
自定义指示器字符

请使用 .TokenGauge.TokenGaugeUsed.FiveHourGauge.SevenDayGauge 替代上述原始的 .Percentage 方法——它们会遵循 gauge_marked_chargauge_unmarked_char 选项的配置。

工作原理

该组件从POSH_CLAUDE_STATUS环境变量读取会话信息,这些数据在使用oh-my-posh claude命令时自动设置,内容包括:

  • 当前 AI 模型信息

  • 令牌用量和上下文窗口使用率

  • 会话费用和持续时间

  • 工作区目录信息

仅当 Claude 代码处于活动状态并提供会话数据时,该组件才会显示。