Skip to content

Commit be61370

Browse files
garthvhclaude
andcommitted
windows app: 'Open in VS Code' menu item (parity with the Mac app)
Adds Open in VS Code next to Run Claude Code in Terminal. Finds Code.exe (user then machine install) and launches it with ANTHROPIC_BASE_URL/AUTH_TOKEN in the process env (UseShellExecute=false so the Environment dict applies), opening a %USERPROFILE%\fauxclaude-test workspace via a dedicated --user-data-dir so it's a separate instance that inherits the env even when VS Code is already running. Claude Code reads the endpoint from the process env, not settings.json, so it must be set at launch. Compile-checked with EnableWindowsTargeting on macOS (0 errors); needs a real Windows run to confirm. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 34a19da commit be61370

1 file changed

Lines changed: 51 additions & 0 deletions

File tree

windows-app/Program.cs

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ public TrayApp()
7676

7777
menu.Items.Add("Open Dashboard", null, (_, _) => OpenUrl($"{ShimUrl}/"));
7878
menu.Items.Add("Run Claude Code in Terminal", null, (_, _) => RunClaude());
79+
menu.Items.Add("Open in VS Code", null, (_, _) => OpenVSCode());
7980
menu.Items.Add("View Log", null, (_, _) => OpenLog());
8081
menu.Items.Add("Edit Model Map…", null, (_, _) => EditModelMap());
8182
menu.Items.Add(new ToolStripSeparator());
@@ -252,6 +253,56 @@ private void RunClaude()
252253
}
253254
}
254255

256+
// Open VS Code pointed at the shim. Claude Code (CLI or the VS Code extension)
257+
// reads ANTHROPIC_BASE_URL from its PROCESS environment — settings.json can't
258+
// redirect it — so we launch VS Code with the env set. A dedicated
259+
// --user-data-dir makes it a separate instance that reliably inherits the env
260+
// even if VS Code is already open (extensions are shared from the default
261+
// location). The shim ignores auth, so a dummy token stands in for the login.
262+
private void OpenVSCode()
263+
{
264+
if (_shim is not { HasExited: false } && !_running) StartShim();
265+
266+
var ws = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile), "fauxclaude-test");
267+
Directory.CreateDirectory(ws);
268+
var readme = Path.Combine(ws, "README.md");
269+
if (!File.Exists(readme))
270+
try { File.WriteAllText(readme, $"# FauxClaude local test workspace\r\n\r\nClaude Code here talks to your local FauxClaude shim ({ShimUrl}).\r\n"); }
271+
catch { /* best effort */ }
272+
273+
// Find Code.exe (user install first, then machine-wide).
274+
var lad = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
275+
string? code = null;
276+
foreach (var c in new[]
277+
{
278+
Path.Combine(lad, "Programs", "Microsoft VS Code", "Code.exe"),
279+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), "Microsoft VS Code", "Code.exe"),
280+
Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFilesX86), "Microsoft VS Code", "Code.exe"),
281+
})
282+
if (File.Exists(c)) { code = c; break; }
283+
284+
if (code == null)
285+
{
286+
MessageBox.Show($"VS Code (Code.exe) not found. Install it, or open this folder manually with " +
287+
$"ANTHROPIC_BASE_URL={ShimUrl} set:\n\n{ws}", "FauxClaude");
288+
return;
289+
}
290+
291+
var profile = Path.Combine(ws, ".vscode-profile");
292+
// UseShellExecute must be false so the Environment dictionary is applied.
293+
var psi = new ProcessStartInfo(code)
294+
{
295+
UseShellExecute = false,
296+
Arguments = $"\"{ws}\" --new-window --user-data-dir \"{profile}\"",
297+
};
298+
psi.Environment.Remove("ANTHROPIC_API_KEY");
299+
psi.Environment["ANTHROPIC_BASE_URL"] = ShimUrl;
300+
psi.Environment["ANTHROPIC_AUTH_TOKEN"] = "local"; // shim ignores auth; satisfies the client
301+
psi.Environment["CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC"] = "1";
302+
try { Process.Start(psi); }
303+
catch (Exception ex) { MessageBox.Show($"Couldn't open VS Code:\n{ex.Message}", "FauxClaude"); }
304+
}
305+
255306
private void ExitApp()
256307
{
257308
StopShim();

0 commit comments

Comments
 (0)