Skip to content

Keep running Claude Code sessions out of dev servers and batch close - #20

Open
kuk1song wants to merge 1 commit into
SonghaiFan:mainfrom
kuk1song:protect-agent-sessions
Open

kuk1song wants to merge 1 commit into
SonghaiFan:mainfrom
kuk1song:protect-agent-sessions

Conversation

@kuk1song

Copy link
Copy Markdown

Claude Code's command-line program (native install, ~/.local/share/claude/versions/<version>) listens on a localhost port of its own, and its working directory is the user's project. LeftOpen therefore lists it as that project's dev server, and leftopen close --all-projects includes it. Closing it ends the session the user is working in.

With main at 633db6b and a Claude Code 2.1.322 session open in a project:

$ leftopen close --all-projects --dry-run
BATCH CLOSE PLAN (4 project servers)
  • Port 4810: other-project — PID 87616 (4.7 MB)
  • Port 8766: my-project — PID 2276 (3.9 MB)
  • Port 8767: my-project — PID 92687 (2.2 MB)
  • Port 60019: my-project — PID 2095 (265 MB)

PID 2095 is the session's claude process; the other three are servers that sessions started.

Add CodingAgent.name(of:) in Core, which recognises the Claude Code program by its executable path. The scanner labels it "Claude Code" as an application, it is listed under Apps, and CloseService refuses to close it while safety protection is on: "PID 2095 is a running Claude Code session. Closing it would end that session; exit it from its own terminal instead." With safety protection off it can still be closed, like the other protections. Servers a session starts are separate processes and are unchanged. Only the native installer's path is recognised. Update both READMEs.

After the change the batch plan lists the three servers only, leftopen close 60019 --dry-run is refused with that reason, and an ordinary leftover server is still planned for closing.

Validation: swift test ran 87 tests, including the new testRunningClaudeCodeSessionIsAnAppAndCannotBeClosed. The one failure, testCoreTextFollowsTheSelectedLanguage, fails the same way on unmodified main on this Mac: its system language is Chinese and the test expects English as the starting language. The release script tests, the Homebrew uninstall test and the legacy icon test passed. Checked with the CLI on macOS 26; the menu bar app was not run.

The Claude Code program listens on a localhost port of its own and runs in
the user's project, so it was listed as that project's dev server and
included in close --all-projects. Recognise it by its executable path, list
it under Apps and refuse to close it while safety protection is on.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant