<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>~iany/ Windows Terminal</title><link>https://blog.iany.me/tags/windows-terminal/</link><description>Recent content in Windows Terminal «~iany/»</description><language>en-US</language><managingEditor>me@iany.me (Ian Yang)</managingEditor><webMaster>me@iany.me (Ian Yang)</webMaster><copyright>CC-BY-SA 4.0</copyright><lastBuildDate>Thu, 29 Jan 2026 23:30:42 +0800</lastBuildDate><atom:link href="https://blog.iany.me/tags/windows-terminal/index.xml" rel="self" type="application/rss+xml"/><item><title>Use tmux for PowerShell in Windows Terminal</title><link>https://blog.iany.me/2026/01/use-tmux-for-powershell-in-windows-terminal/</link><pubDate>Thu, 29 Jan 2026 23:30:42 +0800</pubDate><author>me@iany.me (Ian Yang)</author><guid>https://blog.iany.me/2026/01/use-tmux-for-powershell-in-windows-terminal/</guid><description>&lt;p&gt;You can get tmux session persistence and multiplexing in Windows Terminal by running tmux inside WSL and setting the default shell to PowerShell. New panes and windows will then start &lt;code&gt;pwsh.exe&lt;/code&gt; instead of a Linux shell. Here’s a minimal setup using small wrappers and the &lt;code&gt;tmux -C attach&lt;/code&gt; trick to configure new sessions.&lt;/p&gt;
&lt;h2 id="why-tmux-under-wsl-with-powershell"&gt;Why tmux under WSL with PowerShell?&lt;/h2&gt;
&lt;p&gt;Since tmux does not run natively on Windows, the standard approach is to use it through WSL. However, if you launch &lt;code&gt;wsl tmux&lt;/code&gt; from Windows Terminal, all panes will default to your WSL shell. When working in a Windows directory, I prefer to use native PowerShell within the Windows environment.&lt;/p&gt;
&lt;p&gt;To ensure every tmux pane runs PowerShell, configure tmux to use &lt;code&gt;pwsh.exe&lt;/code&gt; as its default command. When you launch &lt;code&gt;pwsh.exe&lt;/code&gt; from WSL within a Windows directory, it brings us back to the Windows environment.&lt;/p&gt;
&lt;h2 id="wrappers-so-you-can-call-tmux-from-powershell"&gt;Wrappers so you can call tmux from PowerShell&lt;/h2&gt;
&lt;p&gt;Put these in a directory on your &lt;code&gt;PATH&lt;/code&gt; (e.g. &lt;code&gt;~/Documents/PowerShell/bin&lt;/code&gt;).&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;PowerShell&lt;/strong&gt; — &lt;code&gt;tmux.ps1&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;wsl tmux $args
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Cmd&lt;/strong&gt; — &lt;code&gt;tmux.cmd&lt;/code&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-batch"&gt;@echo off
wsl tmux %*
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;From PowerShell or Cmd you can then run &lt;code&gt;tmux new&lt;/code&gt;, &lt;code&gt;tmux attach&lt;/code&gt;, etc., and they all go to WSL’s tmux.&lt;/p&gt;
&lt;h2 id="creating-powershell-sessions"&gt;Creating PowerShell Sessions&lt;/h2&gt;
&lt;p&gt;The next piece is a script that creates a new session whose default command is &lt;code&gt;pwsh.exe&lt;/code&gt;, or attaches if that session already exists. Example usage: &lt;code&gt;tmux-pwsh dev&lt;/code&gt; or &lt;code&gt;tmux-pwsh work&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;The script sets the default command only for sessions it creates; it does not affect sessions started with a standard &lt;code&gt;tmux new-session&lt;/code&gt;.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;&lt;code&gt;tmux-pwsh.ps1&lt;/code&gt;&lt;/strong&gt;:&lt;/p&gt;
&lt;pre&gt;&lt;code class="language-powershell"&gt;param(
[Parameter(Mandatory=$true)]
[string]$SessionName
)
$pwshCommand = &amp;quot;exec pwsh.exe -nologo&amp;quot;
# Check if session exists using exact name match
wsl tmux has-session -t &amp;quot;\=$SessionName&amp;quot; 2&amp;gt;$null
if ($LASTEXITCODE -ne 0) {
wsl tmux new-session -d -s $SessionName $pwshCommand
echo &amp;quot;set-option default-command `&amp;quot;$pwshCommand`&amp;quot;&amp;quot; | `
wsl tmux -C attach -t &amp;quot;\=$SessionName&amp;quot; &amp;gt;$null
}
wsl tmux attach -t &amp;quot;\=$SessionName&amp;quot;
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Note:&lt;/p&gt;
&lt;ol&gt;
&lt;li&gt;The &lt;code&gt;=&lt;/code&gt; prefix does an exact session name match and must be escaped when sending the command from PowerShell to WSL.&lt;/li&gt;
&lt;li&gt;The new session specifies command &lt;code&gt;pwsh.exe&lt;/code&gt; via the command argument.&lt;/li&gt;
&lt;li&gt;Running &lt;code&gt;wsl tmux set-option&lt;/code&gt; immediately after creating the session does not work because there&amp;rsquo;s a brief window where the session is not available for setting options. Instead, sending &lt;code&gt;set-option&lt;/code&gt; via &lt;code&gt;tmux -C attach&lt;/code&gt; reliably applies the setting.&lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;After this, splitting panes and creating new windows in that session will all start &lt;code&gt;pwsh.exe -nologo&lt;/code&gt; in Windows Terminal.&lt;/p&gt;
&lt;h2 id="summary"&gt;Summary&lt;/h2&gt;
&lt;ul&gt;
&lt;li&gt;Use WSL for tmux and PowerShell as the default command by setting tmux’s default command to &lt;code&gt;exec pwsh.exe -nologo&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tmux.ps1&lt;/code&gt;&lt;/strong&gt; / &lt;strong&gt;&lt;code&gt;tmux.cmd&lt;/code&gt;&lt;/strong&gt; — thin wrappers so &lt;code&gt;tmux&lt;/code&gt; from Windows means &lt;code&gt;wsl tmux&lt;/code&gt;.&lt;/li&gt;
&lt;li&gt;&lt;strong&gt;&lt;code&gt;tmux-pwsh.ps1 &amp;lt;name&amp;gt;&lt;/code&gt;&lt;/strong&gt; — create (or attach to) a named session that uses PowerShell as the default command.&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Once these are on your &lt;code&gt;PATH&lt;/code&gt;, run e.g. &lt;code&gt;tmux-pwsh dev&lt;/code&gt; from Windows Terminal to get a tmux session where every pane is PowerShell.&lt;/p&gt;</description><category domain="https://blog.iany.me/post/">Posts</category><category domain="https://blog.iany.me/tags/tmux/">Tmux</category><category domain="https://blog.iany.me/tags/powershell/">PowerShell</category><category domain="https://blog.iany.me/tags/wsl/">WSL</category><category domain="https://blog.iany.me/tags/windows-terminal/">Windows Terminal</category></item></channel></rss>