@@ -6,6 +6,7 @@ import { getContextWindow } from "../llm-api/providers.ts";
66 import { getGitBranch, runShellPassthrough } from "./cli-helpers.ts";
77 import { handleCommand } from "./commands.ts";
88 import { resolveFileRefs } from "./file-refs.ts";
9+import { createGitBranchCache } from "./git-branch-cache.ts";
910 import { type InputResult, readline } from "./input.ts";
1011 import { tildePath } from "./output.ts";
1112 import { buildStatusBarSignature } from "./status-bar.ts";
@@ -23,9 +24,14 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
2324 const { cwd, reporter, cmdCtx, runner } = opts;
2425
2526 let lastStatusSignature: string | null = null;
27+ const gitBranchCache = createGitBranchCache({
28+ cwd,
29+ fetchBranch: getGitBranch,
30+ });
31+ await gitBranchCache.refresh(true);
2632
2733 while (true) {
28- const branch = await getGitBranch(cwd);
34+ const branch = gitBranchCache.get();
2935 const status = runner.getStatusInfo();
3036 const provider = status.model.split("/")[0] ?? "";
3137 const modelShort = status.model.split("/").slice(1).join("/");
@@ -64,6 +70,7 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
6470 return;
6571
6672 case "interrupt":
73+ gitBranchCache.refreshInBackground();
6774 continue;
6875
6976 case "command": {
@@ -81,6 +88,7 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
8188 // Error already rendered by stream-render; continue the loop.
8289 }
8390 }
91+ gitBranchCache.refreshInBackground();
8492 continue;
8593 }
8694
@@ -89,6 +97,7 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
8997 if (out) {
9098 runner.addShellContext(input.command, out);
9199 }
100+ gitBranchCache.refreshInBackground(true);
92101 continue;
93102 }
94103
@@ -103,6 +112,7 @@ export async function runInputLoop(opts: InputLoopOptions): Promise<void> {
103112 } catch {
104113 // Error already rendered by stream-render; continue the loop.
105114 }
115+ gitBranchCache.refreshInBackground();
106116 continue;
107117 }
108118 }