Skip to content

Feature Request: Click-to-Focus support for WindowsΒ #36

@gonnector

Description

@gonnector

Summary

macOS and Linux both support click-to-focus (clicking a notification brings the originating terminal window to the foreground), but the docs currently state:

Windows: Notifications only, no click-to-focus.

This request is to bring click-to-focus parity to Windows.

Use Case

On Windows it's common to run multiple terminal windows simultaneously (Windows Terminal tabs, Git Bash, PowerShell, etc.). When a Claude Code notification fires, there is no way to jump to the specific terminal that sent it β€” you have to hunt for it manually.

Proposed Implementation

Windows provides Win32 APIs that can focus a window by handle or title. A PowerShell one-liner already works in practice:

# Bring window to foreground by partial title match
Add-Type @"
using System;
using System.Runtime.InteropServices;
public class WinFocus {
    [DllImport("user32.dll")] public static extern bool SetForegroundWindow(IntPtr h);
    [DllImport("user32.dll")] public static extern bool ShowWindow(IntPtr h, int n);
    [DllImport("user32.dll")] public static extern IntPtr FindWindow(string cls, string title);
}
"@
$hwnd = [WinFocus]::FindWindow($null, "WINDOW_TITLE")
[WinFocus]::ShowWindow($hwnd, 9)   # SW_RESTORE
[WinFocus]::SetForegroundWindow($hwnd)

Alternatively, Go has golang.org/x/sys/windows which exposes SetForegroundWindow, FindWindow, and EnumWindows natively β€” no cgo or PowerShell subprocess needed.

Suggested approach (Go-native)

  1. At hook time, record the working directory (cwd) and the parent process ID of the hook-wrapper shell.
  2. Walk the window list with EnumWindows and match by:
    • Window title containing the folder name (works for Windows Terminal, Git Bash, PowerShell)
    • Or by PID via GetWindowThreadProcessId
  3. Call ShowWindow(hwnd, SW_RESTORE) + SetForegroundWindow(hwnd) on match.
  4. Fall back gracefully (no crash) if no matching window is found.

Terminal emulators to target

Terminal Title format
Windows Terminal contains folder name or profile name
Git Bash (MINGW) MINGW64:/path or custom title
PowerShell Windows PowerShell or custom
cmd.exe Command Prompt or custom
ConEmu / Cmder configurable, usually contains path
VSCode integrated terminal handled by existing focus-window subcommand

Config suggestion

Reuse the existing clickToFocus flag β€” no new config keys needed:

{
  "notifications": {
    "desktop": {
      "clickToFocus": true
    }
  }
}

Current Behavior

## Windows
Notifications only, no click-to-focus.

(from docs/CLICK_TO_FOCUS.md)

Expected Behavior

Clicking a desktop notification on Windows brings the originating terminal window to the foreground, matching the behavior already available on macOS and Linux.

Environment

  • OS: Windows 11 (MSYS2 / Git Bash)
  • Plugin version: 1.25.2
  • Terminal: Windows Terminal + Git Bash

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions