Skip to content

feat(cli): set terminal tab title from session title via OSC 0 - #17398

Closed
rumbin wants to merge 1 commit into
NousResearch:mainfrom
rumbin:feat/cli-terminal-title-from-session
Closed

feat(cli): set terminal tab title from session title via OSC 0#17398
rumbin wants to merge 1 commit into
NousResearch:mainfrom
rumbin:feat/cli-terminal-title-from-session

Conversation

@rumbin

@rumbin rumbin commented Apr 29, 2026

Copy link
Copy Markdown

Summary

When running multiple Hermes sessions in separate terminal tabs (e.g. Ghostty, iTerm2, Kitty), every tab shows the generic title Hermes. This PR makes each tab reflect the actual session title, so users can distinguish sessions at a glance.

What changes

agent/title_generator.py

  • Added an optional on_title callback parameter to auto_title_session and maybe_auto_title
  • After a title is successfully saved to the DB, the callback is invoked with the new title string
  • The callback is forwarded through the background thread kwargs so the thread result reaches the CLI

cli.py

  • Added HermesCLI._set_terminal_title(title) — emits the standard OSC 0 escape sequence ESC]0;Hermes: <title>BEL to stdout, which all modern terminals interpret as a tab/window title update
  • Wired it into all 5 title-setting paths:
    1. Auto-title after first exchange — passed as on_title callback to maybe_auto_title so the background thread updates the tab once the LLM-generated title is ready
    2. /title command — immediately updates the tab after saving a manually set title
    3. Pending title flush — updates the tab when a /title set before the first message is finally committed to the DB on session creation
    4. /resume command — sets the tab title when switching to an existing titled session mid-conversation
    5. Startup --continue resume — fetches and sets the tab title immediately on launch when loading an existing session

Behaviour

  • New session: tab shows Hermes → switches to Hermes: <generated title> a few seconds after the first exchange
  • hermes -c "my project": tab shows Hermes: my project immediately on startup
  • /title My Project: tab updates instantly
  • All OSC sequences go to sys.stdout directly — same approach as the existing _write_osc52_clipboard helper

Compatibility

OSC 0 is supported by virtually all modern terminal emulators (Ghostty, iTerm2, Kitty, GNOME Terminal, Windows Terminal, WezTerm, Alacritty, xterm). There is no visible side-effect in terminals that don't support it (the sequence is silently ignored).

Update the terminal tab/window title whenever the Hermes session title
changes, using the standard OSC 0 escape sequence supported by Ghostty,
iTerm2, Kitty, GNOME Terminal, and most modern terminals.

Changes:
- Add HermesCLI._set_terminal_title(title) that emits ESC]0;Hermes: <title>BEL
- Wire it into all 5 title-setting paths:
  1. Auto-generated title after first exchange (background thread via
     maybe_auto_title / auto_title_session on_title callback)
  2. /title command — immediate update on manual title set
  3. Pending title flush — when a /title set before first message is
     committed to the DB on session creation
  4. /resume command — sets the tab title of the resumed session
  5. Startup --continue resume — sets the tab on launch

Users with multiple Hermes tabs open can now distinguish sessions at a
glance instead of seeing 'Hermes' on every tab.
@alt-glitch alt-glitch added type/feature New feature or request P3 Low — cosmetic, nice to have comp/cli CLI entry point, hermes_cli/, setup wizard labels Apr 29, 2026
@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #10013 (prior attempt at OSC terminal tab titles) and #17148 (JetBrains terminal title request). May supersede #10013.

@alt-glitch

Copy link
Copy Markdown
Collaborator

Related to #10013 and #17148.

@rumbin

rumbin commented Apr 29, 2026

Copy link
Copy Markdown
Author

Thanks for the pointers @alt-glitch. After reviewing #10013, I can see tsemana's implementation is considerably more complete — dedicated module, persona-aware title format, sanitisation/injection protection, TTY guards, ACP no-op, and 16 unit tests. Our PR covers the same ground but less thoroughly. Closing in favour of #10013. Hopefully that one lands soon!

@rumbin rumbin closed this Apr 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp/cli CLI entry point, hermes_cli/, setup wizard P3 Low — cosmetic, nice to have type/feature New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants