Conduct comprehensive codebase research using parallel sub-agents
Conducts comprehensive codebase research using parallel sub-agents to document existing systems.
/plugin marketplace add coalesce-labs/catalyst/plugin install catalyst-dev@catalystinheritYou are tasked with conducting comprehensive research across the codebase to answer user questions by spawning parallel sub-agents and synthesizing their findings.
Before executing, verify all required tools and systems:
# 1. Validate thoughts system (REQUIRED)
if [[ -f "scripts/validate-thoughts-setup.sh" ]]; then
./scripts/validate-thoughts-setup.sh || exit 1
else
# Inline validation if script not found
if [[ ! -d "thoughts/shared" ]]; then
echo "❌ ERROR: Thoughts system not configured"
echo "Run: ./scripts/humanlayer/init-project.sh . {project-name}"
exit 1
fi
fi
# 2. Validate plugin scripts
if [[ -f "${CLAUDE_PLUGIN_ROOT}/scripts/check-prerequisites.sh" ]]; then
"${CLAUDE_PLUGIN_ROOT}/scripts/check-prerequisites.sh" || exit 1
fi
When this command is invoked, respond with:
I'm ready to research the codebase. Please provide your research question or area of interest, and I'll analyze it thoroughly by exploring relevant components and connections.
Then wait for the user's research query.
Create multiple Task agents to research different aspects concurrently.
We have specialized agents that know how to do specific research tasks:
For codebase research:
IMPORTANT: All agents are documentarians, not critics. They will describe what exists without suggesting improvements or identifying issues.
For thoughts directory (if using thoughts system):
For external research (only if user explicitly asks):
For Linear tickets (if relevant):
The key is to use these agents intelligently:
Example of spawning parallel research tasks:
I'm going to spawn 3 parallel research tasks:
Task 1 - Find WHERE components live:
"Use codebase-locator to find all files related to [topic]. Focus on [specific directories if known]."
Task 2 - Understand HOW it works:
"Use codebase-analyzer to analyze [specific component] and document how it currently works. Include data flow and key integration points."
Task 3 - Find existing patterns:
"Use codebase-pattern-finder to find similar implementations of [pattern] in the codebase. Show concrete examples."
file.ext:line)Collect metadata for the research document:
If using thoughts system with metadata script:
hack/spec_metadata.sh or equivalent to generate metadataIf using simple approach:
git rev-parse HEADgit branch --show-current.git/config or working directoryDocument Storage:
All research documents are stored in the thoughts system for persistence:
Required location: thoughts/shared/research/YYYY-MM-DD-{ticket}-{description}.md
Why thoughts/shared/:
humanlayer thoughts syncFilename format:
thoughts/shared/research/YYYY-MM-DD-PROJ-XXXX-description.mdthoughts/shared/research/YYYY-MM-DD-description.mdReplace PROJ with your ticket prefix from .claude/config.json.
Examples:
thoughts/shared/research/2025-01-08-PROJ-1478-parent-child-tracking.mdthoughts/shared/research/2025-01-08-authentication-flow.md (no ticket)Create a structured research document with the following format:
---
date: YYYY-MM-DDTHH:MM:SS+TZ
researcher: { your-name }
git_commit: { commit-hash }
branch: { branch-name }
repository: { repo-name }
topic: "{User's Research Question}"
tags: [research, codebase, { component-names }]
status: complete
last_updated: YYYY-MM-DD
last_updated_by: { your-name }
---
# Research: {User's Research Question}
**Date**: {date/time with timezone} **Researcher**: {your-name} **Git Commit**: {commit-hash}
**Branch**: {branch-name} **Repository**: {repo-name}
## Research Question
{Original user query, verbatim}
## Summary
{High-level documentation of what you found. 2-3 paragraphs explaining the current state of the
system in this area. Focus on WHAT EXISTS, not what should exist.}
## Detailed Findings
### {Component/Area 1}
**What exists**: {Describe the current implementation}
- File location: `path/to/file.ext:123`
- Current behavior: {what it does}
- Key functions/classes: {list with file:line references}
**Connections**: {How this component integrates with others}
- Calls: `other-component.ts:45` - {description}
- Used by: `consumer.ts:67` - {description}
**Implementation details**: {Technical specifics without evaluation}
### {Component/Area 2}
{Same structure as above}
### {Component/Area N}
{Continue for all major findings}
## Code References
Quick reference of key files and their roles:
- `path/to/file1.ext:123-145` - {What this code does}
- `path/to/file2.ext:67` - {What this code does}
- `path/to/file3.ext:200-250` - {What this code does}
## Architecture Documentation
{Document the current architectural patterns, conventions, and design decisions observed in the
code. This is descriptive, not prescriptive.}
### Current Patterns
- **Pattern 1**: {How it's implemented in the codebase}
- **Pattern 2**: {How it's implemented in the codebase}
### Data Flow
{Document how data moves through the system in this area}
Component A → Component B → Component C {Describe what happens at each step}
### Key Integrations
{Document how different parts of the system connect}
## Historical Context (from thoughts/)
{ONLY if using thoughts system}
{Include insights from thoughts/ documents that provide context}
- `thoughts/shared/research/previous-doc.md` - {Key decision or insight}
- `thoughts/shared/plans/plan-123.md` - {Related implementation detail}
## Related Research
{Links to other research documents that touch on related topics}
- `research/YYYY-MM-DD-related-topic.md` - {How it relates}
## Open Questions
{Areas that would benefit from further investigation - NOT problems to fix, just areas where understanding could be deepened}
- {Question 1}
- {Question 2}
If you're on the main/master branch OR if the commit is pushed:
Generate GitHub permalinks and replace file references:
https://github.com/{owner}/{repo}/blob/{commit-hash}/{file-path}#L{line}
For line ranges:
https://github.com/{owner}/{repo}/blob/{commit-hash}/{file-path}#L{start}-L{end}
If working on a feature branch that's not pushed yet:
path/to/file.ext:lineIf using thoughts system:
humanlayer thoughts sync to sync the thoughts directoryIf using simple approach:
Present to user:
✅ Research complete!
**Research document**: {file-path}
## Summary
{2-3 sentence summary of key findings}
## Key Files
{Top 3-5 most important file references}
## What I Found
{Brief overview - save details for the document}
---
## 📊 Context Status
Current usage: {X}% ({Y}K/{Z}K tokens)
{If >60%}: ⚠️ **Recommendation**: Context is getting full. For best results in the planning phase, I
recommend clearing context now.
**Options**:
1. ✅ Clear context now (recommended) - Close this session and start fresh for planning
2. Create handoff to pause work
3. Continue anyway (may impact performance)
**Why clear?** Fresh context ensures optimal AI performance for the planning phase, which will load
additional files and research.
{If <60%}: ✅ Context healthy. Ready to proceed to planning phase if needed.
---
Would you like me to:
1. Dive deeper into any specific area?
2. Create an implementation plan based on this research?
3. Explore related topics?
If the user has follow-up questions:
DO NOT create a new research document - append to the same one
Update frontmatter fields:
last_updated: {new date}last_updated_by: {your name}last_updated_note: "{Brief note about what was added}"Add new section to existing document:
---
## Follow-up Research: {Follow-up Question}
**Date**: {date} **Updated by**: {your-name}
### Additional Findings
{New research results using same structure as above}
Monitor Your Context Throughout Research:
Example Warning:
⚠️ Context Usage Alert: Currently at 65% (130K/200K tokens)
Research is complete, but context is getting full. Before continuing to
planning phase, I recommend creating a handoff to preserve this work
and start fresh.
Would you like me to:
1. Create a handoff now (recommended)
2. Continue and clear context manually
3. Proceed anyway (not recommended - may impact planning quality)
**Why this matters**: The planning phase will load additional context.
Starting fresh ensures optimal AI performance.
When to Warn:
Educate the User:
/create-handoff command existsthoughts/ directory (if used) provides historical context, not primary sourceIf using thoughts system:
thoughts/searchable/ is a special directory - paths found there should be documented as their
actual locationthoughts/searchable/allison/notes.md → document as thoughts/allison/notes.mdallison/, don't change to shared/)If NOT using thoughts system:
research/ directory in workspace rootlast_updated fields when appending follow-upsIf a Linear ticket is associated with the research, the command can automatically update the ticket status.
Ticket detection (same as other commands):
/research_codebase PROJ-123Status updates:
At research start (Step 2 - after reading mentioned files):
# If ticket is detected or provided
if [[ -n "$ticketId" ]]; then
# Check if Linearis CLI is available
if command -v linearis &> /dev/null; then
# Update ticket state to "Research" (use --state NOT --status!)
linearis issues update "$ticketId" --state "Research"
# Add comment (use 'comments create' NOT 'issues comment'!)
linearis comments create "$ticketId" --body "Starting research: [user's research question]"
else
echo "⚠️ Linearis CLI not found - skipping Linear ticket update"
fi
fi
After research document is saved (Step 6 - after generating document):
# Attach research document to ticket
if [[ -n "$ticketId" ]] && [[ -n "$githubPermalink" ]]; then
# Check if Linearis CLI is available
if command -v linearis &> /dev/null; then
# Add completion comment with research doc link
linearis comments create "$ticketId" \
--body "Research complete! See findings: $githubPermalink"
else
echo "⚠️ Linearis CLI not found - skipping Linear ticket update"
fi
fi
With ticket:
/catalyst-dev:research_codebase PROJ-123
> "How does authentication work?"
What happens:
Without ticket:
/catalyst-dev:research_codebase
> "How does authentication work?"
What happens:
Uses the same Linear configuration as other commands from .claude/config.json:
linear.teamIdlinear.thoughtsRepoUrl (for GitHub permalinks)If Linear MCP not available:
If ticket not found:
If status update fails:
This command integrates with the complete development workflow:
/research-codebase → research document (+ Linear: Research)
↓
/create-plan → implementation plan (+ Linear: Planning)
↓
/implement-plan → code changes (+ Linear: In Progress)
↓
/describe-pr → PR created (+ Linear: In Review)
How it connects:
research_codebase → Linear: Moves ticket to "Research" status and attaches research document
research_codebase → create_plan: Research findings provide foundation for planning. The create_plan command can reference research documents in its "References" section.
Research before planning: Always research the codebase first to understand what exists before planning changes.
Shared agents: Both research_codebase and create_plan use the same specialized agents (codebase-locator, codebase-analyzer, codebase-pattern-finder).
Documentation persistence: Research documents serve as permanent reference for future work.
# User starts research
/research-codebase
# You respond with initial prompt
# User asks: "How does authentication work in the API?"
# You execute:
# 1. Read any mentioned files fully
# 2. Decompose into research areas (auth middleware, token validation, session management)
# 3. Spawn parallel agents:
# - codebase-locator: Find auth-related files
# - codebase-analyzer: Understand auth middleware implementation
# - codebase-pattern-finder: Find auth usage patterns
# - thoughts-locator: Find previous auth discussions (if using thoughts)
# 4. Wait for all agents
# 5. Synthesize findings
# 6. Generate research document at research/2025-01-08-authentication-system.md
# 7. Present summary to user
# User follows up: "How does it integrate with the database?"
# You append to same document with new findings
After saving the research document, add it to workflow context:
if [[ -f "${CLAUDE_PLUGIN_ROOT}/scripts/workflow-context.sh" ]]; then
"${CLAUDE_PLUGIN_ROOT}/scripts/workflow-context.sh" add research "$DOC_PATH" "${TICKET_ID:-null}"
fi
This command is adapted from HumanLayer's research_codebase command. Key differences for portability:
research/ directory.claude/config.json or use PROJ- placeholderexternal-research agent instead of web-search-researcherThe core workflow and philosophy remain the same: parallel sub-agents, documentarian mindset, and structured output.