Claude Existing Terminal Auto Start
English | 日本語
English
Runs claude --permission-mode auto once in an existing restored terminal
when a VS Code window starts.
Features
- Does not run in an empty window (no folder opened), which prevents the
workspace-trust prompt from appearing for a temporary folder.
- When no restored terminal exists (e.g. a folder opened for the first
time), a new terminal is created and the command runs there
(can be disabled with
createTerminalIfNone).
- If the workspace is not yet trusted, it waits and runs as soon as trust
is granted.
- Restored terminals are detected via the
onDidOpenTerminal event, so
the command runs as soon as the terminal appears — no polling.
- Shell-agnostic: works with PowerShell, Command Prompt, Git Bash, WSL, etc.
- Prefers the active existing terminal.
- Skips terminals whose name contains
claude to avoid starting twice.
- Skips when Claude is already running in that terminal, including when the
terminal is re-attached to a surviving
psmux / tmux session. See below.
Not starting Claude twice
A multiplexer session outlives the VS Code window. When the window opens
again, the restored terminal re-attaches to a session where Claude is
already running — and sending the startup command there types it straight
into Claude's prompt.
Before sending anything, the extension therefore inspects processes:
- the process tree below the terminal's shell (covers a plain terminal
whose shell VS Code restored with Claude still running), and
- the multiplexer session the terminal is attached to. Panes are children
of the multiplexer server, not of the terminal, so the session is
resolved from the attached client's
-t target and queried with
list-panes -a -F "#{pane_pid}|#{pane_current_command}|#{session_name}".
If that query is unavailable, the matching server process is located and
its process tree is scanned instead.
A process counts as Claude when its executable name is claude
(claude.exe and similar included), or when its command line contains
@anthropic-ai/claude-code for launches through node. A directory that
merely has claude in its name does not match.
Because the multiplexer client may not have spawned yet at inspection time,
the check runs up to processScanAttempts times and stops as soon as the
answer is conclusive. Decisions are logged to the
Claude Existing Terminal output channel.
Set skipWhenClaudeIsRunning to false to turn the whole check off.
Manual run
Run the following from the Command Palette:
Claude: Run in Existing Terminal Now
This sends the Claude Code startup command to the existing active
terminal without creating a new one. If Claude turns out to be running
already, it asks for confirmation instead of sending silently.
Settings
claudeExistingTerminal.enabled — enable/disable automatic run.
claudeExistingTerminal.command — command to send
(default: claude --permission-mode auto).
claudeExistingTerminal.startupDelayMs — delay before sending the
command after the terminal process is available (default: 2000).
claudeExistingTerminal.restoreWaitMs — maximum time to wait for a
restored terminal before falling back (default: 10000).
claudeExistingTerminal.createTerminalIfNone — create a new terminal
when none is restored (default: true).
claudeExistingTerminal.skipWhenTerminalNameContains — skip terminals
whose name contains any of these strings (default: ["claude"]).
claudeExistingTerminal.skipWhenClaudeIsRunning — skip when Claude is
already running in the terminal or in its multiplexer session
(default: true).
claudeExistingTerminal.claudeProcessNames — executable names that count
as a running Claude (default: ["claude"]).
claudeExistingTerminal.claudeCommandLinePatterns — command-line
substrings that identify a running Claude
(default: ["@anthropic-ai/claude-code"]).
claudeExistingTerminal.multiplexerProcessNames — multiplexers to look
through (default: ["psmux", "tmux", "zellij", "screen"]).
claudeExistingTerminal.processScanAttempts — how many times to inspect
processes before giving up (default: 2).
claudeExistingTerminal.processScanIntervalMs — wait between inspection
attempts (default: 1000).
claudeExistingTerminal.processScanTimeoutMs — timeout for each
inspection command (default: 5000).
To start Claude in normal (non-auto) mode:
{
"claudeExistingTerminal.command": "claude"
}
If terminal restoration is slow in your environment:
{
"claudeExistingTerminal.startupDelayMs": 2000,
"claudeExistingTerminal.restoreWaitMs": 15000
}
日本語
VS Codeのウィンドウ起動時に、復元された既存ターミナル上で
claude --permission-mode autoを一度だけ実行します。
特徴
- フォルダを開いていない空のウインドウ(新規起動)では実行しません。
テンポラリフォルダへの信頼確認が出るのを防ぎます。
- 「フォルダーを開く」で新規に開いた場合など、復元ターミナルが
存在しないときは新しいターミナルを作成して実行します
(
createTerminalIfNoneで無効化できます)。
- ワークスペースが未信頼の間は待機し、信頼が付与された時点で実行します。
- 復元ターミナルは
onDidOpenTerminalイベントで検知するため、
ターミナルが現れた瞬間に実行されます(ポーリングなし)。
- PowerShell、コマンドプロンプト、Git Bash、WSLなどのシェルを固定しません。
- アクティブな既存ターミナルを優先します。
- ターミナル名に
claudeが含まれる場合は、二重起動を避けるためスキップします。
- そのターミナルで既にClaudeが動いているときはスキップします。
psmux/tmuxのセッションが生き残っていて再アタッチした場合も含みます(下記)。
二重起動させない仕組み
多重化セッションはVS Codeのウィンドウより長生きします。ウィンドウを開き直すと、
復元されたターミナルはClaudeが起動済みのセッションへ再アタッチするため、
そこへ起動コマンドを送るとClaudeのプロンプトへ文字列が流し込まれてしまいます。
そこで送信前にプロセスを調べます。
- ターミナルのシェル配下のプロセスツリー
(多重化ツールを使わず、VS Codeがシェルごと復元した場合をカバー)
- ターミナルがアタッチしている多重化セッション。
ペインはターミナルの子ではなく多重化サーバーの子なので辿れません。
アタッチクライアントの
-tからセッション名を取り、
list-panes -a -F "#{pane_pid}|#{pane_current_command}|#{session_name}"
で問い合わせます。これが使えない場合は、対応するサーバープロセスを探して
その配下を走査します。
Claudeとみなすのは、実行ファイル名がclaudeのとき(claude.exeなども含む)、
またはnode経由の起動でコマンドラインに@anthropic-ai/claude-codeを含むときです。
claudeを名前に含むだけのディレクトリは誤検知しません。
検査時点でまだ多重化クライアントが起動していないことがあるため、
結論が出るまでprocessScanAttempts回まで見直します。判定内容は出力パネルの
Claude Existing Terminalに記録されます。
この確認自体を止めたい場合はskipWhenClaudeIsRunningをfalseにします。
手動実行
コマンドパレットで次を実行します。
Claude: Run in Existing Terminal Now
このコマンドも新しいターミナルを作成せず、既存のアクティブな
ターミナルへClaude Code起動コマンドを送信します。既にClaudeが起動していると
判定された場合は、黙って送らずに確認を出します。
設定
claudeExistingTerminal.enabled — 自動実行の有効/無効。
claudeExistingTerminal.command — 送信するコマンド
(既定: claude --permission-mode auto)。
claudeExistingTerminal.startupDelayMs — ターミナルプロセス確認後、
コマンド送信までの待機時間(既定: 2000)。
claudeExistingTerminal.restoreWaitMs — 復元ターミナルを待つ最大時間。
超過するとフォールバックします(既定: 10000)。
claudeExistingTerminal.createTerminalIfNone — 復元ターミナルが無い
場合に新規作成するか(既定: true)。
claudeExistingTerminal.skipWhenTerminalNameContains — 名前にこれらの
文字列を含むターミナルをスキップ(既定: ["claude"])。
claudeExistingTerminal.skipWhenClaudeIsRunning — ターミナルや
その多重化セッションで既にClaudeが動いていればスキップ(既定: true)。
claudeExistingTerminal.claudeProcessNames — Claudeとみなす実行ファイル名
(既定: ["claude"])。
claudeExistingTerminal.claudeCommandLinePatterns — Claudeとみなす
コマンドラインの部分文字列(既定: ["@anthropic-ai/claude-code"])。
claudeExistingTerminal.multiplexerProcessNames — 中を調べる多重化ツール
(既定: ["psmux", "tmux", "zellij", "screen"])。
claudeExistingTerminal.processScanAttempts — プロセス検査の最大回数
(既定: 2)。
claudeExistingTerminal.processScanIntervalMs — 検査の間隔(既定: 1000)。
claudeExistingTerminal.processScanTimeoutMs — 検査コマンドのタイムアウト
(既定: 5000)。
通常モードで起動したい場合は、コマンドを上書きできます。
{
"claudeExistingTerminal.command": "claude"
}
ターミナルの復元が遅い環境では、待機時間を延ばせます。
{
"claudeExistingTerminal.startupDelayMs": 2000,
"claudeExistingTerminal.restoreWaitMs": 15000
}