OSC 7501: a background dev server keeps a `working` child record for the whole session (2.1.326)

Open
#110,589 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
48/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Active
Tech stack
typescript
Domain
cli

Research direction

The issue points to the child-record builder and the filter used for the root record’s “N still running” message, but gives no file paths or tests. Start by locating those two code paths and compare how they classify background shells, especially serve_or_watch commands and shells with stopsOnExit. Done means server or watcher child records no longer remain working after the root turn ends, while awaited tasks still report correctly.

Written by the indexing model from the issue text.

Description

area:tui bug has repro platform:linux regression

Summary

Since 2.1.326, Claude Code sends an OSC 7501 child record for every running background task. That fixes #104195 and #107347 for tasks Claude waits on. But it also covers long-running servers and watchers started with run_in_background, such as vite dev or python3 -m http.server. Each one gets state=working and keeps it until the server exits, which is usually the end of the session.

The root record already treats such a server as no outstanding work: the turn ends with state=done and no "still running" message. The child record says the opposite. So a terminal that shows a session as busy while any of its records is working keeps showing it as running for hours after the agent went idle.

Environment

  • Claude Code 2.1.326 (native installer), Linux
  • Terminal: Kmux, a Konsole fork that implements OSC 7501. Also reproduced with a bare pty that answers the 7501 probe and logs every report.
  • 2.1.325 does not do this: its child records cover only local_agent, remote_agent, in_process_teammate and local_workflow tasks.

Repro

  1. Start claude in a terminal that answers OSC 7501 ; ?.
  2. Send: Start a local dev server: use the Bash tool with run_in_background set to true to run "python3 -m http.server 8765 --bind 127.0.0.1". Do not wait for it, poll it or check it. Then reply with only the word STARTED and end your turn.
  3. Watch the 7501 reports.

Actual (seconds since launch, title/msg decoded from base64):

16.03  state=working:app=claude-code
17.80  state=working:app=claude-code:id=buqctsuiy:title=Start local HTTP dev server on port 8765
17.84  state=working:app=claude-code:msg=Starting local HTTP dev server on port 8765
18.48  state=done:app=claude-code
       (nothing more: the child record stays working)
66.04  state=clear        (Claude Code exits)

For comparison, here is a background sleep 20 that Claude waits on. This case is correct: the root stays working while the shell runs, and the child record is cleared when the shell ends.

10.78  state=working:app=claude-code
12.20  state=working:app=claude-code:id=bfm3mqjau:title=Sleep for 20 seconds
12.38  state=working:app=claude-code:msg=Sleeping for 20 seconds
15.85  state=working:app=claude-code:msg=1 shell still running
32.21  state=working:app=claude-code
32.21  state=clear:id=bfm3mqjau
33.18  state=done:app=claude-code

In real use, a session started npx vite dev in the background at 07:02 and ended its last turn at 08:08. The terminal kept showing the session as running because of the dev server's child record.

Expected

A background task that the root does not count as outstanding work should not be reported as working. Either:

  • send child records only for tasks that the root waits on, using the same filter that produces "N still running"; or
  • send no record for tasks classified as servers or watchers.

Notes

In 2.1.326 the root's "N still running" message already filters background shells: among other things, it skips commands that Claude Code classifies as serve_or_watch and shells with stopsOnExit. The function that builds the child records checks only that the task is running, and gives every task that is not an agent state: "working". Using the same filter there would make the two records agree.

The spec leaves it to the terminal to combine root and child states ("Both are true, and the terminal decides which to show"). So a terminal cannot tell "the agent is waiting for this" from "this server runs until you stop it": both arrive as working child records with free-form titles. As a workaround, Kmux now ignores working child records and takes "running" from the root record only. That works because 2.1.326 keeps the root working for shells it waits on, but it makes the new child records useless for this purpose.

Dominant language
TypeScript
Stars
156k
Forks
25k
Avg merge
16h 19m
Merged PRs (30d)
5

Getting set up

Open in Codespaces

Starts the project's dev container in your browser, under your own GitHub account.

  • No Dockerfile or Docker Compose file
  • No pull request template
  • No contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from anthropics/claude-code

All issues in anthropics/claude-code

Similar issues

More TypeScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.