Vanguard
Delegate codebase searches to GLM-4.7 via background subagent. You remain free to do other work and receive automatic notification when complete.
When to Use
- •Finding code patterns across the codebase
- •Locating implementations of specific features
- •Searching for function/class/variable definitions
- •Exploring unfamiliar codebases
- •Any search that might require multiple grep/rg commands
When NOT to Use
- •You already know the file path (use Read directly)
- •Simple single-file search (use Grep directly)
- •Quick lookups that take < 5 seconds
Workflow
- •User requests a search (e.g., "find where authentication is implemented")
- •Launch background subagent with GLM delegation
- •Continue with other tasks or conversation
- •Receive notification when search completes
- •Subagent verifies GLM results before reporting
- •Report verified results to user
Implementation
Use the Task tool with these parameters:
code
Task(
description="GLM quick search: {brief description}",
subagent_type="general-purpose",
run_in_background=true,
max_turns=30, # GLM call + verification reads + summarization
prompt="""
Call the delegate_to_glm MCP tool with:
task: "{search_instructions}"
working_dir: "{project_root}"
Search instructions should include:
- Use rg (ripgrep) for fast searching
- Specific patterns or keywords to find
- File types or directories to focus on
- Output format: file:line with brief context
IMPORTANT: After GLM returns results, you MUST verify them:
1. For each reported file:line, use Read tool to check the actual content
2. Confirm the code/pattern GLM described actually exists at that location
3. If GLM reported something incorrectly, exclude it from your report
4. Only include verified findings in your final summary
Report format:
- Verified files with line numbers
- Actual code snippet or description (from your verification)
- Any discrepancies found in GLM's results
"""
)
Example Prompts
Find feature implementation
code
Task(
description="GLM search: authentication",
subagent_type="general-purpose",
run_in_background=true,
max_turns=30,
prompt="""
Call delegate_to_glm MCP tool:
task: "Find where user authentication is implemented in this Go project.
Use rg to search for:
- rg -n 'func.*Auth|func.*Login|func.*Verify' --type go
- rg -n 'middleware.*auth' --type go -i
Return file:line for each match."
working_dir: {project_root}
After GLM returns, verify the top 3-5 results:
- Read each file at the reported line
- Confirm the authentication logic exists there
- Report only verified findings with actual code context
"""
)
Find Clean Architecture violations
code
Task(
description="GLM search: architecture violations",
subagent_type="general-purpose",
run_in_background=true,
max_turns=30,
prompt="""
Call delegate_to_glm MCP tool:
task: "Check for Clean Architecture violations.
Use rg to find domain layer importing infrastructure:
- rg -n 'import.*infrastructure|protocol|data' internal/feature/*/domain/ --type go
Report any violations as file:line, or 'No violations found'."
working_dir: {project_root}
If GLM reports violations, verify each one:
- Read the import block of each reported file
- Confirm it actually imports from infrastructure/protocol/data
- Distinguish real violations from false positives (e.g., comments, string literals)
"""
)
Find TODO/FIXME comments
code
Task(
description="GLM search: TODOs",
subagent_type="general-purpose",
run_in_background=true,
max_turns=30,
prompt="""
Call delegate_to_glm MCP tool:
task: "Find all TODO and FIXME comments in the codebase.
Use: rg -n 'TODO|FIXME' --type go --type proto
Return file:line for each match."
working_dir: {project_root}
Verify a sample of results (at least 3-5):
- Read the actual lines to confirm they are real TODO/FIXME comments
- Summarize by category or urgency based on verified content
"""
)
Tips
- •Always use
rg(ripgrep) instead ofgrepfor speed - •Specify
--typeto limit search scope - •Use
-nflag to include line numbers - •For large results, ask GLM to summarize top findings
- •Set
max_iterationshigher (15-20) for complex searches
Configuration
| Parameter | Recommended | Description |
|---|---|---|
| max_turns (Task) | 30 | Subagent turns for GLM call + verification |
| max_iterations (GLM) | 15 | GLM tool calls within delegate_to_glm |
| working_dir | project root | Base directory for searches |
Notes
- •Results come via automatic notification (no polling needed)
- •GLM uses bash, read_file, write_file internally
- •For sync (blocking) searches, use delegate_to_glm directly without subagent
- •Verification is critical: GLM may hallucinate or misinterpret results; always verify before reporting to user