Files
humanlayer/.claude/commands/research_codebase.md
Allison Durham b175cb1f44 Quick changes (#247)
* quick script to go alongside the `hack/create_worktree.sh`

* add `make setup` to CLAUDE.md

* TODO system

* commands added for claude for us to share

* formatting

* take feedback from ellipsis

* create linear ticket

* formatting
2025-06-25 12:37:49 -07:00

9.7 KiB

Research Codebase

You are tasked with conducting comprehensive research across the codebase to answer user questions by spawning parallel sub-agents and synthesizing their findings.

Initial Setup:

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.

Steps to follow after receiving the research query:

  1. Analyze and decompose the research question:

    • Break down the user's query into composable research areas
    • Identify specific components, patterns, or concepts to investigate
    • Create a research plan using TodoWrite to track all subtasks
    • Consider which directories, files, or architectural patterns are relevant
  2. Spawn parallel sub-agent tasks for comprehensive research:

    • Create multiple Task agents to research different aspects concurrently
    • Always include these parallel tasks:
      • Codebase exploration tasks (one for each relevant component/directory)
      • Thoughts directory exploration task (to find historical context and insights)
    • Each codebase sub-agent should focus on a specific directory, component, or question
    • Write detailed prompts for each sub-agent following these guidelines:
      • Instruct them to use READ-ONLY tools (Read, Grep, Glob, LS)
      • Ask for specific file paths and line numbers
      • Request they identify connections between components
      • Have them note architectural patterns and conventions
      • Ask them to find examples of usage or implementation
    • Example codebase sub-agent prompt:
      Research [specific component/pattern] in [directory/module]:
      1. Find all files related to [topic]
      2. Identify how [concept] is implemented (include file:line references)
      3. Look for connections to [related components]
      4. Find examples of usage in [relevant areas]
      5. Note any patterns or conventions used
      Return: File paths, line numbers, and concise explanations of findings
      
    • Thoughts directory sub-agent prompt:
      Explore the thoughts/ directory for context related to [topic]:
      1. Search for any relevant information in thoughts/ (including shared/, local/, etc.)
      2. Look for design decisions, past research, PR descriptions, or implementation notes
      3. Find any historical context about [specific components/patterns]
      4. Note any architectural decisions or trade-offs discussed
      Remember: This information is historical context, not current truth
      IMPORTANT: If you find files in thoughts/searchable/, report the actual path by removing only "searchable/"
      Examples:
      - thoughts/searchable/allison/notes.md → thoughts/allison/notes.md
      - thoughts/searchable/shared/research/file.md → thoughts/shared/research/file.md
      - thoughts/searchable/allison/old_stuff/notes.md → thoughts/allison/old_stuff/notes.md
      DO NOT change the subdirectory structure - only remove "searchable/" from the path
      Return: Relevant findings with correct file paths and key insights
      
  3. Wait for all sub-agents to complete and synthesize findings:

    • IMPORTANT: Wait for ALL sub-agent tasks to complete before proceeding
    • Compile all sub-agent results (both codebase and thoughts findings)
    • Prioritize live codebase findings as primary source of truth
    • Use thoughts/ findings as supplementary historical context
    • Connect findings across different components
    • Include specific file paths and line numbers for reference
    • Verify all thoughts/ paths are correct (e.g., thoughts/allison/ not thoughts/shared/ for personal files)
    • Highlight patterns, connections, and architectural decisions
    • Answer the user's specific questions with concrete evidence
  4. Gather metadata for the research document:

    • Get current date and time with timezone: date '+%Y-%m-%d %H:%M:%S %Z'
    • Get git commit from repository root: cd $(git rev-parse --show-toplevel) && git log -1 --format=%H
    • Get current branch: git branch --show-current
    • Get researcher name from thoughts system: Parse humanlayer thoughts status output for "User: " line
    • Get repository name: basename $(git rev-parse --show-toplevel)
    • Create timestamp-based filename using date without timezone: date '+%Y-%m-%d_%H-%M-%S'
    • Format: thoughts/shared/research/YYYY-MM-DD_HH-MM-SS_topic.md
  5. Generate research document:

    • Use the metadata gathered in step 4
    • Structure the document with YAML frontmatter followed by content:
      ---
      date: [Current date and time with timezone in ISO format]
      researcher: [Researcher name from thoughts status]
      git_commit: [Current commit hash]
      branch: [Current branch name]
      repository: [Repository name]
      topic: "[User's Question/Topic]"
      tags: [research, codebase, relevant-component-names]
      status: complete
      last_updated: [Current date in YYYY-MM-DD format]
      last_updated_by: [Researcher name]
      ---
      
      # Research: [User's Question/Topic]
      
      **Date**: [Current date and time with timezone from step 4]
      **Researcher**: [Researcher name from thoughts status]
      **Git Commit**: [Current commit hash from step 4]
      **Branch**: [Current branch name from step 4]
      **Repository**: [Repository name]
      
      ## Research Question
      [Original user query]
      
      ## Summary
      [High-level findings answering the user's question]
      
      ## Detailed Findings
      
      ### [Component/Area 1]
      - Finding with reference ([file.ext:line](link))
      - Connection to other components
      - Implementation details
      
      ### [Component/Area 2]
      ...
      
      ## Code References
      - `path/to/file.py:123` - Description of what's there
      - `another/file.ts:45-67` - Description of the code block
      
      ## Architecture Insights
      [Patterns, conventions, and design decisions discovered]
      
      ## Historical Context (from thoughts/)
      [Relevant insights from thoughts/ directory with references]
      - `thoughts/shared/something.md` - Historical decision about X
      - `thoughts/local/notes.md` - Past exploration of Y
      Note: Paths exclude "searchable/" even if found there
      
      ## Related Research
      [Links to other research documents in thoughts/shared/research/]
      
      ## Open Questions
      [Any areas that need further investigation]
      
  6. Add GitHub permalinks (if applicable):

    • Check if on main branch or if commit is pushed: git branch --show-current and git status
    • If on main/master or pushed, generate GitHub permalinks:
      • Get repo info: gh repo view --json owner,name
      • Create permalinks: https://github.com/{owner}/{repo}/blob/{commit}/{file}#L{line}
    • Replace local file references with permalinks in the document
  7. Sync and present findings:

    • Run humanlayer thoughts sync to sync the thoughts directory
    • Present a concise summary of findings to the user
    • Include key file references for easy navigation
    • Ask if they have follow-up questions or need clarification
  8. Handle follow-up questions:

    • If the user has follow-up questions, append to the same research document
    • Update the frontmatter fields last_updated and last_updated_by to reflect the update
    • Add last_updated_note: "Added follow-up research for [brief description]" to frontmatter
    • Add a new section: ## Follow-up Research [timestamp]
    • Spawn new sub-agents as needed for additional investigation
    • Continue updating the document and syncing

Important notes:

  • Always use parallel Task agents to maximize efficiency and minimize context usage
  • Always run fresh codebase research - never rely solely on existing research documents
  • The thoughts/ directory provides historical context to supplement live findings
  • Focus on finding concrete file paths and line numbers for developer reference
  • Research documents should be self-contained with all necessary context
  • Each sub-agent prompt should be specific and focused on read-only operations
  • Consider cross-component connections and architectural patterns
  • Include temporal context (when the research was conducted)
  • Link to GitHub when possible for permanent references
  • Keep the main agent focused on synthesis, not deep file reading
  • Encourage sub-agents to find examples and usage patterns, not just definitions
  • Explore all of thoughts/ directory, not just research subdirectory
  • Critical ordering: Follow the numbered steps exactly
    • ALWAYS wait for all sub-agents to complete before synthesizing (step 3)
    • ALWAYS gather metadata before writing the document (step 4 before step 5)
    • NEVER write the research document with placeholder values
  • Path handling: The thoughts/searchable/ directory contains hard links for searching
    • Always document paths by removing ONLY "searchable/" - preserve all other subdirectories
    • Examples of correct transformations:
      • thoughts/searchable/allison/old_stuff/notes.mdthoughts/allison/old_stuff/notes.md
      • thoughts/searchable/shared/prs/123.mdthoughts/shared/prs/123.md
      • thoughts/searchable/global/shared/templates.mdthoughts/global/shared/templates.md
    • NEVER change allison/ to shared/ or vice versa - preserve the exact directory structure
    • This ensures paths are correct for editing and navigation
  • Frontmatter consistency:
    • Always include frontmatter at the beginning of research documents
    • Keep frontmatter fields consistent across all research documents
    • Update frontmatter when adding follow-up research
    • Use snake_case for multi-word field names (e.g., last_updated, git_commit)
    • Tags should be relevant to the research topic and components studied