| name | file-operations |
| description | Analyze files and get detailed metadata including size, line counts, modification times, and content statistics. Use when users request file information, statistics, or analysis without modifying files. Activates on phrases like "analyze this file", "get file info", "how many lines", "file statistics", or "show file details". |
File Operations
Overview
Analyze files and retrieve detailed metadata using Claude's native tools. This skill provides convenient workflows for gathering file statistics, comparing files, and analyzing code structure without making modifications.
When to Use This Skill
Activate this skill when users request:
- File metadata: "What's the size of config.json?"
- Line counts: "How many lines are in this file?"
- File comparison: "Compare the sizes of these two files"
- Code statistics: "Analyze the structure of this Python file"
- File details: "Show me info about all JavaScript files"
Activation phrases:
- "analyze [file]"
- "get file info for [file]"
- "how many lines in [file]"
- "file statistics for [file]"
- "show details of [file]"
- "compare [file1] and [file2]"
Core Operations
1. Get File Size and Modification Time
Use Bash commands for quick file metadata:
Single file info:
stat -f "%z bytes, modified %Sm" [file_path]
Multiple files:
ls -lh [directory]
File size in human-readable format:
du -h [file_path]
2. Count Lines in Files
Line count for single file:
wc -l [file_path]
Line count for multiple files:
wc -l [file1] [file2] [file3]
Total lines in directory:
find [directory] -name "*.py" | xargs wc -l
3. Analyze File Content
Use Read tool to analyze structure:
Read(file_path="src/app.py")
Then analyze the content:
- Count functions/classes
- Identify imports
- Check documentation coverage
- Assess complexity
4. Search for Patterns
Use Grep to analyze code patterns:
Count function definitions:
Grep(pattern="^def ", output_mode="count", path="src/")
Find TODOs:
Grep(pattern="TODO|FIXME|XXX", output_mode="content", -n=true)
Count imports:
Grep(pattern="^import |^from .* import", output_mode="count", path="src/")
5. Find Files by Pattern
Use Glob to discover files:
Glob(pattern="**/*.py")
Workflow Examples
Example 1: Comprehensive File Analysis
User: "Analyze app.py and tell me about it"
Workflow:
Get file size and modification time:
stat -f "%z bytes, modified %Sm" app.pyCount lines:
wc -l app.pyRead the file:
Read(file_path="app.py")Analyze structure:
- Count functions:
Grep(pattern="^def ", output_mode="count", path="app.py") - Count classes:
Grep(pattern="^class ", output_mode="count", path="app.py") - Find imports:
Grep(pattern="^import |^from ", output_mode="content", -n=true, path="app.py")
- Count functions:
Report findings:
app.py Analysis: - Size: 15.2 KB - Lines: 456 - Functions: 12 - Classes: 3 - Imports: 8 modules - Last modified: 2025-10-20
Example 2: Compare File Sizes
User: "Compare the sizes of all Python files in src/"
Workflow:
Find all Python files:
Glob(pattern="src/**/*.py")Get sizes for each file:
ls -lh src/**/*.pyCalculate total size:
du -sh src/*.pyPresent comparison:
Python Files in src/: - auth.py: 25 KB (largest) - utils.py: 18 KB - config.py: 3 KB - main.py: 12 KB Total: 58 KB across 4 files
Example 3: Code Quality Metrics
User: "Give me code quality metrics for the project"
Workflow:
Total line count:
find . -name "*.py" -not -path "./venv/*" | xargs wc -lCount test coverage (test files vs source files):
find . -name "test_*.py" | wc -l find . -name "*.py" -not -name "test_*" | wc -lFind TODOs and FIXMEs:
Grep(pattern="TODO|FIXME|HACK|XXX", output_mode="count")Find missing docstrings:
Grep(pattern="^def |^class ", output_mode="content", -n=true, -A=1)(Then analyze which don't have docstrings)
Report metrics:
Code Quality Metrics: - Total lines of code: 3,456 - Source files: 28 - Test files: 15 (54% coverage by count) - TODOs/FIXMEs: 12 - Functions without docstrings: 8
Example 4: Find Largest Files
User: "What are the largest files in this project?"
Workflow:
List all files by size:
find . -type f -not -path "./node_modules/*" -not -path "./.git/*" -exec du -h {} + | sort -rh | head -20Identify file types of largest files
Analyze if large files need refactoring:
- If source code file > 500 lines, suggest splitting
- If data file, check if it should be externalized
Present findings:
Largest Files: 1. data/dataset.json - 2.3 MB (consider externalizing) 2. src/processor.py - 1,245 lines (suggest refactoring) 3. build/bundle.js - 856 KB (expected for bundle)
Example 5: Directory Structure Analysis
User: "Show me the structure of the src/ directory"
Workflow:
Use tree command (if available):
tree src/ -L 2Or use find:
find src/ -type f -o -type d | sortCount files by type:
find src/ -name "*.py" | wc -l find src/ -name "*.js" | wc -l find src/ -name "*.json" | wc -lAnalyze organization:
- Check for consistent directory structure
- Identify orphaned files
- Note missing documentation
Present structure:
src/ Directory Structure: ├── api/ (8 Python files) ├── models/ (5 Python files) ├── utils/ (12 Python files) ├── tests/ (15 test files) └── config.json Total: 40 Python files, 1 config
Best Practices
Non-Destructive Analysis
This skill should NEVER modify files:
- Use
ReadnotWrite - Use
stat/ls/wcnot modification commands - Use
Grepwithoutput_modenotsed/awk
Efficient Information Gathering
For small files (<100 lines):
- Read entire file and analyze in context
For large files (>1000 lines):
- Use Grep to find specific patterns
- Use
wc -lfor line counts - Use
head/tailfor quick preview
For many files:
- Use Glob to find files first
- Use parallel Bash commands where appropriate
- Summarize rather than showing all details
Context-Aware Reporting
When reporting file information:
- Include relevant context (e.g., "large for a config file")
- Compare to project averages
- Suggest optimizations if appropriate
- Use human-readable formats
Integration with Other Tools
Working with Claude's Native Tools
- Read: Read full file content for analysis
- Grep: Search patterns, count occurrences
- Glob: Find files by pattern
- Bash: Execute stat, wc, du, ls, find commands
Working with Other Skills
- code-auditor: For comprehensive codebase analysis
- code-transfer: After identifying large files that need splitting
- codebase-documenter: For understanding file purposes and relationships
Common Use Cases
Development Workflow
Pre-commit analysis:
- Check file sizes before committing
- Count lines of new code
- Verify no large files added
Code review:
- Compare file versions
- Check complexity metrics
- Identify files needing attention
Refactoring decisions:
- Find largest/most complex files
- Identify files with too many responsibilities
- Locate duplicate code patterns
Project Management
Progress tracking:
- Count lines of code over time
- Track test coverage ratios
- Monitor technical debt (TODOs)
Documentation:
- Find undocumented files
- Identify missing docstrings
- Check README completeness
Tool Reference
Bash Commands for File Operations
File size:
du -h [file]- Human-readable sizestat -f "%z" [file]- Exact bytes (macOS)stat -c "%s" [file]- Exact bytes (Linux)
Line counts:
wc -l [file]- Count lineswc -w [file]- Count wordswc -c [file]- Count bytes
File info:
stat [file]- Complete file statsfile [file]- File typels -lh [file]- Permissions, size, date
Find files:
find [dir] -name "pattern"- Find by namefind [dir] -type f -size +1M- Find large filesfind [dir] -mtime -7- Modified in last 7 days
Grep for Analysis
Count occurrences:
Grep(pattern="pattern", output_mode="count")
Find with context:
Grep(pattern="pattern", output_mode="content", -n=true, -B=2, -A=2)
Count per file:
Grep(pattern="pattern", output_mode="count", path="dir/")