/insights includes Claude Agent SDK sessions, skewing results
Description
/insights analyzes all session JSONL files in ~/.claude/projects/, but this directory also contains sessions created by the Claude Agent SDK (via claude-agent-sdk-python). There's no way to distinguish between interactive Claude Code sessions and programmatic Agent SDK sessions, so /insights mixes them together, producing inaccurate usage reports.
How it happens
The Agent SDK's SubprocessCLITransport spawns the Claude Code CLI as a subprocess, passing cwd from ClaudeAgentOptions. The CLI then stores session files in ~/.claude/projects/{encoded-cwd}/ — the same location it uses for interactive Claude Code sessions.
For example, an Agent SDK app with cwd=/Users/me/.observe-agent/observe-agent-chat-sessions creates sessions at:
~/.claude/projects/-Users-me--observe-agent-observe-agent-chat-sessions/*.jsonl
These are indistinguishable from regular Claude Code sessions.
Impact
In my case, I had 159 Agent SDK sessions mixed in with my Claude Code sessions. /insights reported 197 total sessions, but a significant portion were from a programmatic agent, not interactive use. This skewed:
- Project area analysis — agent runs were categorized as if I was doing that work interactively
- Friction analysis — friction patterns from the agent's behavior were attributed to my interactive workflow
- Interaction style narrative — session counts and patterns reflected agent behavior, not my usage
Expected behavior
One or more of:
/insightsshould distinguish between Claude Code sessions and Agent SDK sessions (the CLI setsCLAUDE_CODE_ENTRYPOINT=sdk-pyvia env — this could be recorded in session metadata)/insightsshould have a flag to exclude specific project directories- The Agent SDK should store sessions in a separate directory (e.g.,
~/.claude/sdk-sessions/) rather than sharing~/.claude/projects/
Environment
- Claude Code: 2.3.1
- claude-agent-sdk-python: 0.1.19
- OS: macOS (Darwin 25.2.0)
This issue has 2 comments on GitHub. Read the full discussion on GitHub ↗