Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions packages/opencode/src/cli/cmd/tui/component/prompt/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -201,15 +201,17 @@ export function Prompt(props: PromptProps) {
const last = msg.findLast((item): item is AssistantMessage => item.role === "assistant" && item.tokens.output > 0)
if (!last) return

const cached = last.tokens.cache.read + last.tokens.cache.write
const tokens =
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
last.tokens.input + last.tokens.output + last.tokens.reasoning + cached
if (tokens <= 0) return

const model = sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
const pct = model?.limit.context ? `${Math.round((tokens / model.limit.context) * 100)}%` : undefined
const cost = msg.reduce((sum, item) => sum + (item.role === "assistant" ? item.cost : 0), 0)
const tokenText = cached > 0 ? `${Locale.number(tokens)} (${Locale.number(cached)} cached)` : Locale.number(tokens)
return {
context: pct ? `${Locale.number(tokens)} (${pct})` : Locale.number(tokens),
context: pct ? `${tokenText} (${pct})` : tokenText,
cost: cost > 0 ? money.format(cost) : undefined,
}
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,34 @@ function View(props: { api: TuiPluginApi; session_id: string }) {
if (!last) {
return {
tokens: 0,
cached: 0,
percent: null,
}
}

const cached = last.tokens.cache.read + last.tokens.cache.write
const tokens =
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
last.tokens.input + last.tokens.output + last.tokens.reasoning + cached
const model = props.api.state.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
return {
tokens,
cached,
percent: model?.limit.context ? Math.round((tokens / model.limit.context) * 100) : null,
}
})

const tokenText = createMemo(() => {
const cached = state().cached
if (cached === 0) return `${state().tokens.toLocaleString()} tokens`
return `${state().tokens.toLocaleString()} tokens (${cached.toLocaleString()} cached)`
})

return (
<box>
<text fg={theme().text}>
<b>Context</b>
</text>
<text fg={theme().textMuted}>{state().tokens.toLocaleString()} tokens</text>
<text fg={theme().textMuted}>{tokenText()}</text>
<text fg={theme().textMuted}>{state().percent ?? 0}% used</text>
<text fg={theme().textMuted}>{money.format(cost())} spent</text>
</box>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export function SubagentFooter() {
const last = msg.findLast((item): item is AssistantMessage => item.role === "assistant" && item.tokens.output > 0)
if (!last) return

const cached = last.tokens.cache.read + last.tokens.cache.write
const tokens =
last.tokens.input + last.tokens.output + last.tokens.reasoning + last.tokens.cache.read + last.tokens.cache.write
last.tokens.input + last.tokens.output + last.tokens.reasoning + cached
if (tokens <= 0) return

const model = sync.data.provider.find((item) => item.id === last.providerID)?.models[last.modelID]
Expand All @@ -49,8 +50,9 @@ export function SubagentFooter() {
currency: "USD",
})

const tokenText = cached > 0 ? `${Locale.number(tokens)} (${Locale.number(cached)} cached)` : Locale.number(tokens)
return {
context: pct ? `${Locale.number(tokens)} (${pct})` : Locale.number(tokens),
context: pct ? `${tokenText} (${pct})` : tokenText,
cost: cost > 0 ? money.format(cost) : undefined,
}
})
Expand Down
1 change: 1 addition & 0 deletions packages/opencode/src/plugin/codex.ts
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,7 @@ export async function CodexAuthPlugin(input: PluginInput): Promise<Hooks> {
"gpt-5.3-codex",
"gpt-5.4",
"gpt-5.4-mini",
"gpt-5.5",
])
for (const [modelId, model] of Object.entries(provider.models)) {
if (modelId.includes("codex")) continue
Expand Down
Loading