The Agent badge showed 2 or 3 while one Claude Code session was connected. The relay log against the open TCP connections in the container showed two causes. - A client may drop its event stream while the relay still asks the API about its token. The close was over before the relay listened for it, so the stream stayed in the list and counted for good. The relay now listens before the token check and keeps no stream that is already gone. It listens on the response, not the request. - Claude Code opens three sessions whenever it connects and keeps a stream on one of them. It never ends the others with a DELETE. Any session counted for two minutes after its last request, so the badge stood at 3 after each start. Now a session counts while its stream is open or it called a tool in the last two minutes. - The relay logs session start, stream open and close and each change of the count, with session ids cut to 8 characters. One case is left: after a relay restart Claude Code sometimes repeats its first call on a spare session. The badge then shows 2 for two minutes and drops to 1 on its own. Tests: - relay.test.ts: 27/27, three new. A dropped stream counts out, a stream dropped during the token check never counts, and spare sessions without a tool call do not count. - Counter-checks: without the early close listener the drop test turns red, with the old count two tests turn red. - Live: the badge showed 2 with one open SSE connection before. After the fix it shows "Agent · 1" and stays there after a normal call. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>