Skip to content

[Feature]: Env-var opt-out for subagent Agent-injection - foreground agents can hang on forced ctx_* calls #832

@tomerikjansen-crypto

Description

@tomerikjansen-crypto

Summary

The Agent PreToolUse hook appends the full <context_window_protection> routing block to every subagent prompt, instructing it that it MUST use ctx_* tools for analysis/fetch. When a subagent runs in the foreground (the default for Claude Code's Agent tool) and one of those forced ctx_* calls blocks (sandbox runtime startup, or a network call in ctx_fetch_and_index with no surfaced timeout), the entire parent session freezes until the user hard-interrupts, which can lose the subagent's work.

There is currently no opt-out. I'd like to request a first-class one (env var and/or per-subagent-type skip).

Environment

  • context-mode 1.0.162 (plugin via marketplace, autoUpdate on)
  • Claude Code CLI, Windows 11, model Opus 4.8
  • MCP server running normally in the main session (ctx_doctor all green)

Why the existing fixes don't fully cover this

Proposed (any one resolves it)

  1. Env-var opt-out, e.g. CONTEXT_MODE_DISABLE_AGENT_INJECTION=1, checked in the canonical === "Agent" branch of routing.mjs, returning pass-through instead of the modified prompt.
  2. Per-subagent-type skip (delivers the Agent PreToolUse routing stalls read-only subagents: injected block omits the ToolSearch bootstrap for deferred ctx_* tools #724 follow-up): skip injection for read-only types (Explore, etc.), optionally a configurable allow/deny list as suggested in [Bug]: Context Mode should not take over cc tool call that would run inside subagents #155.
  3. At minimum, document that the Agent injection exists and how to disable it.

Rationale for opt-out over removal: the injection is genuinely valuable in the main session (it kept ~28 MB out of context in one of my sessions). But a subagent has its own isolated, short-lived context, and the parent only ever sees the subagent's summary, so the in-subagent ctx_* benefit is small while the hang risk is real. An opt-out keeps the default behavior for those who want it.

Current workaround

A local self-healing SessionStart hook that strips the Agent matcher from the plugin's hooks.json after each update (idempotent, pure Node stdlib, never imports from the plugin dir). It works, but it edits plugin-cache files and must re-apply on every version bump, so a supported flag would be much cleaner.

Happy to send a PR for option 1 if you're open to it.

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