Skip to content

setup: .claude/rules/grepai-first.md synced unconditionally even when grepai MCP is not configured #7

@Stashub

Description

@Stashub

Summary

When /brewcode:setup runs on a system without grepai configured,
the SessionStart hook correctly detects this:

SessionStart:startup says: grepai: not configured

Nevertheless, setup synchronizes .claude/rules/grepai-first.md into
the project. The rule contains a directive that every subagent reads:

FIRST grepai mcp for code exploration. Params → MCP descriptions.

Agents receive instructions to use a non-existent MCP server. This
pollutes every agent's prompt with a dead directive.

Root cause

brewcode/skills/setup/scripts/setup.sh (around lines 97-99):

# grepai-first: always sync (plugin-managed rule)
if [ -f "$PLUGIN_TEMPLATES/rules/grepai-first.md.template" ]; then
  sync_template "$PLUGIN_TEMPLATES/rules/grepai-first.md.template" \
                ".claude/rules/grepai-first.md"
fi

The "always sync" comment is explicit: the script ignores grepai
availability. No grepai_configured helper exists anywhere in
setup.sh — grepai detection lives only in the SessionStart hook,
not in setup itself.

Environment

  • Claude Code: v2.1.107
  • Plugin: claude-brewcode 3.5.2
  • OS: Windows 11 Pro, MSYS2 (grepai MCP not installed)

Reproduction

  1. Confirm grepai is not configured (SessionStart log shows
    grepai: not configured).
  2. Run /brewcode:setup.
  3. Open .claude/rules/grepai-first.md — exists with live
    directives referencing a missing tool.

Expected

Either:

  1. Skip syncing when grepai is not configured.
  2. Remove an existing grepai-first.md if grepai becomes
    unavailable between setup runs.
  3. Render the file with a conditional header: "This rule is inactive
    because grepai MCP is not configured in this environment."

Proposed fix

Add a grepai detection helper to setup.sh. The SessionStart hook
already performs this check — the logic can be extracted or
duplicated:

grepai_configured() {
  # Reuse the same detection the SessionStart hook uses.
  # Adjust the concrete check to match the actual MCP registry
  # location in your target environments.
  [ -f "$HOME/.claude/mcp.json" ] && grep -q '"grepai"' "$HOME/.claude/mcp.json"
}

Then wrap the grepai-first.md sync:

if grepai_configured && [ -f "$PLUGIN_TEMPLATES/rules/grepai-first.md.template" ]; then
  sync_template "$PLUGIN_TEMPLATES/rules/grepai-first.md.template" \
                ".claude/rules/grepai-first.md"
elif [ -f ".claude/rules/grepai-first.md" ]; then
  rm ".claude/rules/grepai-first.md"
fi

The exact MCP config path may differ per environment — the author
knows the correct location better. The pattern is what matters:
check before sync, clean up on absence.

Impact

Low severity by itself — Claude usually recognizes the tool is
missing and falls back to native Grep. But the dead directive
pollutes every agent's prompt and undermines the credibility of
.claude/rules/ as a source of applicable guidance.

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