Skip to content

Inference.ts: recursive claude -p calls pollute resume session list #947

@rohanrichards

Description

@rohanrichards

Summary

Inference.ts runs claude -p for sentiment analysis, failure description generation, and other inference tasks. Each invocation creates a persisted session that appears in claude --resume, polluting the resume picker with hundreds of short, meaningless inference sessions.

Over normal usage, this generates 224+ ghost sessions that crowd out real conversations in the resume list.

Environment

  • PAI v4.0.0, Algorithm v3.5.0
  • Claude Code (Windows/MSYS2)
  • Inference callers: RatingCapture.hook.ts (UserPromptSubmit), FailureCapture.ts

Root Cause

Inference.ts:99 builds the claude -p command without --no-session-persistence:

const cmd = `cat "${pf}" | claude -p --model ${config.model} --output-format text --setting-sources '' --system-prompt "$(cat "${sf}")" > "${of}" 2> "${ef}"`;

The existing reliability measures (env stripping per #931, background+file approach per #26190, --setting-sources '') prevent hangs and recursive hook firing — but sessions are still written to disk and indexed in the resume picker.

Fix

Add --no-session-persistence to the claude -p command in Inference.ts:

const cmd = `cat "${pf}" | claude -p --no-session-persistence --model ${config.model} --output-format text --setting-sources '' --system-prompt "$(cat "${sf}")" > "${of}" 2> "${ef}"`;

One-line change. All callers (RatingCapture, FailureCapture, any future inference users) are fixed since they all go through inference().

Cleanup

Existing polluted sessions can be identified by grepping session JSONL files for inference markers:

grep -rl "CLASSIFY THIS MESSAGE FOR SENTIMENT\|Generate the 8-word description" ~/.claude/projects/*/*.jsonl

And safely deleted — they contain only single-turn classification prompts with no user value.

Verification

After the fix:

  1. Trigger a UserPromptSubmit hook (send any message in Claude Code)
  2. Check ls ~/.claude/projects/C--Users-rohan/*.jsonl | wc -l — count should not increase
  3. claude --resume should only show real conversations

Notes

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions