1# Research Codebase
2
3You are tasked with conducting comprehensive research across the codebase to answer user questions by spawning parallel sub-agents and synthesizing their findings.
4
5## Initial Setup:
6
7When this command is invoked, respond with:
8
9```
10I'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.
11```
12
13Then wait for the user's research query.
14
15## Steps to follow after receiving the research query:
16
171. **Read any directly mentioned files first:**
18 - If the user mentions specific files (crates, docs, JSON), read them FULLY first
19 - **IMPORTANT**: Use the Read tool WITHOUT limit/offset parameters to read entire files
20 - **CRITICAL**: Read these files yourself in the main context before spawning any sub-tasks
21 - This ensures you have full context before decomposing the research
22
232. **Analyze and decompose the research question:**
24 - Break down the user's query into composable research areas
25 - Take time to ultrathink about the underlying patterns, connections, and architectural implications the user might be seeking
26 - Identify specific components, patterns, or concepts to investigate
27 - Create a research plan using TodoWrite to track all subtasks
28 - Consider which directories, files, or architectural patterns are relevant
29
303. **Spawn parallel sub-agent tasks for comprehensive research:**
31 - Create multiple Task agents to research different aspects concurrently
32 - We now have specialized agents that know how to do specific research tasks:
33
34 **For codebase research:**
35 - Use the **codebase-locator** agent to find WHERE files and components live
36 - Use the **codebase-analyzer** agent to understand HOW specific code works
37
38 The key is to use these agents intelligently:
39 - Start with locator agents to find what exists
40 - Then use analyzer agents on the most promising findings
41 - Run multiple agents in parallel when they're searching for different things
42 - Each agent knows its job - just tell it what you're looking for
43 - Don't write detailed prompts about HOW to search - the agents already know
44
454. **Wait for all sub-agents to complete and synthesize findings:**
46 - IMPORTANT: Wait for ALL sub-agent tasks to complete before proceeding
47 - Compile all sub-agent results (both codebase and thoughts findings)
48 - Prioritize live codebase findings as primary source of truth
49 - Use thoughts/ findings as supplementary historical context
50 - Connect findings across different components
51 - Include specific file paths and line numbers for reference
52 - Verify all thoughts/ paths are correct (e.g., thoughts/allison/ not thoughts/shared/ for personal files)
53 - Highlight patterns, connections, and architectural decisions
54 - Answer the user's specific questions with concrete evidence
55
565. **Gather metadata for the research document:**
57 - Run the `zed/script/spec_metadata.sh` script to generate all relevant metadata
58 - Filename: `thoughts/shared/research/YYYY-MM-DD_HH-MM-SS_topic.md`
59
606. **Generate research document:**
61 - Use the metadata gathered in step 4
62 - Structure the document with YAML frontmatter followed by content:
63
64 ```markdown
65 ---
66 date: [Current date and time with timezone in ISO format]
67 researcher: [Researcher name from thoughts status]
68 git_commit: [Current commit hash]
69 branch: [Current branch name]
70 repository: [Repository name]
71 topic: "[User's Question/Topic]"
72 tags: [research, codebase, relevant-component-names]
73 status: complete
74 last_updated: [Current date in YYYY-MM-DD format]
75 last_updated_by: [Researcher name]
76 ---
77
78 # Research: [User's Question/Topic]
79
80 **Date**: [Current date and time with timezone from step 4]
81 **Researcher**: [Researcher name from thoughts status]
82 **Git Commit**: [Current commit hash from step 4]
83 **Branch**: [Current branch name from step 4]
84 **Repository**: [Repository name]
85
86 ## Research Question
87
88 [Original user query]
89
90 ## Summary
91
92 [High-level findings answering the user's question]
93
94 ## Detailed Findings
95
96 ### [Component/Area 1]
97
98 - Finding with reference ([file.ext:line](link))
99 - Connection to other components
100 - Implementation details
101
102 ### [Component/Area 2]
103
104 ...
105
106 ## Code References
107
108 - `path/to/file.py:123` - Description of what's there
109 - `another/file.ts:45-67` - Description of the code block
110
111 ## Architecture Insights
112
113 [Patterns, conventions, and design decisions discovered]
114
115 ## Historical Context (from thoughts/)
116
117 [Relevant insights from thoughts/ directory with references]
118
119 - `thoughts/shared/something.md` - Historical decision about X
120 - `thoughts/local/notes.md` - Past exploration of Y
121 Note: Paths exclude "searchable/" even if found there
122
123 ## Related Research
124
125 [Links to other research documents in thoughts/shared/research/]
126
127 ## Open Questions
128
129 [Any areas that need further investigation]
130 ```
131
1327. **Add GitHub permalinks (if applicable):**
133 - Check if on main branch or if commit is pushed: `git branch --show-current` and `git status`
134 - If on main/master or pushed, generate GitHub permalinks:
135 - Get repo info: `gh repo view --json owner,name`
136 - Create permalinks: `https://github.com/{owner}/{repo}/blob/{commit}/{file}#L{line}`
137 - Replace local file references with permalinks in the document
138
1398. **Handle follow-up questions:**
140 - If the user has follow-up questions, append to the same research document
141 - Update the frontmatter fields `last_updated` and `last_updated_by` to reflect the update
142 - Add `last_updated_note: "Added follow-up research for [brief description]"` to frontmatter
143 - Add a new section: `## Follow-up Research [timestamp]`
144 - Spawn new sub-agents as needed for additional investigation
145 - Continue updating the document and syncing
146
147## Important notes:
148
149- Always use parallel Task agents to maximize efficiency and minimize context usage
150- Always run fresh codebase research - never rely solely on existing research documents
151- The thoughts/ directory provides historical context to supplement live findings
152- Focus on finding concrete file paths and line numbers for developer reference
153- Research documents should be self-contained with all necessary context
154- Each sub-agent prompt should be specific and focused on read-only operations
155- Consider cross-component connections and architectural patterns
156- Include temporal context (when the research was conducted)
157- Link to GitHub when possible for permanent references
158- Keep the main agent focused on synthesis, not deep file reading
159- Encourage sub-agents to find examples and usage patterns, not just definitions
160- Explore all of thoughts/ directory, not just research subdirectory
161- **File reading**: Always read mentioned files FULLY (no limit/offset) before spawning sub-tasks
162- **Critical ordering**: Follow the numbered steps exactly
163 - ALWAYS read mentioned files first before spawning sub-tasks (step 1)
164 - ALWAYS wait for all sub-agents to complete before synthesizing (step 4)
165 - ALWAYS gather metadata before writing the document (step 5 before step 6)
166 - NEVER write the research document with placeholder values
167- **Frontmatter consistency**:
168 - Always include frontmatter at the beginning of research documents
169 - Keep frontmatter fields consistent across all research documents
170 - Update frontmatter when adding follow-up research
171 - Use snake_case for multi-word field names (e.g., `last_updated`, `git_commit`)
172 - Tags should be relevant to the research topic and components studied