Skip to content

Subagents don't receive the codebase-memory-mcp code-discovery reminder #631

Description

@halindrome

Problem

The installer registers a SessionStart reminder hook for Claude Code (matchers startup/resume/clear/compact) that tells the agent to prefer codebase-memory-mcp tools (search_graph, trace_path, get_code_snippet, …) over grep/file-read for code discovery.

But subagents spawned via the Agent tool do not fire SessionStart — only SubagentStart/SubagentStop fire for them. So every subagent starts CMM-unaware and falls back to grep/file-read, exactly the behavior the SessionStart reminder exists to prevent. On agents that lean on subagents for exploration, much of the code navigation happens in precisely the contexts the reminder never reaches.

Proposal

Register a Claude Code SubagentStart hook (matcher *, all agent types) that injects a leaner variant of the same code-discovery guidance via hookSpecificOutput.additionalContext. Leaner = it omits the "run index_repository first" step, since the parent session has already indexed the project.

Notes:

  • SubagentStart injects context only via a JSON object on stdout (not the plain-text form SessionStart accepts), so the generated hook script emits a static JSON literal — no runtime escaping, no python3/jq dependency.
  • SubagentStart is Claude-Code-specific (added in Claude Code 2.0.43, command-type hooks only). It belongs in the Claude installer path only; Codex/Gemini/etc. have no equivalent subagent-start event. The guidance text stays tool-neutral, so the agent-agnostic boundary is preserved (only the plumbing is Claude-specific).
  • Advisory, non-blocking. Older Claude Code (< 2.0.43) simply ignores the unknown event key (fail-open).

Scope

Small, self-contained: a sibling to the existing SessionStart reminder in the Claude installer, plus a unit test (~80 LOC).

Metadata

Metadata

Assignees

No one assigned

    Labels

    editor/integrationEditor compatibility and CLI integrationenhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions