Repository navigation
Description
Context
pipeline/haiku.py::call_haiku() spawns a headless claude -p subprocess per summarization. It's a tool-less, one-shot, --max-turns 1, JSON-output call — it only needs to summarize the prompt and return text. Current command:
claude -p PROMPT --output-format json --model haiku --max-turns 1 --allowedTools ""
It runs with cwd=tempfile.gettempdir() and CLAUDECODE stripped from the env.
The subprocess is doing far more than the job requires: it loads the user's global ~/.claude/CLAUDE.md, settings, hooks, and MCP servers into a call that never needed any of them. This is wasted input tokens, wasted startup, output contamination (global instructions — e.g. custom output styles — leak into summaries), and a real eviction bug (see #86 / below).
All flags below verified against claude --help on Claude Code v2.1.156. Latency figures are intentionally omitted — none have been benchmarked. The point of this issue is to land the safe wins and benchmark the rest.
The original trigger — PR #86 (withdrawn)
PR #86 added --strict-mcp-config to fix a concrete bug: without it, the subprocess boots the user's globally-configured MCP servers. For single-consumer channel plugins (Telegram = one getUpdates slot per bot) the spawned poller evicts the user's live session poller, then exits and clears the slot → the user's channel goes silent until a manual /mcp reconnect. Diagnosed on a 24/7 session where every Telegram death lined up with a [haiku] consolidation event. PR was withdrawn; the fix never landed. It should — either via --strict-mcp-config or --bare (below).
Tier 1 — pure wins (no auth change, ship these)
| Flag | Effect | Notes |
|---|---|---|
--strict-mcp-config |
With no --mcp-config given, loads zero MCP servers. |
Fixes the #86 eviction bug. No caller passes an MCP tool (only real caller consolidate.py passes no tools; tests use Read/Write). Safe. |
--setting-sources project (or narrowest valid) |
Restricts which settings JSON files load (user/project/local). |
Caveat: does NOT block CLAUDE.md discovery or hooks — only settings files. Cannot be set to empty. Partial mitigation only; --bare is the real fix (Tier 3). |
--exclude-dynamic-system-prompt-sections |
Moves the dynamic preamble (cwd, env, git status, OS) out of the static system prompt. | Trims input the summarization call doesn't need. Ignored if --system-prompt is used. |
--no-session-persistence |
Sessions not written to disk / not resumable. | We never resume these one-shots — pure win. --print only. |
--max-budget-usd <amount> |
Hard cost ceiling per call. | Cheap guardrail for overnight batch runs. --print only. |
Tier 2 — correctness / reliability
| Flag | Effect | Notes |
|---|---|---|
--json-schema <schema> |
Structured-output validation against a JSON Schema. | Could replace the brittle ===RECENT=== / ===ARCHIVE=== delimiter parsing in consolidate.py::parse_consolidation_response() with a validated {recent, archive} object. Removes a whole class of fallback-parsing edge cases. Needs a prompt rework — separate PR. |
--fallback-model <model> |
Auto-fallback when the primary model is overloaded. | Stops an overnight consolidation from hard-failing when Haiku is busy. Trade-off: a fallback call costs more. --print only. |
Tier 3 — --bare (big win, but a real trade-off — DECISION NEEDED)
--bare = "Minimal mode: skip hooks, LSP, plugin sync, attribution, auto-memory, background prefetches, keychain reads, and CLAUDE.md auto-discovery."
This single flag does everything Tier 1 isolation does and more — it's the cleanest way to make the subprocess only the summarization job, and it kills the CLAUDE.md-contamination + MCP-eviction problems at the root.
But it skips keychain reads → auth falls back to ANTHROPIC_API_KEY / apiKeyHelper. remember currently piggybacks on the user's logged-in subscription via the keychain. So --bare requires an API key and separate billing. This is the same fork as "subprocess → direct API call."
→ Decision for the team: keep subscription auth (use Tier 1 flags, skip --bare), or move to API-key auth (use --bare, or go further and drop the CLI for a direct Anthropic SDK call — which also erases the nested-session / CLAUDECODE-stripping / tempdir machinery entirely).
Env vars to investigate (NOT yet verified)
Reduce subprocess startup network chatter. The first two are well-known; the rest need verification before use:
DISABLE_TELEMETRY=1(well-known)CLAUDE_CODE_DISABLE_NONESSENTIAL_TRAFFIC=1(well-known)CLAUDE_CODE_DISABLE_AUTO_MEMORY,CLAUDE_CODE_DISABLE_BACKGROUND_TASKS— unverified, confirm they exist before relying on them
Proposed plan
- Ship now (Tier 1): add
--strict-mcp-config,--exclude-dynamic-system-prompt-sections,--no-session-persistenceto thecmdlist. Closes the fix(haiku): run summarization subprocess with --strict-mcp-config #86 bug. Suite is green and no test asserts on the cmd list, so additive flags are non-breaking. - Benchmark: wrap
call_haikuwith a timing harness, measure per-call wall time + token cost before/after, and probe whether global~/.claude/CLAUDE.mdactually leaks into output today (run a tool-less call, inspect for contamination). - Decide on
--bare/ direct-API (Tier 3) — auth/billing call for the team. - Separate PR:
--json-schemato replace delimiter parsing inconsolidate.py.
Files
pipeline/haiku.py—call_haiku()builds thecmdlist (~L56).pipeline/consolidate.py—parse_consolidation_response()delimiter parsing (~L60).tests/test_haiku.py— callers; none pass MCP tools.
Verified on Claude Code v2.1.156.
Activity
sergeclaesen commentedon Jun 5, 2026
Field report corroborating Tier 1 — specifically
--no-session-persistence.On a 24/7 Mac Mini setup this surfaces as a very visible user-facing symptom that the issue frames mainly as token-waste / contamination: the per-exchange pipeline writes a persisted session record for every
claude -pcall, and those sync straight into the desktop app's Recents list. On heavy interactive days it floods:All of them land in two junk project dirs —
~/.claude/projects/-private-tmp/and-private-var-folders-…-T/— because both callscd /tmp. Max ~17 lines each, pure pipeline artifacts, but every one shows up as amac-mini-serge-<random>entry in Recents.I patched all three call sites locally and added
--no-session-persistencenext to the existing--output-format json:scripts/save-session.sh:175(haiku) and:241(ndc)pipeline/haiku.pycmd listSmoke-tested with the exact production invocation: JSON output intact (
is_error: false), and zero new session records written. The pipeline only consumes stdout JSON, so dropping persistence is a clean win — confirms it belongs in the "ship these" tier.Still present in current HEAD (
save-session.sh:175/241,haiku.py:57). Happy to open a PR for the Tier-1 isolation flags if that helps it land.feat(haiku): isolate one-shot subprocess with --no-session-persistenc…
fdaviddpt commentedon Jun 18, 2026
Resolved by #93 — the summarizer subprocess now runs with
--no-session-persistenceand--exclude-dynamic-system-prompt-sections, so it no longer floods~/.claude/projects/with session records. Thanks @sergeclaesen for the field report with the per-day session-record counts (22 → 782 → 585) — that made the impact concrete and confirmed the fix tier.release: 0.8.0 (#106)