claude-code - 💡(How to fix) Fix Does delegating work to `claude -p` subprocesses reduce context accumulation in the parent session?

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…

Root Cause

My hypothesis is that Pattern B delays auto compaction in the parent session because:

  • claude -p runs in its own isolated context window
  • All intermediate tool calls (file reads, searches, reasoning) stay inside the subprocess
  • The parent session only sees the final output, so its context accumulates much slower

Code Example

Pattern A (direct):
  user → Claude Code → does all file reads, searches, analysis
  → context grows fast → auto compact kicks in → loses earlier instructions

Pattern B (delegated):
  user → Claude Code → claude -p subprocess (heavy research/analysis)
  → parent only receives final stdout → context stays lean
RAW_BUFFERClick to expand / collapse

I've been using a pattern where instead of having Claude Code do everything directly, I delegate heavy subtasks to claude -p subprocesses (either directly or via a Python orchestrator script).

Pattern A (direct):
  user → Claude Code → does all file reads, searches, analysis
  → context grows fast → auto compact kicks in → loses earlier instructions

Pattern B (delegated):
  user → Claude Code → claude -p subprocess (heavy research/analysis)
  → parent only receives final stdout → context stays lean

My hypothesis is that Pattern B delays auto compaction in the parent session because:

  • claude -p runs in its own isolated context window
  • All intermediate tool calls (file reads, searches, reasoning) stay inside the subprocess
  • The parent session only sees the final output, so its context accumulates much slower

Questions:

  1. Is this understanding correct — does claude -p run in a completely separate context window from the parent?
  2. If so, is this a recommended pattern for long-running or large tasks where context pressure is a concern?
  3. Are there any gotchas beyond "if the subprocess returns a huge output, the parent context still grows"?

For context, I'm considering this for a workflow that processes a large batch of customer support tickets — a Python script iterates through each ticket, calls claude -p to generate a draft response, then the script handles validation and posting. The parent Claude Code session would just monitor the script execution.

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING