Revision: 1 Last modified: 2026-12-04T19:00:00Z
title.sh sets the terminal window/tab title (OSC 0) to the live §11.4.182 label of an entity, a
session, or an explicit string.
It exists so that with several shells, agents and sessions open, the title bar tells you which is which —
(T1/main - claude4 - opus - high) rather than a bare bash.
Three properties make it safe to call from anywhere:
- Safe in a non-tty — it writes nothing and exits
0. - Safe under
tmuxandscreen— the escape sequence is emitted through the right sink rather than being mangled by the multiplexer. 0always — a title is cosmetic and must never fail a caller. A failedtitle.shinside a prompt hook would be a bug about decoration taking down a session.
bash,jq;render/lib.shbeside it (sourced).- A label-sync snapshot in
$LABEL_SYNC_DIRfor--entity/--sessionforms. - No files are required for the
--textform.
Environment variables (names only):
| Variable | Meaning |
|---|---|
LABEL_SYNC_DIR |
State dir holding snapshot.json (see CONTRACT.md). |
LABEL_SYNC_TITLE_SINK |
Default sink file for the escape sequence. |
TERM, TMUX, STY |
Terminal / multiplexer detection. |
LABEL_SYNC_SHELL_ID |
Default entity when --entity is omitted. |
CLAUDE_CODE_SESSION_ID |
Session used when neither --entity nor --session is given. |
# set the title from an explicit string
bash scripts/label-sync/render/title.sh --text "build: gates"
# title this shell's entity (default from LABEL_SYNC_SHELL_ID)
bash scripts/label-sync/render/title.sh
# title a specific entity or session
bash scripts/label-sync/render/title.sh --entity "$entity_id"
bash scripts/label-sync/render/title.sh --session "$CLAUDE_CODE_SESSION_ID"
# write to a sink file instead of the tty
bash scripts/label-sync/render/title.sh --sink /tmp/title.out
# pass the sequence through unwrapped
bash scripts/label-sync/render/title.sh --passthrough| Flag | Meaning |
|---|---|
--text T |
Use an explicit title string. |
--entity ID |
Title the named entity. |
--session SID |
Title the named session. |
--sink FILE |
Write the escape sequence to FILE instead of a tty. |
--passthrough |
Emit the sequence without the standard wrapping. |
The three selectors are mutually exclusive in intent; the resolution order is: explicit --text, then
--entity, then --session, then the defaults ($LABEL_SYNC_SHELL_ID, else $CLAUDE_CODE_SESSION_ID).
| Code | Meaning |
|---|---|
0 |
Always. A title is cosmetic and must never fail a caller. |
There is no failure code by design. A caller that needs to know whether a title was written must inspect
the sink, because "no title written" and "title written" both exit 0.
The OSC 0 escape sequence, written to the sink file when --sink is given, or to stdout/stderr only if
one of them is a tty. Otherwise nothing is written at all.
- Not a tty and no
--sink. Writes nothing, exits0— the reason it is safe in CI and in hooks. - Under
tmux/screen. The sequence is routed appropriately rather than being interpreted by the outer terminal. - Nothing resolvable (no
--text, no entity, noLABEL_SYNC_SHELL_ID, no session id). The title is left alone — it does not clear or overwrite an existing title with a placeholder. - A snapshot that is down. The entity/session form cannot resolve, so the title is left alone.
- A label containing control characters. Sanitised via
ls_sanitize— a title is an escape-sequence context, which is exactly where unsanitised text is dangerous. --sinkto an unwritable path. The write fails but the exit status stays0; titles are cosmetic.--passthroughwith a non-tty. Still writes nothing unless a tty or sink is present.
- Sources
render/lib.sh. - Resolves the title text:
--text, elsels_entity_labelfor--entity/--session, else the default ids. - If nothing resolves, returns without writing (title untouched).
- Sanitises the text with
ls_sanitize. - Delegates to
ls_emit_title, which selects the sink (explicit file, else a tty) and writes the OSC 0 sequence. - Exits
0.
Sources scripts/label-sync/render/lib.sh.
Sibling renderers: scripts/label-sync/render/statusline.sh,
scripts/label-sync/render/tmux-status.sh, scripts/label-sync/render/shell-hook.sh (which typically
calls title.sh on each prompt), scripts/label-sync/render/watch-labels.sh.
Cross-reference: docs/label-sync/CONTRACT.md, docs/label-sync/RENDERERS.md.
See also docs/scripts/lib.md, docs/scripts/statusline.md and
docs/scripts/track_branch_label.md.
2026-12-04 — bash -n scripts/label-sync/render/title.sh → exit 0. bash scripts/label-sync/render/title.sh --text "probe" --sink /tmp/title-probe.out exits 0 and writes the
OSC 0 sequence to the sink file.