@@ -327,11 +327,13 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
327327 turnIndex = 1;
328328 totalIn = 0;
329329 totalOut = 0;
330+ lastContextTokens = 0;
330331 },
331332 };
332333 const spinner = new Spinner();
333334 let totalIn = 0;
334335 let totalOut = 0;
336+ let lastContextTokens = 0;
335337
336338 // ── Handle initial prompt (non-interactive) ────────────────────────────────
337339 if (opts.initialPrompt) {
@@ -340,6 +342,10 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
340342
341343 // ── REPL ──────────────────────────────────────────────────────────────────
342344 while (true) {
345+ // Render the status bar to stdout before drawing the prompt so both are on
346+ // the same stream, guaranteeing correct ordering (no stderr/stdout race).
347+ await renderStatusBarForSession();
348+
343349 let input: InputResult;
344350 try {
345351 input = await readline({ cwd });
@@ -455,9 +461,12 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
455461
456462 totalIn += inputTokens;
457463 totalOut += outputTokens;
464+ lastContextTokens = contextTokens;
458465 touchActiveSession(session);
466+ }
459467
460- // Render status bar
468+ // ── Render status bar (called before each prompt) ──────────────────────────
469+ async function renderStatusBarForSession(): Promise<void> {
461470 const branch = await getGitBranch(cwd);
462471 const provider = currentModel.split("/")[0] ?? "";
463472 const modelShort = currentModel.split("/").slice(1).join("/");
@@ -471,9 +480,9 @@ export async function runAgent(opts: AgentOptions): Promise<void> {
471480 cwd: cwdDisplay,
472481 gitBranch: branch,
473482 sessionId: session.id,
474- inputTokens,
475- outputTokens,
476- contextTokens,
483+ inputTokens: totalIn,
484+ outputTokens: totalOut,
485+ contextTokens: lastContextTokens,
477486 contextWindow: getContextWindow(currentModel),
478487 });
479488 }