How to Dynamically Set PuTTY Window Title to Session Name Using Configuration and Scripting


2 views

When working with multiple SSH connections to the same host through different ports (common in tunnel configurations), PuTTY's default behavior of displaying only the hostname in the window title becomes problematic. This happens because PuTTY automatically sets the window title to the remote hostname followed by "PuTTY" upon connection.

The most straightforward solution is to configure each saved session individually:

1. Open PuTTY Configuration
2. Load your target session
3. Navigate to: Window → Behavior
4. In "Window title" field, enter: %session
5. Save the session

The %session variable will be replaced with the actual session name when the connection is established.

For bulk updates or automated deployment, you can modify PuTTY's registry entries directly:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\YourSessionName]
"WinTitle"="%session"

For more control, combine PuTTY with a startup script:

#!/bin/bash
# ~/.bashrc or similar
echo -ne "\033]0;${PUTTY_SESSION:-$HOSTNAME}\007"

Then configure PuTTY to pass the session name:

1. Connection → Data → Auto-login username
2. Add to "Remote command":
   export PUTTY_SESSION=%session && bash --login

When scripting connections, you can use Plink with a custom title:

plink -load "SessionName" -m title_command.txt

# title_command.txt content:
echo -ne "\033]0;SessionName\007"

For Windows users managing multiple sessions:

$sessions = 'Tunnel-22','Tunnel-222','Tunnel-2222'
$sessions | ForEach-Object {
    reg add "HKCU\Software\SimonTatham\PuTTY\Sessions\$_" /v WinTitle /t REG_SZ /d "%session" /f
}

PuTTY's default window title behavior displays the remote hostname followed by "PuTTY" (e.g., server.example.com - PuTTY). While useful for standard SSH connections, this becomes problematic when:

  • Connecting to the same host via multiple ports (e.g., SSH tunnels on ports 22, 2222, 22222)
  • Managing numerous saved sessions with identical hostnames

To automatically use the session name as window title:

  1. Launch PuTTY and load your target session
  2. Navigate to: Window → Behavior
  3. In "Window title" field, enter: %sessionname% - PuTTY
  4. Return to "Session" category and click Save

For power users managing multiple sessions, modify Windows Registry:

Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\your_session_name]
"WinTitle"="%sessionname% - PuTTY"

To apply globally across all sessions:

[HKEY_CURRENT_USER\Software\SimonTatham\PuTTY\Sessions\Default%20Settings]
"WinTitle"="%sessionname% - PuTTY"

When launching from command line or scripts:

putty.exe -load "session_name" -cmd "echo -ne '\\033]0;session_name\\007'"
  • Dynamic updates: The title updates only at connection start. For real-time changes, combine with shell prompts (e.g., add to .bashrc):
    PS1="\\[\\e]0;\\u@${PWD}\\a\\]$PS1"
  • Special characters: Escape percent signs in batch files as %%sessionname%%

For dynamic window management:

#IfWinActive ahk_class PuTTY
    SetTitleMatchMode, 2
    WinGet, active_id, ID, A
    WinGetTitle, current_title, ahk_id %active_id%
    StringReplace, new_title, current_title, "PuTTY", "%sessionname% - PuTTY"
    WinSetTitle, ahk_id %active_id%, , %new_title%
#IfWinActive