Skip to content

Show and stop the servers a thread started #7969

Description

@lanjak

Problem

Agents often start a dev server (npm run dev, python3 -m http.server, a test server) and leave it running after the turn ends. bb does not show which servers a thread started or on which ports. To open one, the user scrolls the thread output for the port. To stop one, the user finds the process with lsof or ps and kills it by hand. Servers that nobody stops keep their ports and use memory.

Steps to reproduce

  1. Start a Claude Code thread with the prompt: "Run nohup python3 -m http.server 48231 --bind 127.0.0.1 &, then reply done."
  2. Wait for the turn to end.
  3. Look at the thread, and run bb thread show <thread-id>.

Expected: the thread shows that it has a server on port 48231, with a way to open it and a way to stop it. The CLI lists the same.

Actual: nothing in the thread, the CLI, or the SDK shows the server. It runs until someone kills it.

Proposal

List the servers each thread started: processes that listen on a TCP port and that the thread's agent started from its shell. bb sets BB_THREAD_ID in agent shells, so the machine of the thread's environment can attribute each listening process to a thread. Show them above the composer with the ports, an Open action, and a Stop action. Stop ends the server's command and the processes under it, and never the agent, its shell, or bb. Add bb dev-servers list|stop for the CLI.

Related: #3192 asks for a list of listening ports on the in-app browser's new-tab page. #5954 asks bb to clean up processes agents leave behind.

Version: bb main at 4e45c9b.

AGENT GENERATED

Activity

  1. added
    hostHost daemon, process lifecycle, memory, event loop
    threadsTurns, timeline, messaging, forks
    on Nov 21, 2026
  2. bb-slop-cop commented on Nov 21, 2026

    @bb-slop-cop
    Contributor

    🚨 SLOP COP 🚨 · new-issue-autopilot

    Applied the missing classification:

    • Type: Feature — adds per-thread server discovery and lifecycle controls rather than correcting existing functionality.
    • Priority: Medium — meaningful workflow and resource-management improvement; manual inspection and termination remain available.
    • Effort: High — requires process attribution, safe termination, and coordinated UI, CLI, and SDK surfaces.
    • Labels: host, threads.

    No existing classification values were present; all applied values were verified. Reproduction reporting and a fix PR were skipped because the final Type is Feature.

  3. lanjak commented on Nov 21, 2026

    @lanjak
    ContributorAuthor

    Hi, I'd like a maintainer's sign-off on this feature before #7970 goes up for review. I opened it too early, so I've moved it to draft. Please treat it as a prototype for now.

    What #7970 does: a built-in plugin lists the servers a thread's agent started, with their ports, and offers Open and Stop. It finds them through the BB_THREAD_ID variable in agent shells, on Linux and macOS, with no daemon change. CLI: bb processes servers|stop.

    I renamed the plugin from dev-servers to processes, because I'd also like to propose per-thread CPU and memory use and port forwarding on top of it. Those would get their own issues first.

    Happy to change the approach, or close it if you'd rather solve this another way.

  4. lanjak commented on Nov 21, 2026

    @lanjak
    ContributorAuthor

    Update: I closed #7970. The prototype stays on my fork: main...lanjak:bb:thread-dev-servers (head 1105f33375). The rename to processes that I mentioned above is not on the branch yet. I'll post an update when it is.

  5. lanjak commented on Nov 21, 2026

    @lanjak
    ContributorAuthor

    Update: the prototype for this issue is on the fork branch, now at 987431f.

    Compare: main...lanjak:bb:thread-dev-servers

    Changes since the closed PR #7970

    • The plugin is renamed to Processes: directory plugins/processes, plugin id bb--processes, package bb-plugin-bb--processes. The CLI is bb processes servers [thread-id] [--json] and bb processes stop <pid> [--thread <thread-id>] [--json]. Per-thread resource use and port forwarding can build on the same plugin later.
    • Attribution now covers Codex. Codex starts some commands without a shell and marks each with CODEX_TOOL_CALL_ID. A listener with that id is rooted at the highest ancestor with the same id.
    • On macOS, ps -E shows no environment for processes that rewrite their command line (npm, zsh). On Linux, /proc/<pid>/environ can be empty. Such processes take the thread of their nearest visible ancestor.
    • A root that the provider bridge started is never used. This covers the agent, its MCP servers, and agents that a package runner (npx) or a shell started. The check skips package runners and wrapper shells between the root and the bridge.
    • New setting stopOnArchive (default on): archiving or deleting a thread stops its servers, if its machine is online.
    • The list shows the command of the listening process. The root is only the target of Stop.

    macOS results (rufimac, Darwin 27, real ps and lsof)

    A real Claude Code thread on the Mac ran nohup npm run serve & and started python3 -m http.server as a background task. The plugin's host code from the branch:

    • listed both servers under the thread;
    • did not list the claude process, which carries BB_THREAD_ID;
    • stopped both servers and closed both ports, after which the orphaned npm exited;
    • refused to stop the claude pid.

    Agent-shaped process trees under the real host daemon gave these results:

    • npm run serve under a live zsh tool shell is rooted at npm.
    • An orphaned server is listed.
    • A Codex-shaped agent's server is listed.
    • The agent's own port, an npm exec --call child, and an agent launched through npm exec are not listed.
    • Stop ended only the npm tree and refused both agents.

    One difference from Linux: on macOS a nohup npm run serve server whose shell has exited is rooted at python3, not npm, because npm hides its environment. Stop still ends the server, and npm exits after it.

    Other checks

    • Linux QA with a real Codex thread: the server was listed during the turn, Stop closed the port, and codex kept running.
    • Linux QA with a real Claude Code thread: archiving the thread stopped its nohup server.
    • pnpm exec turbo run test typecheck lint lint:type-aware --filter=bb-plugin-bb--processes: 48 tests pass.
    • The server's builtin registry, bb-official generator and plugin install job tests, the CLI skill coverage test, and the plugin-guide first-party test pass.

    AGENT GENERATED

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    hostHost daemon, process lifecycle, memory, event loopthreadsTurns, timeline, messaging, forks

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions