Code Reading
Category: perception
Skill Level: intermediate
Stability: stable
Added: 2025-03
Last Updated: 2026-04
Description
Parse, understand, and extract meaning from source code files or snippets. Covers identifying intent, extracting function signatures and docstrings, detecting dependencies, summarizing modules, spotting bugs or anti-patterns, and explaining logic in plain language. Works across all major languages: Python, JavaScript/TypeScript, Go, Rust, Java, C/C++, SQL, and shell scripts.
Inputs
| Input |
Type |
Required |
Description |
source |
string |
✅ |
Raw source code or file path |
language |
string |
❌ |
Language hint (auto-detected if omitted) |
task |
string |
❌ |
summarize, extract_signatures, find_bugs, explain |
Outputs
| Output |
Type |
Description |
purpose |
string |
One-sentence description of file intent |
functions |
list |
[{name, params, return_type, summary}] |
imports |
list |
External dependencies detected |
issues |
list |
Potential bugs or code smells |
Example
import anthropic
from pathlib import Path
client = anthropic.Anthropic()
def analyze_code_file(file_path: str) -> str:
"""Extract structured metadata from a source code file."""
source = Path(file_path).read_text(encoding="utf-8")
language = Path(file_path).suffix.lstrip(".")
response = client.messages.create(
model="claude-opus-4-5",
max_tokens=2048,
messages=[{
"role": "user",
"content": (
f"Analyze this {language} file and return JSON with:\n"
"- language\n"
"- purpose: one-sentence description\n"
"- functions: [{name, params, return_type, summary}]\n"
"- classes: [{name, methods, summary}]\n"
"- imports: list of external dependencies\n"
"- issues: list of potential bugs or code smells\n"
"Return ONLY valid JSON.\n\n"
f"```{language}\n{source[:8000]}\n```"
)
}]
)
return response.content[0].text
result = analyze_code_file("src/utils.py")
print(result)
Frameworks & Models
| Framework / Model |
Implementation |
Since |
| Claude claude-opus-4-5 |
Direct text prompt with fenced code block |
2024-06 |
| GPT-4o |
Same pattern via OpenAI SDK |
2024-05 |
| LangChain |
ChatAnthropic chain |
v0.2 |
Notes
- Chunk files larger than ~800 lines before sending; use sliding window for context continuity
- For multi-file analysis, send a directory tree first then individual files
- Combine with Structured Data Reading to process
package.json, pyproject.toml, etc.
Related Skills
- Text Reading — general text extraction
- Structured Data Reading — config file parsing
- Document Parsing — for code in PDFs or docs
- File System Reading — discovering files to read
Changelog
| Date |
Change |
2026-04 |
Expanded from stub: full description, I/O table, runnable example, notes |
2025-03 |
Initial stub entry |
Failure Modes
| Failure Mode |
Cause |
Mitigation |
| Untrusted input causes incorrect extraction |
Malformed, adversarial, or incomplete source data |
Validate structure, bound input size, preserve source provenance, and reject ambiguous results when required |
| Model or parser overstates certainty |
Heuristic extraction is treated as authoritative |
Return source spans or structured evidence and distinguish extraction from verification |
| Context or resource exhaustion |
Large files, histories, responses, or media are processed without limits |
Apply size, time, row, page, or token limits and process incrementally |
Evidence
The skill's implementation guidance is grounded in the following primary references:
Evidence status: implementation guidance verified against the cited documentation; no benchmark claim is made unless a reproducible benchmark is included in this file.
1---2name: code-reading3description: Inspect source code to identify purpose, structure, dependencies, control flow, and likely defects without treating model interpretation as proof of correctness. Use it before debugging, refactoring, or architecture changes.4metadata:5 source: https://skillmd.com/skills/samotech/code-reading6 upstream: skills/01-perception/code-reading.md7 category: 01-perception8 version: "v2"9---10111213# Code Reading1415**Category:** `perception`16**Skill Level:** `intermediate`17**Stability:** `stable`18**Added:** 2025-0319**Last Updated:** 2026-042021---2223## Description2425Parse, understand, and extract meaning from source code files or snippets. Covers identifying intent, extracting function signatures and docstrings, detecting dependencies, summarizing modules, spotting bugs or anti-patterns, and explaining logic in plain language. Works across all major languages: Python, JavaScript/TypeScript, Go, Rust, Java, C/C++, SQL, and shell scripts.2627---2829## Inputs3031| Input | Type | Required | Description |32|---|---|---|---|33| `source` | `string` | ✅ | Raw source code or file path |34| `language` | `string` | ❌ | Language hint (auto-detected if omitted) |35| `task` | `string` | ❌ | `summarize`, `extract_signatures`, `find_bugs`, `explain` |3637---3839## Outputs4041| Output | Type | Description |42|---|---|---|43| `purpose` | `string` | One-sentence description of file intent |44| `functions` | `list` | `[{name, params, return_type, summary}]` |45| `imports` | `list` | External dependencies detected |46| `issues` | `list` | Potential bugs or code smells |4748---4950## Example5152```python53import anthropic54from pathlib import Path5556client = anthropic.Anthropic()5758def analyze_code_file(file_path: str) -> str:59 """Extract structured metadata from a source code file."""60 source = Path(file_path).read_text(encoding="utf-8")61 language = Path(file_path).suffix.lstrip(".")6263 response = client.messages.create(64 model="claude-opus-4-5",65 max_tokens=2048,66 messages=[{67 "role": "user",68 "content": (69 f"Analyze this {language} file and return JSON with:\n"70 "- language\n"71 "- purpose: one-sentence description\n"72 "- functions: [{name, params, return_type, summary}]\n"73 "- classes: [{name, methods, summary}]\n"74 "- imports: list of external dependencies\n"75 "- issues: list of potential bugs or code smells\n"76 "Return ONLY valid JSON.\n\n"77 f"```{language}\n{source[:8000]}\n```"78 )79 }]80 )81 return response.content[0].text8283result = analyze_code_file("src/utils.py")84print(result)85```8687---8889## Frameworks & Models9091| Framework / Model | Implementation | Since |92|---|---|---|93| Claude claude-opus-4-5 | Direct text prompt with fenced code block | 2024-06 |94| GPT-4o | Same pattern via OpenAI SDK | 2024-05 |95| LangChain | `ChatAnthropic` chain | v0.2 |9697---9899## Notes100101- Chunk files larger than ~800 lines before sending; use sliding window for context continuity102- For multi-file analysis, send a directory tree first then individual files103- Combine with [Structured Data Reading](structured-data-reading.md) to process `package.json`, `pyproject.toml`, etc.104105---106107## Related Skills108109- [Text Reading](text-reading.md) — general text extraction110- [Structured Data Reading](structured-data-reading.md) — config file parsing111- [Document Parsing](document-parsing.md) — for code in PDFs or docs112- [File System Reading](file-system-reading.md) — discovering files to read113114---115116## Changelog117118| Date | Change |119|---|---|120| `2026-04` | Expanded from stub: full description, I/O table, runnable example, notes |121| `2025-03` | Initial stub entry |122123124## Failure Modes125126| Failure Mode | Cause | Mitigation |127|---|---|---|128| Untrusted input causes incorrect extraction | Malformed, adversarial, or incomplete source data | Validate structure, bound input size, preserve source provenance, and reject ambiguous results when required |129| Model or parser overstates certainty | Heuristic extraction is treated as authoritative | Return source spans or structured evidence and distinguish extraction from verification |130| Context or resource exhaustion | Large files, histories, responses, or media are processed without limits | Apply size, time, row, page, or token limits and process incrementally |131132133## Evidence134135The skill's implementation guidance is grounded in the following primary references:136- Python AST documentation: https://github.com/python/cpython/blob/3.14/Doc/library/ast.rst137- Python inspect documentation: https://github.com/python/cpython/blob/3.14/Doc/library/inspect.rst138139Evidence status: implementation guidance verified against the cited documentation; no benchmark claim is made unless a reproducible benchmark is included in this file.