在资源管理器里对任意文件夹右击 → Claude AI → 自动打开 Windows Terminal(Git Bash),进入该目录、自动通过工作区信任检查、启动 Claude Code;退出 Claude 后窗口保留为 Git Bash。
实测环境(2026-11):
组件 版本 Windows 10 Pro 19045(Windows 11 也可用,见文末) Windows Terminal 1.26.2734.0 便携版(Store 版同样适用) Git for Windows bash 5.3.15(UCRT64 运行时) Claude Code 2.1.332(npm 安装)
1. 效果与原理 1
2
3
4
5
6
7
8
9
10
Explorer 右键
│ 注册表动词 HKCU\Software\Classes\Directory\shell\ClaudeAI
▼
wt.exe -p "Git Bash" -d "<右击的目录>" "bash.exe" -l "<launcher>"
│
▼
Git Bash(claude-here.sh)
├─ ① 把 projects[<目录>].hasTrustDialogAccepted 写入 ~/.claude.json(跳过信任弹窗)
├─ ② 运行 claude
└─ ③ claude 退出后 exec bash --login -i(窗口不关)
关键点:
只写 HKCU (当前用户),不需要管理员权限,随时可删。 两个键分别覆盖「右键文件夹图标」和「右键文件夹空白处」。 %V 会被资源管理器替换成目标目录,两处都有效(Windows 10 实测)。逻辑(多个步骤)放在启动脚本里,注册表命令保持简单,避开 Windows Terminal 的 ; 命令分隔符问题。 2. 文件 1
2
3
4
5
6
<本目录>\
├─ README.md
└─ scripts\
├─ install-claude-menu.ps1 安装/卸载右键菜单(自动探测 wt.exe / bash.exe)
├─ claude-here.sh 启动脚本:预信任目录 → claude → 保留 Git Bash
└─ trust-workspace.cjs 预写工作区信任记录(等效于点 "Yes, I trust this folder")
(<本目录> 指本文件所在目录,例如 C:\Users\A\claude-portable\ai-start-right-click。)
安装后 claude-here.sh 与 trust-workspace.cjs 应放在同一目录(默认 %USERPROFILE%\.claude\bin\),启动脚本会按自身位置查找 trust-workspace.cjs。三个脚本的完整内容见文末附录。
3. 安装 前置条件:
已安装 Windows Terminal (Store 版或便携版都行;便携版 wt.exe 不在 PATH 也没关系,安装脚本会去 C:\terminal-* 里找) 已安装 Git for Windows (C:\Program Files\Git\bin\bash.exe) claude 在 PATH 中可用(Git Bash 里能直接运行 claude)步骤:
1
2
3
4
5
6
7
8
# 1) 先干跑,确认探测到的路径和最终命令无误(不写注册表)
powershell -NoProfile -ExecutionPolicy Bypass -File <本目录>\scripts\install-claude -menu.ps1 -Print
# 2) 正式安装(会把 claude-here.sh / trust-workspace.cjs 复制到 %USERPROFILE%\.claude\bin\)
powershell -NoProfile -ExecutionPolicy Bypass -File <本目录>\scripts\install-claude -menu.ps1
# 3) 卸载
powershell -NoProfile -ExecutionPolicy Bypass -File <本目录>\scripts\install-claude -menu.ps1 -Remove
参数 参数 说明 -WtPath <path>指定 wt.exe。不指定时依次尝试 PATH、%LOCALAPPDATA%\Microsoft\WindowsApps、%ProgramFiles%\WindowsTerminal、C:\terminal-*\wt.exe -BashPath <path>指定 Git for Windows 的 bash.exe -LauncherPath <path>启动脚本位置,默认 %USERPROFILE%\.claude\bin\claude-here.sh -ProfileName "Git Bash"用哪个 Windows Terminal profile 的外观(图标/配色)。不存在时自动退回默认外观并警告 -NoProfile完全不传 -p(标签页用默认 profile 的外观) -Print只打印探测结果和命令,不写注册表 -Remove删除两个菜单键
关闭自动信任 编辑 claude-here.sh,把顶部 TRUST_ON_OPEN=1 改成 0。
之后每次打开新目录仍会弹出一次信任确认(这是 Claude Code 的默认设计)。
想给某个目录手动加信任:
1
node "%USERPROFILE%\.claude\bin\trust-workspace.cjs" "D:\some\project"
权限模式(auto / bypass) 新版 Claude Code(如 2.1.332)的默认权限模式可能是 auto (由分类器自动批准/拦截),会话界面会显示 “auto mode on”。启动脚本里如果是裸的 claude,会话就沿用这个默认。
想只让右键打开的会话 绕过全部权限确认:
1
2
# claude-here.sh 顶部
CLAUDE_ARGS = "--dangerously-skip-permissions"
(共享版脚本里 CLAUDE_ARGS 默认为空,即沿用全局默认;按需打开。)
想全局 bypass,请改 ~/.claude/settings.json:
1
"permissions" : { "defaultMode" : "bypassPermissions" }
注意:
必须放在 permissions 下面;合法值为 acceptEdits / auto / bypassPermissions / manual(或别名 default)/ dontAsk / plan。 顶层写 "defaultMode": "bypass" 是无效的(层级不对、值也不对),会被静默忽略,于是落到默认的 auto 模式——这是最常见的“为什么不是 bypass”的原因。 --dangerously-skip-permissions 通常需要一次免责确认;设置 "skipDangerousModePermissionPrompt": true 可跳过该确认。4. 为什么需要预写信任记录 Claude Code 每次在未信任的目录 里启动,都会询问:「Is this a project you created or one you trust?」(默认选项是 No, exit)。
信任状态按规范化路径 记录在 ~/.claude.json 的 projects[<path>].hasTrustDialogAccepted(正斜杠、不带尾斜杠、真实大小写); 主目录的信任通过界面点 “Yes” 不会被保存 ,所以从主目录启动会每次都问;但预写这条记录仍然有效(本方案已验证);Claude Code 2.1.332 没有 官方的「全局默认信任」开关:--dangerously-skip-permissions、bypassPermissions 权限模式都不会跳过这个对话框;CLAUDE_CODE_SANDBOXED 虽然会导致自动信任,但它是内部变量,会改变大量其他行为,不建议使用; 因此本方案选择在启动前写入与「点 Yes」完全相同的记录。这是 Claude Code 自己的报错信息里给出的做法(“set projects[].hasTrustDialogAccepted: true in ")。 写入细节:读 → 改 → 写临时文件 → 校验 ~/.claude.json 的 mtime 未变 → 原子重命名;mtime 变了就重试,最多 5 次,避免和正在运行的 Claude 会话互相覆盖。
用户须知:自动信任意味着该目录里的 .claude 设置、hooks、MCP server 会在启动时被加载。只对你自己的/可信的目录使用;随时可用 TRUST_ON_OPEN=0 关闭。
5. 踩过的坑(值得借鉴) 不要用 cmd.exe 中转 。在 Git Bash 里 cmd //c "..." 会把引号加反斜杠,参数被破坏。直接调用 wt.exe / bash.exe,避免多层引号。Git Bash 里 reg add 的 /d、/ve 会被 MSYS 路径转换改写 (/d → D:\),报"无效语法”。写注册表请用 PowerShell(New-ItemProperty),或给 reg 参数加 MSYS_NO_PATHCONV=1。PowerShell 5.1 会把无 BOM 的 UTF-8 中文注释读成乱码 ,可能直接解析失败。.ps1 里保持纯 ASCII(或用 UTF-8 BOM)。Windows Terminal 把命令行里的 ; 当作标签页/分屏分隔符 ,所以 claude; exec bash 这种写法必须放进脚本文件,不能写在 wt 的参数里。不传 -p <profile> 时,WT 用 defaultProfile(常见是 Windows PowerShell)的外观运行你的命令 ,图标/配色看起来像 cmd,容易误判;传 -p "Git Bash" 才对得上 profile 的图标。注意这只是外观——进程本身一直是 Git Bash。便携版 Windows Terminal 的 wt.exe 不在 PATH (Store 版有 WindowsApps 别名),必须用绝对路径;安装脚本会自动探测 C:\terminal-*\wt.exe。主目录信任不持久 (见第 4 节);C:\Users\<you> 通过 UI 点 Yes 只对当次会话有效。并发写 ~/.claude.json :Claude 会话也会写这个文件,直接覆盖可能丢配置;用 mtime 校验 + 原子替换。-p 指定的 profile 不存在时 ,WT 会报错/回退,菜单可能打不开终端。安装脚本会读取 %LOCALAPPDATA%\Microsoft\Windows Terminal\settings.json 检查 profile 是否存在,不存在就自动省略 -p。极端情况:目录路径内含 ; 时 -d 参数可能被 WT 拆分(罕见,遇到可改用脚本内 cd)。 6. 验证方法 A. 确认真的在用 Git Bash(而不是 cmd)
看标签页提示符或 $BASH_VERSION;本方案实测的进程链:
1
explorer.exe → WindowsTerminal.exe → bash.exe (C:\Program Files\Git\bin\bash.exe -l ...)
B. 确认信任弹窗被跳过
Claude Code 支持 --debug-file:
1
claude --debug-file C:\temp\dbg.log
未信任时,日志里会出现:hooks modules not loaded until workspace trust is accepted 预写信任记录后,该行消失,日志明显变长(MCP、记忆、文件监视正常初始化) C. 确认权限模式
看会话界面是否显示 “auto mode on”;或检查 claude 进程命令行里有没有 --dangerously-skip-permissions。
7. 手动注册表内容(不使用脚本时参考) 1
2
3
4
5
HKCU\Software\Classes\Directory\shell\ClaudeAI
(默认) = Claude AI
Icon = C:\Program Files\Git\ucrt64\share\git\git-for-windows.ico
HKCU\Software\Classes\Directory\shell\ClaudeAI\command
(默认) = "<wt.exe 完整路径>" -p "Git Bash" -d "%V" "C:\Program Files\Git\bin\bash.exe" -l "/c/Users/<you>/.claude/bin/claude-here.sh"
Directory\Background\shell\ClaudeAI 内容完全相同(覆盖「空白处右键」)。
注意:注册表命令里的启动脚本路径必须是 MSYS 风格 (/c/Users/...),而 wt.exe、bash.exe 用 Windows 风格路径。
8. Windows 11 注意 Windows 11 的新式右键菜单默认只显示精简项:按 Shift+F10 或点「显示更多选项」即可看到本菜单。 想把条目放进 Win11 新菜单,需要实现 IExplorerCommand COM 扩展,超出本文范围。 附录:完整脚本 以下为 scripts/ 下三个脚本的完整内容,可直接保存后使用。
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
<#
.SYNOPSIS
Adds an Explorer context-menu entry "Claude AI" that opens Claude Code in
Windows Terminal, using Git Bash, for the folder you right-clicked.
.DESCRIPTION
Registers two per-user keys (no admin rights needed):
HKCU\Software\Classes\Directory\shell\ClaudeAI (right-click a folder)
HKCU\Software\Classes\Directory\Background\shell\ClaudeAI (right-click empty space)
The menu runs:
wt.exe [-p <profile>] -d "%V" "bash.exe" -l "<launcher>"
claude-here.sh pre-trusts the folder, starts claude, and drops to an
interactive Git Bash when claude exits.
.PARAMETER WtPath
Full path to wt.exe. Auto-detected when omitted.
.PARAMETER BashPath
Full path to bash.exe (Git for Windows). Default: %ProgramFiles%\Git\bin\bash.exe
.PARAMETER LauncherPath
Full path to claude-here.sh.
Default: %USERPROFILE%\.claude\bin\claude-here.sh
If it does not exist and claude-here.sh sits next to this script, the
launcher and trust-workspace.cjs are copied there automatically.
.PARAMETER ProfileName
Windows Terminal profile used for the tab's icon and appearance.
Default: "Git Bash". Falls back to no -p if that profile is not found.
.PARAMETER NoProfile
Do not pass -p to wt.exe at all.
.PARAMETER Print
Show the detected paths and the final command without touching the registry.
.PARAMETER Remove
Remove the menu entries.
.EXAMPLE
powershell -NoProfile -ExecutionPolicy Bypass -File install-claude-menu.ps1 -Print
.EXAMPLE
powershell -NoProfile -ExecutionPolicy Bypass -File install-claude-menu.ps1
.EXAMPLE
powershell -NoProfile -ExecutionPolicy Bypass -File install-claude-menu.ps1 -Remove
#>
param (
[string]$WtPath ,
[string]$BashPath ,
[string]$LauncherPath ,
[string]$ProfileName = 'Git Bash' ,
[switch]$NoProfile ,
[switch]$Print ,
[switch]$Remove
)
$ErrorActionPreference = 'Stop'
$menuName = 'Claude AI'
$keys = @(
'HKCU:\Software\Classes\Directory\shell\ClaudeAI' ,
'HKCU:\Software\Classes\Directory\Background\shell\ClaudeAI'
)
if ($Remove ) {
foreach ($k in $keys ) {
if (Test-Path $k ) { Remove-Item -Path $k -Recurse -Force }
Write-Host "removed: $k"
}
exit 0
}
function Find-Exe {
param ([string]$Explicit , [string[]]$Candidates , [string]$What )
if ($Explicit ) {
if (-not (Test-Path $Explicit )) { throw "$What not found: $Explicit" }
return (Resolve-Path $Explicit ).Path
}
foreach ($c in $Candidates ) {
if ($c -and (Test-Path $c )) { return (Resolve-Path $c ).Path }
}
throw "$What not found. Pass the full path explicitly."
}
# --- wt.exe ---------------------------------------------------------------
$wtCandidates = @()
$wtCmd = Get-Command wt.exe -ErrorAction SilentlyContinue
if ($wtCmd ) { $wtCandidates += $wtCmd .Source }
$wtCandidates += (Join-Path $env:LOCALAPPDATA 'Microsoft\WindowsApps\wt.exe' )
$wtCandidates += (Join-Path $env:ProgramFiles 'WindowsTerminal\wt.exe' )
$portable = Get-ChildItem -Path 'C:\' -Filter 'wt.exe' -Depth 1 -ErrorAction SilentlyContinue |
Where-Object { $_ .DirectoryName -like 'C:\terminal-*' } |
Sort-Object LastWriteTime -Descending |
Select-Object -First 1
if ($portable ) { $wtCandidates += $portable .FullName }
$wt = Find-Exe -Explicit $WtPath -Candidates $wtCandidates -What 'wt.exe'
# --- bash.exe -------------------------------------------------------------
$bashCandidates = @(
(Join-Path $env:ProgramFiles 'Git\bin\bash.exe' ),
(Join-Path ${env:ProgramFiles(x86)} 'Git\bin\bash.exe' )
)
$bash = Find-Exe -Explicit $BashPath -Candidates $bashCandidates -What 'bash.exe (Git for Windows)'
# --- launcher -------------------------------------------------------------
$targetDir = Join-Path $env:USERPROFILE '.claude\bin'
if (-not $LauncherPath ) { $LauncherPath = Join-Path $targetDir 'claude-here.sh' }
if (-not (Test-Path $LauncherPath )) {
foreach ($f in 'claude-here.sh' , 'trust-workspace.cjs' ) {
$src = Join-Path $PSScriptRoot $f
if (Test-Path $src ) {
New-Item -ItemType Directory -Path $targetDir -Force | Out-Null
Copy-Item $src (Join-Path $targetDir $f ) -Force
Write-Host "copied: $src -> $targetDir"
}
}
}
if (-not (Test-Path $LauncherPath )) {
throw "launcher not found: $LauncherPath (copy claude-here.sh and trust-workspace.cjs there first)"
}
$trustScript = Join-Path (Split-Path $LauncherPath ) 'trust-workspace.cjs'
if (-not (Test-Path $trustScript )) {
Write-Warning "trust-workspace.cjs not found next to the launcher; the trust pre-seed will be skipped."
}
# Windows path -> MSYS path (C:\a\b -> /c/a/b) for the Git Bash argument.
function ConvertTo-MsysPath {
param ([string]$Path )
$p = (Resolve-Path $Path ).Path.Replace('\' , '/' )
if ($p -match '^([A-Za-z]):(.*)$' ) { return '/' + $Matches [1].ToLower() + $Matches [2] }
return $p
}
$launcherMsys = ConvertTo-MsysPath $LauncherPath
# --- verify the WT profile exists ----------------------------------------
function Test-TerminalProfile {
param ([string]$Name )
$settings = Join-Path $env:LOCALAPPDATA 'Microsoft\Windows Terminal\settings.json'
if (-not (Test-Path $settings )) { return $true } # cannot verify: keep it
try {
$st = Get-Content $settings -Raw -ErrorAction Stop | ConvertFrom-Json
$list = @()
if ($st .profiles -and $st .profiles.list) { $list = @($st .profiles.list) }
elseif ($st .profiles -is [array]) { $list = @($st .profiles) }
foreach ($p in $list ) {
if ($p .name -eq $Name -or $p .guid -eq $Name ) { return $true }
}
} catch { return $true }
return $false
}
$profileArg = ''
if (-not $NoProfile -and $ProfileName ) {
if (Test-TerminalProfile $ProfileName ) {
$profileArg = " -p `" $ProfileName `" "
} else {
Write-Warning "Windows Terminal profile '$ProfileName' not found; the tab will use the default profile's look. Pass -ProfileName <name>, or -NoProfile to silence this."
}
}
$command = " `" $wt `" $profileArg -d `" %V `" `" $bash `" -l `" $launcherMsys `" "
$icon = $wt
$gitIcon = Join-Path $env:ProgramFiles 'Git\ucrt64\share\git\git-for-windows.ico'
if (Test-Path $gitIcon ) { $icon = $gitIcon }
if ($Print ) {
Write-Host "wt.exe : $wt"
Write-Host "bash.exe : $bash"
Write-Host "launcher : $LauncherPath"
Write-Host "profile : $(if ($profileArg ) { $ProfileName } else { '(default look)' })"
Write-Host "icon : $icon"
Write-Host "command : $command"
exit 0
}
foreach ($k in $keys ) {
New-Item -Path $k -Force | Out-Null
New-ItemProperty -Path $k -Name '(Default)' -Value $menuName -PropertyType String -Force | Out-Null
New-ItemProperty -Path $k -Name 'Icon' -Value $icon -PropertyType String -Force | Out-Null
New-Item -Path "$k\command" -Force | Out-Null
New-ItemProperty -Path "$k\command" -Name '(Default)' -Value $command -PropertyType String -Force | Out-Null
Write-Host "registered: $k"
}
Write-Host ""
Write-Host "command: $command"
Write-Host ""
Write-Host "Right-click a folder (or empty space inside one) and pick '$menuName'."
scripts/claude-here.sh 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
#!/usr/bin/env bash
# ---------------------------------------------------------------------------
# Launcher used by the "Claude AI" Explorer context-menu entry.
#
# Runs Claude Code in the current directory, then drops to an interactive
# login Git Bash so the window does not close when Claude exits.
#
# Copy this file next to trust-workspace.cjs (default location:
# %USERPROFILE%\.claude\bin\).
#
# TRUST_ON_OPEN=0 -> do not auto-accept the workspace trust dialog.
# CLAUDE_ARGS -> extra flags for claude. Newer Claude Code versions
# default to "auto" permission mode; put
# "--dangerously-skip-permissions" here to bypass all
# permission prompts instead (opt-in, review the risk).
# ---------------------------------------------------------------------------
TRUST_ON_OPEN = 1
CLAUDE_ARGS = ""
SCRIPT_DIR = " $( cd " $( dirname " ${ BASH_SOURCE [0]} " ) " && pwd ) "
if [ " $TRUST_ON_OPEN " = "1" ] && command -v node >/dev/null 2>&1; then
node " $SCRIPT_DIR /trust-workspace.cjs" " $PWD " >/dev/null 2>&1 || true
fi
claude $CLAUDE_ARGS
echo
echo "[Claude exited] This is now a login Git Bash shell."
exec bash --login -i
scripts/trust-workspace.cjs 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env node
// ---------------------------------------------------------------------------
// Pre-accept the Claude Code workspace trust dialog for one directory.
//
// Usage: node trust-workspace.cjs <dir>
//
// Writes projects[<canonical dir>].hasTrustDialogAccepted = true into the
// global config (~/.claude.json, or $CLAUDE_CONFIG_DIR/.claude.json).
// This is exactly the record Claude Code's own "Yes, I trust this folder"
// answer writes, so the trust dialog is skipped on the next launch.
//
// Files are written with an mtime check + rename so a Claude session that
// happens to write the same config concurrently is not silently clobbered.
// ---------------------------------------------------------------------------
'use strict' ;
const fs = require('fs' );
const path = require('path' );
function canonical(p) {
let out = p;
try { out = fs.realpathSync.native (p); } catch (e) {
try { out = fs.realpathSync(p); } catch (e2) { out = path.resolve(p); }
}
out = out.replace(/\\/g , '/' );
if (out.length > 1 ) out = out.replace(/\/+$/ , '' );
return out;
}
const dir = process.argv[2 ];
if (! dir) process.exit(0 );
const configDir = process.env.CLAUDE_CONFIG_DIR;
const configPath = configDir
? path.join(configDir, '.claude.json' )
: path.join(process.env.USERPROFILE || process.env.HOME || '' , '.claude.json' );
const key = canonical(dir);
for (let attempt = 0 ; attempt < 5 ; attempt++ ) {
let raw, statBefore;
try {
statBefore = fs.statSync(configPath);
raw = fs.readFileSync(configPath, 'utf8' );
} catch (e) { process.exit(0 ); }
let cfg;
try { cfg = JSON.parse(raw); } catch (e) { process.exit(0 ); }
if (! cfg.projects || typeof cfg.projects !== 'object' ) cfg.projects = {};
const entry = (cfg.projects[key] && typeof cfg.projects[key] === 'object' )
? cfg.projects[key] : {};
if (entry.hasTrustDialogAccepted === true ) process.exit(0 );
cfg.projects[key] = Object .assign({}, entry, { hasTrustDialogAccepted: true });
const tmp = configPath + '.trusttmp.' + process.pid;
try {
fs.writeFileSync(tmp, JSON.stringify(cfg, null , 2 ) + '\n' , 'utf8' );
const statAfter = fs.statSync(configPath);
if (statAfter.mtimeMs !== statBefore.mtimeMs) { fs.unlinkSync(tmp); continue ; }
fs.renameSync(tmp, configPath);
process.exit(0 );
} catch (e) {
try { fs.unlinkSync(tmp); } catch (e2) { /* ignore */ }
continue ;
}
}
process.exit(0 );
9. 参考 Windows Terminal 文档:https://aka.ms/terminal-documentation Claude Code 文档:https://code.claude.com/docs Claude Code 的信任记录:~/.claude.json → projects.<path>.hasTrustDialogAccepted