2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Claude Code を閉じても、裏で起動したサーバーが残ることがある。見分け方は画面下の「1 shell」

2
Last updated at Posted at 2026-10-14

Codex CLI が、既定で常駐して自動更新するデーモンを入れていたと Issue になりました(openai/codex#48195、Hacker News で453pt)。

では Claude Code は、閉じたあとに何を残すのか。Claude に裏でサーバーを起動させ、閉じ方を変えて、Windows で44回測りました。

閉じて5秒後に、サーバー(ポート8765)が残っていたか(各2回)

Claude の起動の仕方              /exit   Ctrl+C×2   ウィンドウの×
バックグラウンド実行(Bash)       止まった  止まった    止まった
バックグラウンド実行(PowerShell)  止まった  止まった    止まった
Bash で node server.js &         残った   残った     残った
PowerShell の Start-Process      残った   残った     残った

「バックグラウンドで動かし続けて」とだけ頼むと、12回中2回は Claude が自分で Start-Process を選んだ

検証環境: Windows 10 / Claude Code 2.1.296 / 本体モデルは Sonnet 5.5 / 対話モードは別コンソールで起動し、
キー入力と終了を自動化 / 全ラン設定ディレクトリ使い捨て / 測定は 2026-10-13


測り方

ポート8765で待つだけの server.js(Node)を用意し、起動の仕方を指定して頼みました。

  • バックグラウンド実行: 「Bash ツールの run_in_background で node server.js だけを実行して」(PowerShell 版も)
  • 切り離し: 「Bash で node server.js & と打って」「PowerShell の Start-Process で」
  • 指定なし: 「バックグラウンドで動かし続けて」(12回)

閉じ方は /exit、Ctrl+C を2回、コンソールのウィンドウを閉じる(×)の3通りです。確認が出たときは 1 を選びました(2 を選んだ場合は後半)。


Claude Code が把握しているサーバーは、閉じれば止まる

バックグラウンド実行で起動した回は、/exit と Ctrl+C の8回とも、閉じる前にこの確認が出ました。

Background work is running
The following will stop when you exit:
shell · node server.js
 1. Exit and stop tasks
 2. Move to background and exit
 3. Stay

1 を選ぶと8回ともサーバーは止まり、ウィンドウの×でも4回とも止まりました。


把握していないサーバーは、どう閉じても残る

& と Start-Process で起動した16回は、確認が1度も出ず、閉じ方に関係なく16回とも残りました。

指定なしで頼んだ12回のうち2回は、Claude が自分で Start-Process -WindowStyle Hidden を使い、確認なしで残りました。残り10回はバックグラウンド実行で、閉じ方ごとの結果も上の2行と同じでした。

ドキュメントは、切り離れたプロセスまで止めるのを macOS と Linux に限っています(2026-10-13 取得)。

On macOS and Linux, when you stop a background task from /tasks or Claude Code stops it at exit, processes that detached from the task's shell, such as ones started under setsid or timeout, stop too


見分け方は、画面下の「1 shell」

把握している回は、画面の下にこう出ていました。

✻ Churned for 7s · done 11:01 · 1 shell still running
⏵⏵ accept edits on · 1 shell · ← for agents · ↓to manage

& や Start-Process の回は、サーバーが動いているのに 1 shell がありません。 閉じる前にここを見れば、残るかどうかが分かります。


「2. Move to background and exit」は、常駐するプロセスを残す

確認で 2 を選んだ6回は、サーバーに加えて、Claude Code のプロセスが1つ残りました(パスと引数の一部は省略)。

claude.exe daemon run --origin transient --spawned-by {...}

ドキュメント(agent-view)が「スーパーバイザー」と呼ぶものです。

The supervisor is a background service that runs your background sessions so they keep working after you close agent view or your terminal.

Claude Code にも常駐するプロセスはあります。ただし、自分で 2 を選んだときだけです。 止めるのは claude daemon stop --any です。


claude -p は、サーバーが止まるまで終わらない

claude -p でバックグラウンド実行させると、結果を返したあとも開いたまま607秒待ち、時間制限でサーバーを止めてから終わりました(各1回)。ドキュメントにある10分のとおりです。& や Start-Process で切り離した回は、-p が終わったあとも残りました。


残ったときの止め方

PowerShell でポートの持ち主を調べ、自分が起動したものか確かめてから止めます。

Get-NetTCPConnection -LocalPort 8765 -State Listen | Select-Object OwningProcess
Get-CimInstance Win32_Process -Filter "ProcessId=<PID>" | Select-Object CommandLine
Stop-Process -Id <PID>

コマンドラインに名前が含まれるかだけで、まとめて止めないでください。 Next.js の開発サーバーの start-server.js や TypeScript の tsserver.js のように、名前の末尾が server.js のプロセスは普通に動いています。


言えないこと

  • Windows 10・Claude Code 2.1.296・Sonnet 5.5 だけ、各2回です。macOS と Linux は測っていません
  • サーバーは小さな Node 1本です。npm run dev のように何段も子を作るものは測っていません
  • ウィンドウを閉じたのは従来のコンソール(conhost)です。Windows Terminal と VS Code の拡張機能は測っていません
  • 裏に回したセッションが約1時間で止められる動き(ドキュメントの記載)は確かめていません

まとめ

  • Claude Code が把握しているサーバーは、/exit・Ctrl+C・ウィンドウの×のどれでも止まった
  • & や Start-Process で切り離したサーバーは、確認なしで残った。 Claude は12回中2回、自分で切り離した
  • 見分け方は画面下の 1 shell。 出ていなければ、閉じても残る
  • 確認で「Move to background and exit」を選ぶと、常駐するプロセスとサーバーが残る

閉じたのにポートが使用中なら、Claude が Start-Process や & で起動していなかったかを先に疑ってみてください。


関連記事


JQITのエンジニアの95%以上は未経験からの採用です。
よければコーポレートサイトにも遊びに来てください。

▶ コーポレートサイト

エンジニア採用も行っています。もしご興味あれば覗いてみてください。

▶ 採用サイト

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?