跳转到主内容

GitHub Copilot CLI

非官方测试版翻译

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

功能

Display GitHub Copilot CLI session information including the current AI model, token usage, and workspace details. Shows a visual gauge of context window usage and formatted token/duration information for monitoring your Copilot CLI session.

This segment integrates with GitHub Copilot CLI's statusline functionality to provide real-time session data in your prompt.

For setup instructions, see Change your prompt.

示例配置

{
"type": "copilot_cli",
"style": "diamond",
"leading_diamond": "",
"trailing_diamond": "",
"foreground": "#111111",
"background": "#fee898",
"template": "  {{ .Model.DisplayName }}  {{ .TokenGauge }} "
}

模板 (信息)

default template
\uec1e {{ .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
.SessionIDstringUnique identifier for the Copilot CLI session
.SessionNamestringCustom session name; empty when absent
.TranscriptPathstringPath to the session transcript directory
.ModelModelAI model information
.WorkspaceWorkspaceWorkspace directory information
.RemoteRemoteRemote connection state
.VersionstringCopilot CLI version
.UsernamestringAuthenticated username; empty when absent
.CostCostDuration and line-change information
.ContextWindowContextWindowToken usage information
.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., ▰▰▱▱▱)
.RemainingPercentPercentagePercentage of context window remaining (0-100)
.RemainingTokensCountintNumber of remaining context window tokens; 0 when context window size is unknown
.FormattedTokensstringHuman-readable token count (e.g., "1.2K", "15.3M")
.FormattedDurationstringTotal session duration (e.g., "2m 5s")
.FormattedAPIDurationstringAPI wait time (e.g., "0m 45s")

模型属性

NameTypeDescription
.IDstringTechnical model identifier
.DisplayNamestringHuman-readable model name (e.g., "claude-sonnet-4.6 (medium)")

工作区属性

NameTypeDescription
.CurrentDirstringCurrent working directory

Remote Properties

NameTypeDescription
.ConnectedboolWhether a remote connection is active

费用属性

NameTypeDescription
.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
.TotalPremiumRequestsintNumber of premium model requests made in the session

上下文窗口属性

NameTypeDescription
.ContextWindowSize*intMaximum context window size; nil when unknown
.UsedPercentage*float64Percentage used (0-100); nil when unknown
.RemainingPercentage*float64Percentage remaining (0-100); nil when unknown
.RemainingTokens*intRemaining token count; nil when unknown
.CurrentContextTokensintTokens in the current active context
.TotalInputTokensintTotal input tokens used in the session
.TotalOutputTokensintTotal output tokens generated in the session
.TotalCacheReadTokensintTotal tokens read from cache
.TotalCacheWriteTokensintTotal tokens written to cache
.TotalReasoningTokensintTotal reasoning tokens used in the session
.TotalTokensintGrand total of all tokens used in the session
.LastCallInputTokensintInput tokens for the most recent API call
.LastCallOutputTokensintOutput tokens for the most recent API call

百分比方法

The Percentage type (returned by .TokenUsagePercent, .RemainingPercent) provides additional methods for direct use in templates:

MethodReturnsDescription
.GaugestringVisual gauge showing remaining capacity using hardcoded / characters
.GaugeUsedstringVisual gauge showing used capacity using hardcoded / characters
.StringstringNumeric percentage value (e.g., "75")
Custom gauge characters

Use .TokenGauge and .TokenGaugeUsed instead of the raw .Percentage methods above — they respect the gauge_marked_char and gauge_unmarked_char options.

工作原理

The oh-my-posh copilot command reads GitHub Copilot CLI's session JSON from stdin, caches the parsed data, then renders your configured prompt. Copilot CLI sends a fresh JSON payload on every statusline refresh.

The segment is only visible when Copilot CLI is actively providing session data.