Code Explorer
Use this skill to understand unfamiliar code efficiently and explain it in plain language. It supports both English and Chinese requests. Default to understanding first. Only switch to improvement mode when the user explicitly asks for improvements, optimizations, risks, or feature ideas.
Skill root
- Treat the directory containing this
SKILL.md as SKILL_ROOT.
- Resolve bundled files relative to
SKILL_ROOT, not the workspace root.
- When shell helpers are useful, run them via
SKILL_ROOT/scripts/....
- If that path cannot be resolved, load
error-handling.md and continue with manual inspection instead of stopping.
Helper commands:
bash "$SKILL_ROOT/scripts/detect_lang.sh"
bash "$SKILL_ROOT/scripts/find_entry.sh" <lang>
bash "$SKILL_ROOT/scripts/git_context.sh" [target]
Step 0: Pick the analysis mode
Choose the mode automatically based on the user's request:
| Mode |
Trigger |
Behavior |
| Quick mode |
Single function, variable, or narrow question |
Answer directly without the full four-phase flow |
| Standard mode |
One file or one module |
Run Phase 1-4 with the standard output structure |
| Deep mode |
Whole project, architecture, multi-module relationships |
Finish Phase 1, then confirm scope before going deeper |
| Suggestion mode |
Explicit asks for improvements, optimization, risks, or feature ideas |
Reuse Phase 1 and selective Phase 2, then output structured suggestions |
Mode boundary:
- Quick, standard, and deep modes are for understanding code. Do not proactively give optimization or feature suggestions there.
- Suggestion mode is only for explicit improvement requests.
Step 1: Run helper scripts
Run the bundled scripts when they materially speed up the analysis:
- Detect the language with
scripts/detect_lang.sh
- Find likely entry points with
scripts/find_entry.sh <lang>
- Gather Git context with
scripts/git_context.sh [target]
If any helper fails, load error-handling.md and fall back to manual inspection.
Step 2: Load language guidance selectively
After language detection, load only the relevant language guide:
- Go ->
lang/go.md
- Python ->
lang/python.md
- JavaScript/TypeScript ->
lang/javascript.md
- Other languages -> skip language-specific guidance and use the generic workflow
Do not load language guides when:
- The request is quick mode
- The user only wants one narrow dimension such as data flow or callers
- The task is not about code semantics, such as a pure directory or dependency overview
For languages without a guide, fall back to:
- Search for likely entry points such as
main, init, bootstrap, start, or run
- Read dependency files such as lockfiles,
*.toml, *.gradle, Makefile, or similar
- Infer architecture from directory names such as
src/, lib/, pkg/, cmd/, service/, internal/
Step 3: Four-phase analysis workflow
Phase 1: Macro scan
Goal: build the project map quickly without diving into implementation.
- Identify the tech stack, preferably with the helper scripts
- Scan the top-level directory structure
- Read only the most relevant dependency files
- Infer the high-level architecture
Deep mode rule:
- After Phase 1, ask the user which modules or flows to focus on before reading more code.
Parallelism rule:
- If the environment supports delegation and the user explicitly allows subagents, parallelize independent module scans or call-chain traces.
- Otherwise stay local and serial.
Budget rule:
- Keep Phase 1 within 5 files and prefer signatures, comments, and manifests.
Phase 2: Trace the critical path
Goal: follow one data flow or control flow at a time.
- Lock onto the target function, class, module, or request path
- Search upward for callers and entry points
- Search downward for callees and dependent components
- Track how key objects are transformed and passed across modules
Execution rules:
- Search precisely before reading
- Read targeted slices rather than full files
- Prefer signatures and comments first, then implementation only when needed
- If the likely scope exceeds 10 files, ask the user whether to continue, narrow scope, or split the work
Phase 3: Abstract and visualize
- Rewrite the core logic as 5-10 steps of pseudocode or structured prose
- Include at least one ASCII diagram chosen for the situation:
- module or architecture diagram
- request or call sequence diagram
- state transition diagram
- inheritance or ownership tree
- Identify useful patterns or anti-patterns
Phase 4: Synthesize
- Summarize the core function in one sentence
- Explain the design intent, not just the mechanics
- Call out real risks or complexity points
- Add Git evolution context when available
Step 4: Suggestion mode
When the user explicitly asks for improvements, load suggestion-mode.md and follow its priority and output rules.
Output format
Quick mode:
**[function or symbol]** - [one-sentence explanation]
Core logic:
1. ...
2. ...
Watch-outs: [if any]
Standard and deep modes:
## Core Summary
[one sentence, at most 50 characters in Chinese or similarly compact in English]
## Diagram
[ASCII diagram, required]
## Logic Breakdown
**Entry point**: `path:symbol`
**Core flow**:
1. ...
2. ...
3. ...
**Data flow**: `A` -> `B` -> `C`
## Deep Insights
- **Design intent**: ...
- **Key dependencies**: ...
- **Git context**: ...
- **Watch-outs**: ...
## Next Questions
1. ...
2. ...
## Analysis Notes
[Mention any delegated or parallel work here when used]
Suggestion mode:
- Follow
suggestion-mode.md
Constraints
- Do not give optimization or feature suggestions in quick, standard, or deep mode unless the user asked for them
- Do not paste long code blocks; keep quoted snippets under 15 lines
- Do not read large files blindly; prefer targeted reads
- Always include at least one ASCII diagram in standard and deep modes
- Emit a short checkpoint summary after each phase
- Prefer explaining why over merely restating what
- If the context grows large, load
context-mgmt.md and actively reduce scope
Never do these things
- Never dive into a random function before building enough architectural context
- Never read a large file wholesale when a precise search can narrow the slice
- Never dump source code instead of explaining it
- Never juggle too many independent call chains at once; finish one path cleanly, then move to the next
- Never let a helper-script failure stop the analysis
Recovery guidance
- Load
error-handling.md when helper scripts fail, paths cannot be resolved, or the target cannot be found
- Load
context-mgmt.md when file count or token usage starts getting large
1---2name: code-explorer-23description: Deeply read and explain unfamiliar codebases. Use when Codex needs to explain a file or module, trace a function or request flow, map a project's architecture, clarify design intent, or review which parts of the code can be improved or extended. 适用于:解释一个文件或模块是做什么的、追踪函数或请求的执行流程、梳理项目架构、说明为什么这样设计、分析一段代码的核心逻辑,或评估哪些部分可以优化、重构、改进或扩展。4---56# Code Explorer78Use this skill to understand unfamiliar code efficiently and explain it in plain language. It supports both English and Chinese requests. Default to understanding first. Only switch to improvement mode when the user explicitly asks for improvements, optimizations, risks, or feature ideas.910## Skill root1112- Treat the directory containing this `SKILL.md` as `SKILL_ROOT`.13- Resolve bundled files relative to `SKILL_ROOT`, not the workspace root.14- When shell helpers are useful, run them via `SKILL_ROOT/scripts/...`.15- If that path cannot be resolved, load `error-handling.md` and continue with manual inspection instead of stopping.1617Helper commands:1819```bash20bash "$SKILL_ROOT/scripts/detect_lang.sh"21bash "$SKILL_ROOT/scripts/find_entry.sh" <lang>22bash "$SKILL_ROOT/scripts/git_context.sh" [target]23```2425## Step 0: Pick the analysis mode2627Choose the mode automatically based on the user's request:2829| Mode | Trigger | Behavior |30|------|---------|----------|31| Quick mode | Single function, variable, or narrow question | Answer directly without the full four-phase flow |32| Standard mode | One file or one module | Run Phase 1-4 with the standard output structure |33| Deep mode | Whole project, architecture, multi-module relationships | Finish Phase 1, then confirm scope before going deeper |34| Suggestion mode | Explicit asks for improvements, optimization, risks, or feature ideas | Reuse Phase 1 and selective Phase 2, then output structured suggestions |3536Mode boundary:37- Quick, standard, and deep modes are for understanding code. Do not proactively give optimization or feature suggestions there.38- Suggestion mode is only for explicit improvement requests.3940## Step 1: Run helper scripts4142Run the bundled scripts when they materially speed up the analysis:43441. Detect the language with `scripts/detect_lang.sh`452. Find likely entry points with `scripts/find_entry.sh <lang>`463. Gather Git context with `scripts/git_context.sh [target]`4748If any helper fails, load `error-handling.md` and fall back to manual inspection.4950## Step 2: Load language guidance selectively5152After language detection, load only the relevant language guide:5354- Go -> `lang/go.md`55- Python -> `lang/python.md`56- JavaScript/TypeScript -> `lang/javascript.md`57- Other languages -> skip language-specific guidance and use the generic workflow5859Do not load language guides when:60- The request is quick mode61- The user only wants one narrow dimension such as data flow or callers62- The task is not about code semantics, such as a pure directory or dependency overview6364For languages without a guide, fall back to:65- Search for likely entry points such as `main`, `init`, `bootstrap`, `start`, or `run`66- Read dependency files such as lockfiles, `*.toml`, `*.gradle`, `Makefile`, or similar67- Infer architecture from directory names such as `src/`, `lib/`, `pkg/`, `cmd/`, `service/`, `internal/`6869## Step 3: Four-phase analysis workflow7071### Phase 1: Macro scan7273Goal: build the project map quickly without diving into implementation.74751. Identify the tech stack, preferably with the helper scripts762. Scan the top-level directory structure773. Read only the most relevant dependency files784. Infer the high-level architecture7980Deep mode rule:81- After Phase 1, ask the user which modules or flows to focus on before reading more code.8283Parallelism rule:84- If the environment supports delegation and the user explicitly allows subagents, parallelize independent module scans or call-chain traces.85- Otherwise stay local and serial.8687Budget rule:88- Keep Phase 1 within 5 files and prefer signatures, comments, and manifests.8990### Phase 2: Trace the critical path9192Goal: follow one data flow or control flow at a time.93941. Lock onto the target function, class, module, or request path952. Search upward for callers and entry points963. Search downward for callees and dependent components974. Track how key objects are transformed and passed across modules9899Execution rules:100- Search precisely before reading101- Read targeted slices rather than full files102- Prefer signatures and comments first, then implementation only when needed103- If the likely scope exceeds 10 files, ask the user whether to continue, narrow scope, or split the work104105### Phase 3: Abstract and visualize1061071. Rewrite the core logic as 5-10 steps of pseudocode or structured prose1082. Include at least one ASCII diagram chosen for the situation:109 - module or architecture diagram110 - request or call sequence diagram111 - state transition diagram112 - inheritance or ownership tree1133. Identify useful patterns or anti-patterns114115### Phase 4: Synthesize1161171. Summarize the core function in one sentence1182. Explain the design intent, not just the mechanics1193. Call out real risks or complexity points1204. Add Git evolution context when available121122## Step 4: Suggestion mode123124When the user explicitly asks for improvements, load `suggestion-mode.md` and follow its priority and output rules.125126## Output format127128Quick mode:129130```markdown131**[function or symbol]** - [one-sentence explanation]132133Core logic:1341. ...1352. ...136137Watch-outs: [if any]138```139140Standard and deep modes:141142```markdown143## Core Summary144[one sentence, at most 50 characters in Chinese or similarly compact in English]145146## Diagram147[ASCII diagram, required]148149## Logic Breakdown150**Entry point**: `path:symbol`151152**Core flow**:1531. ...1542. ...1553. ...156157**Data flow**: `A` -> `B` -> `C`158159## Deep Insights160- **Design intent**: ...161- **Key dependencies**: ...162- **Git context**: ...163- **Watch-outs**: ...164165## Next Questions1661. ...1672. ...168169## Analysis Notes170[Mention any delegated or parallel work here when used]171```172173Suggestion mode:174- Follow `suggestion-mode.md`175176## Constraints177178- Do not give optimization or feature suggestions in quick, standard, or deep mode unless the user asked for them179- Do not paste long code blocks; keep quoted snippets under 15 lines180- Do not read large files blindly; prefer targeted reads181- Always include at least one ASCII diagram in standard and deep modes182- Emit a short checkpoint summary after each phase183- Prefer explaining why over merely restating what184- If the context grows large, load `context-mgmt.md` and actively reduce scope185186## Never do these things187188- Never dive into a random function before building enough architectural context189- Never read a large file wholesale when a precise search can narrow the slice190- Never dump source code instead of explaining it191- Never juggle too many independent call chains at once; finish one path cleanly, then move to the next192- Never let a helper-script failure stop the analysis193194## Recovery guidance195196- Load `error-handling.md` when helper scripts fail, paths cannot be resolved, or the target cannot be found197- Load `context-mgmt.md` when file count or token usage starts getting large