$npx -y skills add DevelopersGlobal/ai-agent-skills --skill code-explanationGet layered, context-aware explanations of unfamiliar code. Understand what it does, why it was written that way, and how to work with it safely.
| 1 | ## Overview |
| 2 | |
| 3 | Understanding unfamiliar code is a daily engineering task — onboarding to a codebase, debugging a library, or reviewing a PR. AI agents can explain code, but without structure, explanations are either too high-level to be useful or too detailed to absorb. |
| 4 | |
| 5 | This skill produces layered, targeted explanations: start with what it does, then why, then how to work with it. |
| 6 | |
| 7 | ## When to Use |
| 8 | |
| 9 | - Onboarding to an unfamiliar codebase |
| 10 | - Understanding a complex function or algorithm before modifying it |
| 11 | - Debugging code you didn't write |
| 12 | - Reviewing a PR for a part of the system you don't know well |
| 13 | |
| 14 | ## Process |
| 15 | |
| 16 | ### Step 1: The 30-Second Summary |
| 17 | |
| 18 | 1. In 2–3 sentences: What does this code do? What problem does it solve? |
| 19 | 2. What is the expected input? What is the output/effect? |
| 20 | 3. Where does this fit in the larger system? |
| 21 | |
| 22 | **Deliver:** A 2–3 sentence plain-English summary a junior engineer can understand. |
| 23 | |
| 24 | ### Step 2: Key Concepts and Patterns |
| 25 | |
| 26 | 4. What design patterns does this use? (observer, factory, pipeline, etc.) |
| 27 | 5. What external libraries or frameworks are being used and why? |
| 28 | 6. Are there any non-obvious algorithmic choices? (Why O(n log n) and not O(n²)?) |
| 29 | 7. What are the key data structures and why were they chosen? |
| 30 | |
| 31 | **Deliver:** 3–5 bullet points explaining the key design decisions. |
| 32 | |
| 33 | ### Step 3: Execution Walkthrough |
| 34 | |
| 35 | 8. Walk through the primary execution path step by step. |
| 36 | 9. For each significant step: what happens? what state changes? |
| 37 | 10. Highlight any surprising or non-obvious behavior. |
| 38 | 11. Show example input → output. |
| 39 | |
| 40 | **Deliver:** A numbered step-by-step walkthrough of the happy path. |
| 41 | |
| 42 | ### Step 4: Edge Cases and Gotchas |
| 43 | |
| 44 | 12. What inputs cause unexpected behavior? |
| 45 | 13. What are the performance characteristics? (O(n) per call? Expensive on large inputs?) |
| 46 | 14. What side effects does this have? (Modifies global state? Makes network calls?) |
| 47 | 15. What could go wrong? What does failure look like? |
| 48 | |
| 49 | **Deliver:** A "watch out for" section with at least 2 gotchas. |
| 50 | |
| 51 | ### Step 5: How to Work With This Code Safely |
| 52 | |
| 53 | 16. What should you not change without fully understanding? (Invariants, contracts) |
| 54 | 17. What tests cover this code? Are there gaps? |
| 55 | 18. What would break if you changed X? |
| 56 | |
| 57 | **Deliver:** Specific guidance for safely modifying or extending this code. |
| 58 | |
| 59 | ## Common Rationalizations (and Rebuttals) |
| 60 | |
| 61 | | Excuse | Rebuttal | |
| 62 | |--------|----------| |
| 63 | | "I'll just read it" | Reading unfamiliar code without structure is slow and error-prone. Use the layered approach. | |
| 64 | | "I'll ask a colleague" | Colleagues are often unavailable. AI can give a first-pass explanation 24/7. | |
| 65 | | "I understand it well enough" | "Well enough" has caused many production incidents. Confirm your understanding. | |
| 66 | |
| 67 | ## Red Flags |
| 68 | |
| 69 | - Making changes to code you don't understand |
| 70 | - Assuming behavior without verifying it |
| 71 | - Skipping the "gotchas" section when under time pressure |
| 72 | |
| 73 | ## Verification |
| 74 | |
| 75 | - [ ] 30-second summary written (would pass the "elevator test") |
| 76 | - [ ] Key design decisions explained |
| 77 | - [ ] Happy path walkthrough complete with example |
| 78 | - [ ] At least 2 gotchas identified |
| 79 | - [ ] Guidance on safe modification provided |
| 80 | |
| 81 | ## References |
| 82 | |
| 83 | - [surgical-changes skill](../surgical-changes/SKILL.md) |
| 84 | - [debugging-methodology skill](../debugging-methodology/SKILL.md) |