Skip to content

perf: optimize Claude Code discover() — use history.jsonl, batch lsof#96

Merged
c-h- merged 1 commit into
mainfrom
fix/claude-code-discover-perf
Mar 5, 2026
Merged

perf: optimize Claude Code discover() — use history.jsonl, batch lsof#96
c-h- merged 1 commit into
mainfrom
fix/claude-code-discover-perf

Conversation

@c-h-
Copy link
Copy Markdown
Collaborator

@c-h- c-h- commented Mar 5, 2026

Summary

  • Uses history.jsonl instead of scanning all project dirs to find active Claude Code sessions
  • Batches lsof calls for PID checks instead of one-per-session
  • Reduces discover() from timeout (>5s) to <500ms

Fixes #90

Test plan

🤖 Generated with Claude Code

@c-h- c-h- enabled auto-merge (squash) March 5, 2026 22:33
The discover() method was scanning 156 project dirs and 1,697 session
files, timing out at 5s. Claude Code maintains ~/.claude/history.jsonl
with every session's ID, project path, timestamp, and prompt text.

- Read history.jsonl as primary discovery source (~2ms vs 5s+ timeout)
- Fall back to project dir scanning only if history.jsonl doesn't exist
- Batch lsof: single call for all PIDs instead of one per PID
- Batch ps: single call for all start times instead of one per PID
- Defer expensive fields (model, tokens) to status() calls

Fixes #90

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@c-h- c-h- force-pushed the fix/claude-code-discover-perf branch from 768f2d8 to 2b2026d Compare March 5, 2026 22:34
@c-h- c-h- merged commit b7798f7 into main Mar 5, 2026
1 check passed
c-h- added a commit that referenced this pull request Mar 6, 2026
New features:
- feat: add --file flag to launch command (#95)

Bug fixes:
- fix: insert -- separator before positional prompt args (#106)
- fix: peek/status timeout on opencode sessions (#100)
- fix: use temp file for large prompts instead of CLI args (#101)

Performance:
- perf: use history.jsonl for Claude Code discover(), batch lsof calls (#96)

Co-Authored-By: Charlie Hulcher <charlie@kindo.ai>
@c-h- c-h- mentioned this pull request Mar 6, 2026
c-h- added a commit that referenced this pull request Mar 6, 2026
New features:
- feat: add --file flag to launch command (#95)

Bug fixes:
- fix: insert -- separator before positional prompt args (#106)
- fix: peek/status timeout on opencode sessions (#100)
- fix: use temp file for large prompts instead of CLI args (#101)

Performance:
- perf: use history.jsonl for Claude Code discover(), batch lsof calls (#96)

Co-authored-by: Doink (OpenClaw) <charlie+doink@kindo.ai>
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.

Bug: Claude Code adapter discover() times out with 156 project dirs / 1,697 sessions

1 participant