Workflow
Step 1: File Selection
Check for existing runs first:
ls -d .aitask-explain/*/files.txt 2>/dev/null
If existing runs are found, read files.txt from each run to build a summary.
If invoked with arguments (file/directory paths): parse each argument:
- If argument matches
<path>:<start_line>-<end_line> (e.g., src/app.py:10-50): extract the file path and store the line range as focus context for Step 4
- If argument is a plain path (no colon+range suffix): use as-is (no range)
Skip to "Proceed with files" below.
If no arguments and existing runs exist:
Use AskUserQuestion:
- Question: "How would you like to select files?"
- Header: "Files"
- Options:
- "Use existing analysis" (description: "Reuse data from a previous aitask-explain run")
- "Search for files" (description: "Find files by keywords, names, or functionality")
- "Enter paths directly" (description: "Type file/directory paths manually")
If "Use existing analysis":
- If multiple runs exist, use
AskUserQuestion to select which run (show timestamp + covered files summary for each)
- Once a run is selected, use
AskUserQuestion:
- Question: "Run from <timestamp> covers: <file list>. Use existing data or refresh?"
- Header: "Refresh"
- Options:
- "Use existing data" (description: "Skip regeneration, use cached reference data")
- "Refresh references" (description: "Re-run git analysis to update data for these files")
- If "Use existing data": set
run_dir to the selected run's path, skip Step 3 (no regeneration needed), proceed to Step 2
- If "Refresh references": use the file list from
files.txt, delete old run directory, proceed to Step 3
If no arguments and no existing runs:
Use AskUserQuestion:
- Question: "How would you like to select files?"
- Header: "Files"
- Options:
- "Search for files" (description: "Find files by keywords, names, or functionality")
- "Enter paths directly" (description: "Type file/directory paths manually")
If "Search for files": Read and follow .claude/skills/user-file-select/SKILL.md to get file paths. Once file paths are returned, proceed to "Proceed with files" below.
If "Enter paths directly":
Use AskUserQuestion:
- Question: "Which files or directories would you like explained? (enter paths separated by spaces)"
- Header: "Files"
- Options: free text only (use "Other")
Proceed with files:
- Directory expansion: If any path is a directory, the shell script expands it to all git-tracked text files within it using
git ls-files <directory>
- Binary file detection: Binary files (images, compiled assets, etc.) are automatically detected by the extraction pipeline and marked with
binary: true in reference.yaml. They have commit timelines but no line-level annotations. No special handling is needed at file selection — binary files are processed alongside text files.
- Validate all resolved files exist and are tracked by git
Step 2: Mode Selection
Use AskUserQuestion with multiSelect: true:
- Question: "What would you like explained?"
- Header: "Mode"
- Options:
- "Functionality" (description: "What the code does — purpose, components, data flow")
- "Usage examples" (description: "How the code is used in the project — real imports and references")
- "Code evolution" (description: "How the code changed over time — traced through commits and aitasks")
Step 3: Generate Reference Data
Run the shell script to gather raw data and produce the YAML reference:
./.aitask-scripts/aitask_explain_extract_raw_data.sh --gather <path1> [path2...] --max-commits 50
- Parse the
RUN_DIR: <path> line from output to get the run-specific directory
- The script automatically cleans up stale runs (older runs for the same source directory) after gathering
- Store the
run_dir path for cleanup in Step 6
- Read
<run_dir>/reference.yaml to understand the structure
- For "Code evolution" mode: also read extracted task/plan files from
<run_dir>/tasks/ and <run_dir>/plans/
Step 4: Analysis and Explanation
If a line range was specified in Step 1: Focus analysis primarily on the specified line range. Read the full file for context, but center the explanation on the specified lines. For Code Evolution mode, prioritize commits that touched the specified range.
Based on selected modes, provide analysis:
Functionality Mode
- Read the target file(s) in full
- For binary files (marked
binary: true in reference.yaml): describe the file's role based on its path, filename, and extension. Search the codebase with Grep for references to the file to understand how it's used. Do not attempt line-level code analysis.
- For text files: Provide a structured explanation covering:
- Purpose: What problem does this code solve
- Key components: Main functions, classes, data structures
- Data flow: How data moves through the code
- Error handling: How errors are managed
- Design patterns: Notable patterns or conventions used
- Reference the commit history from
reference.yaml for context on why certain patterns exist
Usage Examples Mode
- Search the project codebase for imports/references to the target file(s):
- Use
Grep to find source statements (for shell), import statements, function calls
- Use
Grep for filename references in documentation, configuration, etc.
- Present real usage examples from the project itself
- For each usage found, provide:
- File path and line number
- Context of how it's being used
- Brief explanation of the usage pattern
- If no project usages found, describe typical usage based on the code's interface
Code Evolution Mode
- Read
<run_dir>/reference.yaml for the line-range-to-commit-to-task mapping
- Read relevant extracted plans from
<run_dir>/plans/ for implementation notes and context
- Read relevant extracted tasks from
<run_dir>/tasks/ for original task descriptions
- For binary files (marked
binary: true in reference.yaml): present only the commit timeline (no line_ranges data exists). Show when the file was added, modified, or replaced, and which tasks/commits touched it.
- For text files: Present a newest-first narrative of how the code evolved:
- What each significant commit/task changed
- Why changes were made (extracted from plan "Final Implementation Notes")
- How the code's architecture evolved over time
- Key decisions documented in the plans
- Use the
line_ranges data to connect current code sections to their historical commits
Step 5: Interactive Follow-up Loop
Use AskUserQuestion:
- Question: "What would you like to do next?"
- Header: "Next"
- Options:
- "Ask about specific code section" (description: "Ask about a line range or function — uses reference data for targeted context")
- "Switch analysis mode" (description: "Change between functionality / usage / evolution")
- "Analyze different files" (description: "Select new files to analyze")
- "Done" (description: "Finish and clean up")
Handle selection:
Step 6: Cleanup
Use AskUserQuestion:
- Question: "Clean up the analysis data?"
- Header: "Cleanup"
- Options:
- "Yes, delete" (description: "Remove the run directory and all generated data")
- "No, keep" (description: "Keep the data for future sessions — can be reused with 'Use existing analysis'")
If "Yes, delete":
./.aitask-scripts/aitask_explain_extract_raw_data.sh --cleanup <run_dir>
Where <run_dir> is the path captured in Step 3 (e.g., .aitask-explain/20260221_143052).
If "No, keep":
- Inform user: "Analysis data preserved at
<run_dir>. Use /aitask-explain again and select 'Use existing analysis' to reuse it."
- To manage existing runs later:
./.aitask-scripts/aitask_explain_runs.sh
Note: Stale run cleanup (removing older runs for the same source directory) happens automatically during Step 3 gathering. Manual cleanup via Step 6 removes the current run entirely. To trigger a manual stale cleanup: ./.aitask-scripts/aitask_explain_runs.sh --cleanup-stale
Step 7: Satisfaction Feedback
Execute the Satisfaction Feedback Procedure (see .claude/skills/task-workflow/satisfaction-feedback.md) with skill_name = "explain".
Notes
- This skill uses
aitask_explain_extract_raw_data.sh for raw data extraction (git log, git blame, task/plan file copying)
- Raw data is processed by
aitask_explain_process_raw_data.py into a structured reference.yaml file
- Each run creates an isolated directory under
.aitask-explain/<dir_key>__<timestamp>/ where dir_key is derived from the common parent directory of analyzed files (e.g., aiscripts__lib__20260226_155403)
- The
reference.yaml maps lines → commits → task IDs, enabling targeted "code evolution" explanations
- Commit timeline is ordered newest first (most recent changes have lowest timeline numbers)
- Task/plan files are copied with ID-only names (e.g.,
t16.md, p16.md) for simpler referencing
- Existing runs can be reused to avoid expensive re-analysis of unchanged code
- Run management (list, delete) is available via
./.aitask-scripts/aitask_explain_runs.sh
- Accepts both individual files and directories; directories are expanded to git-tracked text files
- Binary files (images, compiled assets, etc.) are auto-detected by the extraction pipeline and marked
binary: true in reference.yaml. They have commit timelines but empty line_ranges. The codebrowser shows "Binary file — cannot display" for content with "(binary, N commits)" in the annotation info bar.
1---2name: aitask-explain-33description: Explain files in the project: functionality, usage examples, and code evolution history traced through aitasks.4---5
6## Workflow
7
8### Step 1: File Selection
9
10**Check for existing runs first:**
11
12```bash
13ls -d .aitask-explain/*/files.txt 2>/dev/null
14```
15
16If existing runs are found, read `files.txt` from each run to build a summary.
17
18**If invoked with arguments (file/directory paths):** parse each argument:
19- If argument matches `<path>:<start_line>-<end_line>` (e.g., `src/app.py:10-50`): extract the file path and store the line range as focus context for Step 4
20- If argument is a plain path (no colon+range suffix): use as-is (no range)
21
22Skip to "Proceed with files" below.
23
24**If no arguments and existing runs exist:**
25
26Use `AskUserQuestion`:
27- Question: "How would you like to select files?"
28- Header: "Files"
29- Options:
30 - "Use existing analysis" (description: "Reuse data from a previous aitask-explain run")
31 - "Search for files" (description: "Find files by keywords, names, or functionality")
32 - "Enter paths directly" (description: "Type file/directory paths manually")
33
34**If "Use existing analysis":**
35- If multiple runs exist, use `AskUserQuestion` to select which run (show timestamp + covered files summary for each)
36- Once a run is selected, use `AskUserQuestion`:
37 - Question: "Run from \<timestamp\> covers: \<file list\>. Use existing data or refresh?"
38 - Header: "Refresh"
39 - Options:
40 - "Use existing data" (description: "Skip regeneration, use cached reference data")
41 - "Refresh references" (description: "Re-run git analysis to update data for these files")
42- If "Use existing data": set `run_dir` to the selected run's path, skip Step 3 (no regeneration needed), proceed to Step 2
43- If "Refresh references": use the file list from `files.txt`, delete old run directory, proceed to Step 3
44
45**If no arguments and no existing runs:**
46
47Use `AskUserQuestion`:
48- Question: "How would you like to select files?"
49- Header: "Files"
50- Options:
51 - "Search for files" (description: "Find files by keywords, names, or functionality")
52 - "Enter paths directly" (description: "Type file/directory paths manually")
53
54**If "Search for files":** Read and follow `.claude/skills/user-file-select/SKILL.md` to get file paths. Once file paths are returned, proceed to "Proceed with files" below.
55
56**If "Enter paths directly":**
57
58Use `AskUserQuestion`:
59- Question: "Which files or directories would you like explained? (enter paths separated by spaces)"
60- Header: "Files"
61- Options: free text only (use "Other")
62
63**Proceed with files:**
64
65- **Directory expansion**: If any path is a directory, the shell script expands it to all git-tracked text files within it using `git ls-files <directory>`
66- **Binary file detection**: Binary files (images, compiled assets, etc.) are automatically detected by the extraction pipeline and marked with `binary: true` in `reference.yaml`. They have commit timelines but no line-level annotations. No special handling is needed at file selection — binary files are processed alongside text files.
67- Validate all resolved files exist and are tracked by git
68
69### Step 2: Mode Selection
70
71Use `AskUserQuestion` with `multiSelect: true`:
72- Question: "What would you like explained?"
73- Header: "Mode"
74- Options:
75 - "Functionality" (description: "What the code does — purpose, components, data flow")
76 - "Usage examples" (description: "How the code is used in the project — real imports and references")
77 - "Code evolution" (description: "How the code changed over time — traced through commits and aitasks")
78
79### Step 3: Generate Reference Data
80
81Run the shell script to gather raw data and produce the YAML reference:
82
83```bash
84./.aitask-scripts/aitask_explain_extract_raw_data.sh --gather <path1> [path2...] --max-commits 50
85```
86
87- Parse the `RUN_DIR: <path>` line from output to get the run-specific directory
88- The script automatically cleans up stale runs (older runs for the same source directory) after gathering
89- Store the `run_dir` path for cleanup in Step 6
90- Read `<run_dir>/reference.yaml` to understand the structure
91- For "Code evolution" mode: also read extracted task/plan files from `<run_dir>/tasks/` and `<run_dir>/plans/`
92
93### Step 4: Analysis and Explanation
94
95**If a line range was specified in Step 1:** Focus analysis primarily on the specified line range. Read the full file for context, but center the explanation on the specified lines. For Code Evolution mode, prioritize commits that touched the specified range.
96
97Based on selected modes, provide analysis:
98
99#### Functionality Mode
100
101- Read the target file(s) in full
102- **For binary files** (marked `binary: true` in `reference.yaml`): describe the file's role based on its path, filename, and extension. Search the codebase with `Grep` for references to the file to understand how it's used. Do not attempt line-level code analysis.
103- **For text files**: Provide a structured explanation covering:
104 - **Purpose**: What problem does this code solve
105 - **Key components**: Main functions, classes, data structures
106 - **Data flow**: How data moves through the code
107 - **Error handling**: How errors are managed
108 - **Design patterns**: Notable patterns or conventions used
109- Reference the commit history from `reference.yaml` for context on why certain patterns exist
110
111#### Usage Examples Mode
112
113- Search the project codebase for imports/references to the target file(s):
114 - Use `Grep` to find `source` statements (for shell), `import` statements, function calls
115 - Use `Grep` for filename references in documentation, configuration, etc.
116- Present real usage examples from the project itself
117- For each usage found, provide:
118 - File path and line number
119 - Context of how it's being used
120 - Brief explanation of the usage pattern
121- If no project usages found, describe typical usage based on the code's interface
122
123#### Code Evolution Mode
124
125- Read `<run_dir>/reference.yaml` for the line-range-to-commit-to-task mapping
126- Read relevant extracted plans from `<run_dir>/plans/` for implementation notes and context
127- Read relevant extracted tasks from `<run_dir>/tasks/` for original task descriptions
128- **For binary files** (marked `binary: true` in `reference.yaml`): present only the commit timeline (no `line_ranges` data exists). Show when the file was added, modified, or replaced, and which tasks/commits touched it.
129- **For text files**: Present a **newest-first narrative** of how the code evolved:
130 - What each significant commit/task changed
131 - **Why** changes were made (extracted from plan "Final Implementation Notes")
132 - How the code's architecture evolved over time
133 - Key decisions documented in the plans
134- Use the `line_ranges` data to connect current code sections to their historical commits
135
136### Step 5: Interactive Follow-up Loop
137
138Use `AskUserQuestion`:
139- Question: "What would you like to do next?"
140- Header: "Next"
141- Options:
142 - "Ask about specific code section" (description: "Ask about a line range or function — uses reference data for targeted context")
143 - "Switch analysis mode" (description: "Change between functionality / usage / evolution")
144 - "Analyze different files" (description: "Select new files to analyze")
145 - "Done" (description: "Finish and clean up")
146
147**Handle selection:**
148
149- **"Ask about specific code section":**
150 - Use `AskUserQuestion` to ask which section (via "Other" free text): line range (e.g., "lines 50-80"), function name (e.g., "resolve_task_file"), or a description (e.g., "the error handling logic")
151 - Use the `line_ranges` from `reference.yaml` to identify which commits and tasks are relevant to that section
152 - Read relevant task/plan files from `<run_dir>/tasks/` and `<run_dir>/plans/` for context
153 - Provide a targeted explanation combining code analysis with historical commit/task context
154 - Loop back to Step 5
155
156- **"Switch analysis mode":**
157 - Return to Step 2 (mode selection)
158 - Skip Step 3 (reference data already generated)
159
160- **"Analyze different files":**
161 - Return to Step 1 (file selection)
162 - New reference data will be generated in Step 3
163
164- **"Done":**
165 - Proceed to Step 6 (cleanup)
166
167### Step 6: Cleanup
168
169Use `AskUserQuestion`:
170- Question: "Clean up the analysis data?"
171- Header: "Cleanup"
172- Options:
173 - "Yes, delete" (description: "Remove the run directory and all generated data")
174 - "No, keep" (description: "Keep the data for future sessions — can be reused with 'Use existing analysis'")
175
176**If "Yes, delete":**
177
178```bash
179./.aitask-scripts/aitask_explain_extract_raw_data.sh --cleanup <run_dir>
180```
181
182Where `<run_dir>` is the path captured in Step 3 (e.g., `.aitask-explain/20260221_143052`).
183
184**If "No, keep":**
185- Inform user: "Analysis data preserved at `<run_dir>`. Use `/aitask-explain` again and select 'Use existing analysis' to reuse it."
186- To manage existing runs later: `./.aitask-scripts/aitask_explain_runs.sh`
187
188**Note:** Stale run cleanup (removing older runs for the same source directory) happens automatically during Step 3 gathering. Manual cleanup via Step 6 removes the current run entirely. To trigger a manual stale cleanup: `./.aitask-scripts/aitask_explain_runs.sh --cleanup-stale`
189
190### Step 7: Satisfaction Feedback
191
192Execute the **Satisfaction Feedback Procedure** (see `.claude/skills/task-workflow/satisfaction-feedback.md`) with `skill_name` = `"explain"`.
193
194---
195
196## Notes
197
198- This skill uses `aitask_explain_extract_raw_data.sh` for raw data extraction (git log, git blame, task/plan file copying)
199- Raw data is processed by `aitask_explain_process_raw_data.py` into a structured `reference.yaml` file
200- Each run creates an isolated directory under `.aitask-explain/<dir_key>__<timestamp>/` where `dir_key` is derived from the common parent directory of analyzed files (e.g., `aiscripts__lib__20260226_155403`)
201- The `reference.yaml` maps lines → commits → task IDs, enabling targeted "code evolution" explanations
202- Commit timeline is ordered **newest first** (most recent changes have lowest timeline numbers)
203- Task/plan files are copied with ID-only names (e.g., `t16.md`, `p16.md`) for simpler referencing
204- Existing runs can be reused to avoid expensive re-analysis of unchanged code
205- Run management (list, delete) is available via `./.aitask-scripts/aitask_explain_runs.sh`
206- Accepts both individual files and directories; directories are expanded to git-tracked text files
207- Binary files (images, compiled assets, etc.) are auto-detected by the extraction pipeline and marked `binary: true` in `reference.yaml`. They have commit timelines but empty `line_ranges`. The codebrowser shows "Binary file — cannot display" for content with "(binary, N commits)" in the annotation info bar.