Claude 代码
非官方测试版翻译
本页面由 PageTurner AI 翻译(测试版)。未经项目官方认可。 发现错误? 报告问题 →
功能
显示 Claude 代码会话信息,包括当前 AI 模型、令牌用量、费用和工作区详情。 通过可视化上下文窗口用量指示器和格式化的费用/令牌信息,方便您监控 Claude 使用情况。
该组件与 Claude 代码的状态行功能 集成,可在提示符中提供实时会话数据。
示例配置
- json
- yaml
- toml
{
"type": "claude",
"style": "diamond",
"leading_diamond": "",
"trailing_diamond": "",
"foreground": "#FFFFFF",
"background": "#FF6B35",
"template": " {{ .Model.DisplayName }} {{ .TokenUsagePercent.Gauge }} "
}
type: claude
style: diamond
leading_diamond:
trailing_diamond:
foreground: "#FFFFFF"
background: "#FF6B35"
template: " {{ .Model.DisplayName }} {{ .TokenUsagePercent.Gauge }} "
type = "claude"
style = "diamond"
leading_diamond = ""
trailing_diamond = ""
foreground = "#FFFFFF"
background = "#FF6B35"
template = " {{ .Model.DisplayName }} {{ .TokenUsagePercent.Gauge }} "
模板 (信息)
默认模板
\udb82\udfc9 {{ .Model.DisplayName }} \uf2d0 {{ .TokenUsagePercent.Gauge }}
属性
| Name | Type | Description |
|---|---|---|
.SessionID | string | Unique identifier for the Claude session |
.Model | Model | AI model information |
.Workspace | Workspace | Workspace directory information |
.Cost | Cost | Cost and duration information |
.ContextWindow | ContextWindow | Token usage information |
.TokenUsagePercent | Percentage | Percentage of context window used (0-100) |
.FormattedCost | string | Formatted cost string (e.g., "$0.15" or "$0.0012") |
.FormattedTokens | string | Human-readable token count (e.g., "1.2K", "15.3M") |
模型属性
| Name | Type | Description |
|---|---|---|
.ID | string | Technical model identifier |
.DisplayName | string | Human-readable model name (e.g., "Claude 3.5 Sonnet") |
工作区属性
| Name | Type | Description |
|---|---|---|
.CurrentDir | string | Current working directory |
.ProjectDir | string | Root project directory |
费用属性
| Name | Type | Description |
|---|---|---|
.TotalCostUSD | float64 | Total cost in USD |
.TotalDurationMS | int64 | Total session duration in milliseconds |
上下文窗口属性
| Name | Type | Description |
|---|---|---|
.TotalInputTokens | int | Total input tokens used in the session |
.TotalOutputTokens | int | Total output tokens generated in the session |
.ContextWindowSize | int | Maximum context window size for the model |
.CurrentUsage | CurrentUsage | Current message token usage |
当前用量属性
| Name | Type | Description |
|---|---|---|
.InputTokens | int | Input tokens for the current message |
.OutputTokens | int | Output tokens for the current message |
百分比方法
TokenUsagePercent属性属于Percentage类型,提供以下附加功能:
| Method | Returns | Description |
|---|---|---|
.Gauge | string | Visual gauge showing remaining capacity using 5 bar blocks (▰▰▰▰▱) |
.GaugeUsed | string | Visual gauge showing used capacity using 5 bar blocks (▰▱▱▱▱) |
.String | string | Numeric percentage value (e.g., "75" for use in templates) |
工作原理
该组件从POSH_CLAUDE_STATUS环境变量读取会话信息,这些数据在使用oh-my-posh claude命令时自动设置,内容包括:
-
当前 AI 模型信息
-
令牌用量和上下文窗口使用率
-
会话费用和持续时间
-
工作区目录信息
仅当 Claude 代码处于活动状态并提供会话数据时,该组件才会显示。