Skip to content

fix: detect Claude sessions started outside of Pixel Agents#101

Open
Commandershadow9 wants to merge 2 commits intopablodelucca:mainfrom
Commandershadow9:feat/better-agent-detection
Open

fix: detect Claude sessions started outside of Pixel Agents#101
Commandershadow9 wants to merge 2 commits intopablodelucca:mainfrom
Commandershadow9:feat/better-agent-detection

Conversation

@Commandershadow9
Copy link

@Commandershadow9 Commandershadow9 commented Mar 9, 2026

Motivation

Many users start Claude Code manually — from an existing VS Code terminal, via SSH Remote, or by opening a terminal before the extension loads. These sessions write JSONL files as expected but are never picked up by Pixel Agents. The office stays empty even though Claude is actively working.

This happens because of two issues in the detection logic.

Problem 1: Pre-registration blocks active sessions

ensureProjectScan seeds knownJsonlFiles with all existing .jsonl files on startup, including ones from currently running sessions. Since scanForNewJsonlFiles only processes files NOT in knownJsonlFiles, these active sessions are permanently invisible.

Fix: Skip pre-registration for files that appear to be from active sessions — files that are both large (≥3KB) and recently modified (<10 minutes). These stay "undiscovered" so the periodic scan can properly detect and adopt them.

Problem 2: Terminal matching only checks the focused terminal

scanForNewJsonlFiles only tries to match new JSONL files against vscode.window.activeTerminal. If the user is focused on a different terminal or the editor, the JSONL is detected but silently discarded because no terminal match is found.

Fix: Iterate over all vscode.window.terminals to find the first untracked terminal instead of only checking the focused one.

Changes

src/fileWatcher.ts — both fixes are small and focused:

  • ensureProjectScan: Add size/age check before adding files to knownJsonlFiles
  • scanForNewJsonlFiles: Replace activeTerminal lookup with terminals iteration

Test plan

  • Start Claude Code in a regular terminal (not via the Pixel Agents "+" button)
  • Open the Pixel Agents panel — verify the running session is detected and a character appears
  • Switch focus to a different terminal tab, start another Claude session there
  • Verify the second session is also detected even though its terminal isn't focused
  • Verify sessions started via the "+" button still work as before (no regression)

🤖 Generated with Claude Code

Shadow and others added 2 commits March 9, 2026 19:52
When Claude Code is started outside of Pixel Agents (e.g. from an
existing terminal), the extension fails to detect and track the agent
because:

1. ensureProjectScan pre-registers ALL existing JSONL files as "known",
   preventing active sessions from being picked up. Now files that are
   both large (≥3KB) and recently modified (<10min) are skipped during
   pre-registration, allowing them to be detected by terminal scanning.

2. scanForNewJsonlFiles only checks vscode.window.activeTerminal when
   adopting orphaned JSONL files. If the Claude terminal isn't focused,
   it's never found. Now all terminals are scanned to find an untracked
   terminal to adopt.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The seeding logic (smart pre-registration that skips active JSONLs)
was placed after `if (projectScanTimerRef.current) return`, meaning
it only ran on the first call. Now it runs on every call, ensuring
newly appeared files are always seeded correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@Commandershadow9 Commandershadow9 changed the title fix: improve agent detection for non-extension-spawned terminals fix: detect Claude sessions started outside of Pixel Agents Mar 9, 2026
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