Automatically sorts C/C++ header files (#include statements) with full support for conditional compilation blocks. Use when Claude needs to organize #include statements in .cpp/.h files. Handles: (1) Corresponding header placement first (e.g., file.cpp includes file.h), (2) System headers (<>) sorted alphabetically, (3) Local headers ("") sorted alphabetically, (4) Conditional compilation blocks (#ifdef/#ifndef/#if defined) where headers participate in global sort while preserving block structu…
Automatically sorts C/C++ header files (#include statements) with full support for conditional compilation blocks.
Use when Claude needs to organize #include statements in .cpp/.h files.
Handles: (1) Corresponding header placement first (e.g., file.cpp includes file.h), (2) System headers (<>) sorted alphabetically, (3) Local headers ("") sorted alphabetically, (4) Conditional compilation blocks (#ifdef/#ifndef/#if defined) where headers participate in global sort while preserving block structure.
Key features: prefers longer paths for duplicate includes, preserves inline/preceding comments, handles #elif/#else blocks, validates no headers are lost.
Similar popular skills
Related neighbors and high-traction skills in the same topics — useful to compare before installing.
Duplicate include handling: When multiple includes with same filename but different paths exist (e.g., "file.h" and "path/to/file.h"), the longest path is used as the corresponding header and placed first
Comment preservation: Inline comments (// comment) and preceding comments are preserved
Nested conditional blocks: Handles #elif and #else within #ifdef blocks
Validation: Verifies no headers are lost during sorting
Script Reference
See scripts/sort_includes.py for implementation details.
Key functions:
extractincludeswith_ifdef() - Parses includes and conditional blocks
sortincludeswith_ifdef() - Sorts with 3-category rule
formatifdefblock() - Formats conditional blocks with sorted includes
Verification
After sorting, verify:
All #ifdef blocks contain same number of headers as before
Corresponding header has complete path (not shortened)