Repository: microsoft/terminal (language: cpp)

Issue:
`-d .` doesn't work (WT Preview 1.23.10353.0)

### Discussed in https://github.com/microsoft/terminal/discussions/18631

<div type='discussions-op-text'>

<sup>Originally posted by **rctlmk** February 26, 2025</sup>
Hello,
It seems that `-d .` doesn't seem to work anymore:

https://github.com/user-attachments/assets/d14f5902-18d1-4b66-91fa-47539cf8c49a

I'm on Win11 build 26100.2161, WT Preview 1.23.10353.0 with the default profile. Also, `wt -d ..` will open at `C:\Windows`, regardless of the current directory.

On regular WT (1.21.10351.0) everything works as expected.
</div>


Discussion / hints:
I presume"me too" style comments are not helpful, but... Win 11 10.0.26100.3476, WT Preview 1.23.10732.0.

This effectively breaks [GitHub Desktop's "Open In Windows Terminal" shortcut](https://github.com/desktop/desktop/blob/7f36d6e5feb803ea08b5393fc9ec5f679c38e7b1/app/src/lib/shells/win32.ts#L475).

Fix patch:
diff --git a/src/cascadia/TerminalApp/Remoting.cpp b/src/cascadia/TerminalApp/Remoting.cpp
index 8383fb98fd2..0c8693ed46a 100644
--- a/src/cascadia/TerminalApp/Remoting.cpp
+++ b/src/cascadia/TerminalApp/Remoting.cpp
@@ -17,7 +17,7 @@ namespace winrt::TerminalApp::implementation
 {
     CommandlineArgs::CommandlineArgs(winrt::array_view<const winrt::hstring> args, winrt::hstring currentDirectory, uint32_t showWindowCommand, winrt::hstring envString) :
         _args{ args.begin(), args.end() },
-        _cwd{ std::move(currentDirectory) },
+        CurrentDirectory{ std::move(currentDirectory) },
         ShowWindowCommand{ showWindowCommand },
         CurrentEnvironment{ std::move(envString) }
     {
diff --git a/src/cascadia/TerminalApp/Remoting.h b/src/cascadia/TerminalApp/Remoting.h
index a86619c4dc2..2ad297f31e2 100644
--- a/src/cascadia/TerminalApp/Remoting.h
+++ b/src/cascadia/TerminalApp/Remoting.h
@@ -36,7 +36,6 @@ namespace winrt::TerminalApp::implementation
         ::TerminalApp::AppCommandlineArgs _parsed;
         int32_t _parseResult = 0;
         winrt::com_array<winrt::hstring> _args;
-        winrt::hstring _cwd;
     };
 
     struct RequestReceiveContentArgs : RequestReceiveContentArgsT<RequestReceiveContentArgs>
diff --git a/src/cascadia/TerminalApp/TerminalPage.cpp b/src/cascadia/TerminalApp/TerminalPage.cpp
index fb061e548cc..581b0ddcf35 100644
--- a/src/cascadia/TerminalApp/TerminalPage.cpp
+++ b/src/cascadia/TerminalApp/TerminalPage.cpp
@@ -563,8 +563,11 @@ namespace winrt::TerminalApp::implementation
                 _WindowProperties.VirtualEnvVars(originalVirtualEnv);
             }
         });
-        _WindowProperties.VirtualWorkingDirectory(cwd);
-        _WindowProperties.VirtualEnvVars(env);
+        if (!cwd.empty())
+        {
+            _WindowProperties.VirtualWorkingDirectory(cwd);
+            _WindowProperties.VirtualEnvVars(env);
+        }
 
         for (size_t i = 0; i < actions.size(); ++i)
         {


Test patch: