Skip to content

Commit b018221

Browse files
feat(tui): add configurable terminal title with status indicator
Add terminal_title config option with template placeholders: %n - session name %s - BUSY/IDLE status %m - current model %a - current agent Example: terminal_title = "[%s] OC | %n" Default behavior unchanged - without config, title remains "OC | <session>". Closes anomalyco#4539
1 parent e66d829 commit b018221

3 files changed

Lines changed: 26 additions & 2 deletions

File tree

‎packages/opencode/src/cli/cmd/tui/app.tsx‎

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,6 +264,7 @@ function App() {
264264
// Update terminal window title based on current route and session
265265
createEffect(() => {
266266
if (!terminalTitleEnabled() || Flag.OPENCODE_DISABLE_TERMINAL_TITLE) return
267+
const format = sync.data.config.terminal_title
267268

268269
if (route.data.type === "home") {
269270
renderer.setTerminalTitle("OpenCode")
@@ -278,8 +279,21 @@ function App() {
278279
}
279280

280281
// Truncate title to 40 chars max
281-
const title = session.title.length > 40 ? session.title.slice(0, 37) + "..." : session.title
282-
renderer.setTerminalTitle(`OC | ${title}`)
282+
const name = session.title.length > 40 ? session.title.slice(0, 37) + "..." : session.title
283+
284+
if (!format) {
285+
renderer.setTerminalTitle(`OC | ${name}`)
286+
return
287+
}
288+
289+
const status = sync.session.status(route.data.sessionID) === "idle" ? "IDLE" : "BUSY"
290+
const model = local.model.current()
291+
const title = format
292+
.replace(/%n/g, name)
293+
.replace(/%s/g, status)
294+
.replace(/%m/g, model ? `${model.providerID}/${model.modelID}` : "")
295+
.replace(/%a/g, local.agent.current().name)
296+
renderer.setTerminalTitle(title)
283297
}
284298
})
285299

‎packages/opencode/src/config/config.ts‎

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1127,6 +1127,12 @@ export namespace Config {
11271127
},
11281128
),
11291129
instructions: z.array(z.string()).optional().describe("Additional instruction files or patterns to include"),
1130+
terminal_title: z
1131+
.string()
1132+
.optional()
1133+
.describe(
1134+
"Terminal title format. Placeholders: %n (session name), %s (BUSY/IDLE status), %m (model), %a (agent). Example: '[%s] OC | %n'",
1135+
),
11301136
layout: Layout.optional().describe("@deprecated Always uses stretch layout."),
11311137
permission: Permission.optional(),
11321138
tools: z.record(z.string(), z.boolean()).optional(),

‎packages/sdk/js/src/v2/gen/types.gen.ts‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1449,6 +1449,10 @@ export type Config = {
14491449
* Additional instruction files or patterns to include
14501450
*/
14511451
instructions?: Array<string>
1452+
/**
1453+
* Terminal title format. Placeholders: %n (session name), %s (BUSY/IDLE status), %m (model), %a (agent). Example: '[%s] OC | %n'
1454+
*/
1455+
terminal_title?: string
14521456
layout?: LayoutConfig
14531457
permission?: PermissionConfig
14541458
tools?: {

0 commit comments

Comments
 (0)