Skip to content

fix(harvest): exclude sub-agent transcripts and agent-generated sessions from task mining - #99

Merged
Yifan Yang (Yif-Yang) merged 1 commit into
microsoft:mainfrom
codeL1985:fix/harvest-agent-noise
Jul 12, 2026
Merged

Yifan Yang (Yif-Yang) merged 1 commit into
microsoft:mainfrom
codeL1985:fix/harvest-agent-noise

Conversation

@codeL1985

Copy link
Copy Markdown
Contributor

Problem

Harvest mines machine-generated prompts as if they were user tasks. On a machine with memory/observer plugins installed (e.g. claude-mem) and regular Agent-tool use, ~80% of mined tasks were not authored by the user:

  1. Sub-agent sidechain transcripts — Claude Code stores them at <session>/subagents/agent-*.jsonl; os.walk sweeps them in, so every Task/Agent spawn's prompt becomes a "recurring user task" (one session contributed 19 near-duplicate tasks).
  2. Other tools' agent sessions — plugins like claude-mem run their own observer agents whose transcripts look like normal multi-turn sessions, so the single-turn heuristic from Mining counts headless claude -p calls and sub-agent fan-out as user tasks, inflating recurring-task signal #62 never catches them.
  3. Expanded slash-command bodies — Claude Code injects the full command markdown as a user message; _is_meta_prompt only skips short /cmd forms, so the plugin's own /skillopt-sleep command body got mined as a task (self-harvest).

Downstream effect: the optimizer trains and gates on prompts the user never wrote.

Fix

  • Skip subagents/ directories and agent-*.jsonl files in the transcript walk (structural, no heuristics).
  • New _AGENT_SESSION_MARKERS + _is_agent_session(): drop sessions whose FIRST user prompt is a known agent brief. Ships with markers for claude-mem and this plugin's own command; user-extensible via SKILLOPT_SLEEP_AGENT_MARKERS (comma-separated), mirroring the existing SKILLOPT_SLEEP_NEG_FEEDBACK pattern.
  • _is_meta_prompt: also skip prompts containing <command-message>/<command-name> or starting with # /.

Verification

On a real ~/.claude with claude-mem installed: harvest went from 120 sessions / mostly machine-generated tasks to 55 sessions / 38 tasks, all genuinely user-authored.

🤖 Generated with Claude Code

…k mining

Three filters to stop machine-generated prompts polluting the mined task
pool (they dominated ~80% of tasks on this machine):

- _is_meta_prompt: drop expanded slash-command bodies (<command-message>
  tags or '# /' headers) — plugin self-invocations are not user intents
- _AGENT_SESSION_MARKERS + _is_agent_session: skip sessions whose first
  prompt is another tool's agent brief (claude-mem observers, CLAUDE.md
  critic sub-agents, SkillOpt-Sleep's own command body)
- load walk: skip <session>/subagents/ dirs and agent-*.jsonl files —
  Agent-tool sidechain transcripts are Claude-authored, not user tasks

Verified: harvest went from 120 sessions / mostly-noise tasks to 55
sessions / 38 real user tasks.

Co-Authored-By: Claude Fable 5 <[email protected]>
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.

2 participants