К основному содержанию
скилл CX Codex

include-what-you-use — скилл для Claude Code: чистит #include в C/C++

Скилл ведёт агента через IWYU: разбирает отчёты, применяет mapping-файлы и убирает лишние #include, из-за которых сборка C++ расползается.

Установить в Claude Code · Через Skills CLI (Vercel) Все способы и платформы ↓
npx skills add mohitmishra786/low-level-dev-skills --skill include-what-you-use -a claude-code
Открыть на GitHub

Что делает include-what-you-use

Скилл объясняет агенту, как запускать include-what-you-use и читать его вывод. Отчёт делится на три части: что добавить, что удалить и как должен выглядеть итоговый список заголовков. Дальше агент подсказывает, где хватит forward declaration, а где нужен полный #include — например, для наследования или создания объекта по значению.

Внутри есть готовые куски для CMake: CMAKE_CXX_INCLUDE_WHAT_YOU_USE с mapping-файлом и --no_comments, сборка через clang++ и лог в файл. Правки применяет fix_include, у него есть --dry_run для предпросмотра и --only_re для отбора файлов по маске. Mapping-файлы нужны для сторонних заголовков: они переводят приватные заголовки в публичные, вроде <bits/types.h> в <sys/types.h>.

IWYU ошибается на макросах из заголовков, специализациях шаблонов и заголовках, нужных для ODR. Поэтому цикл такой: прогнать, применить, пересобрать, откатить сломанное. Если правки не проверять тестами, сборка отвалится на линковке — это повод держать fix_include под рукой, а не запускать его вслепую по всему проекту.

Какие задачи решает

  • убрать лишние #include в большом C++ проекте
  • разобрать вывод iwyu и понять, что добавлять, а что удалять
  • выбрать между forward declaration и полным заголовком
  • подключить IWYU к сборке через CMake
  • настроить mapping-файл для системных и сторонних заголовков

Примеры запросов агенту

  • Прогони iwyu_tool.py по build/ и покажи, какие заголовки лишние
  • Замени этот include на forward declaration, если хватит указателя
  • Добавь проверку IWYU в CMakeLists с mapping-файлом iwyu.imp

Как установить include-what-you-use

1Через Skills CLI (Vercel)

npx skills add mohitmishra786/low-level-dev-skills --skill include-what-you-use -a claude-code

2Вручную: положить файлы

~/.claude/skills/include-what-you-use/SKILL.md

Папка скилла целиком; для одного проекта — .claude/skills/include-what-you-use/

По шагам, с командами для каждой платформы: Как установить скилл в Claude Code: пять способов

Вопросы о include-what-you-use

Как установить include-what-you-use в Claude?

Выполните npx skills add mohitmishra786/low-level-dev-skills --skill include-what-you-use -a claude-code. Скилл окажется в ~/.claude/skills/include-what-you-use/SKILL.md.

Что делает этот скилл?

Проводит агента по работе с IWYU: запуск анализа, чтение отчёта, применение правок через fix_include, forward declarations вместо полных заголовков и mapping-файлы.

На чём IWYU может ошибиться?

На макросах из заголовков, специализациях шаблонов и заголовках, которые нужны для корректной линковки по ODR. После правок проект надо пересобрать и прогнать тесты.

Исходный текст

SKILL.md · MIT
---
name: include-what-you-use
description: Include What You Use (IWYU) skill for optimizing C/C++ header includes. Use when reducing compilation cascades, interpreting IWYU reports, applying mapping files, deciding between forward declarations and full includes, or integrating IWYU with CMake. Activates on queries about IWYU, include-what-you-use, header bloat, reducing includes, forward declarations, compilation cascade, or slow C++ compilation from headers.
---

# Include What You Use (IWYU)

## Purpose

Guide agents through using IWYU to reduce unnecessary `#include` directives, interpret IWYU reports and mapping files, decide between forward declarations and full includes, and integrate IWYU into CMake builds to reduce compilation cascades in large codebases.

## Triggers

- "How do I use include-what-you-use?"
- "How do I reduce my C++ compilation times by fixing includes?"
- "How do I interpret IWYU output?"
- "Should I use a forward declaration or include?"
- "How do I integrate IWYU with CMake?"
- "What is a compilation cascade and how do I avoid it?"

## Workflow

### 1. Install and run IWYU

```bash
# Install
apt-get install iwyu              # Ubuntu/Debian
brew install include-what-you-use # macOS

# Run on a single file
iwyu -Xiwyu --error main.cpp 2>&1

# Run via compile_commands.json
iwyu_tool.py -p build/ src/main.cpp 2>&1 | tee iwyu.log

# Run on entire project
iwyu_tool.py -p build/ 2>&1 | tee iwyu.log
```

### 2. CMake integration

```cmake
# CMakeLists.txt — use IWYU as include checker during build
find_program(IWYU_PROGRAM NAMES include-what-you-use iwyu)
if(IWYU_PROGRAM)
    set(CMAKE_CXX_INCLUDE_WHAT_YOU_USE
        ${IWYU_PROGRAM}
        -Xiwyu --mapping_file=${CMAKE_SOURCE_DIR}/iwyu.imp
        -Xiwyu --no_comments
    )
endif()
```

```bash
# Build with IWYU analysis
cmake -S . -B build -DCMAKE_CXX_COMPILER=clang++
cmake --build build 2>&1 | tee iwyu.log
```

### 3. Interpreting IWYU output

```text
main.cpp should add these lines:
#include <string>   // for std::string
#include "mylib/widget.h"  // for Widget

main.cpp should remove these lines:
- #include <vector>  // lines 5-5
- #include "internal/detail.h"  // lines 8-8

The full include-list for main.cpp:
#include <iostream>  // for std::cout
#include <string>    // for std::string
#include "mylib/widget.h"  // for Widget
---
```

Reading the output:
- **should add**: headers providing symbols used but not yet included
- **should remove**: headers included but whose symbols aren't used directly
- **The full include-list**: what the final header list should look like

### 4. Apply IWYU fixes automatically

```bash
# fix_include script (comes with IWYU)
fix_include < iwyu.log

# Options
fix_include --nosafe_headers < iwyu.log    # more aggressive — also removes system headers
fix_include --comments < iwyu.log          # preserve // comments in includes
fix_include --dry_run < iwyu.log           # preview changes without applying

# Limit to specific files
fix_include --only_re='src/.*\.cpp' < iwyu.log

# Run and apply in one pipeline
iwyu_tool.py -p build/ 2>&1 | fix_include
```

### 5. Forward declarations vs full includes

IWYU prefers forward declarations (class/struct declarations without definition) when the full type isn't needed:

```cpp
// full_include.h — DON'T include this if only a pointer is used
#include "widget.h"      // full definition: Widget members, vtable, etc.

// forward_decl.h — OK when Widget* or Widget& is sufficient
class Widget;            // forward declaration
void process(Widget *w); // pointer: forward decl is enough

// When forward declaration is sufficient:
// - Pointer or reference parameter: Widget*, Widget&
// - Return type as pointer: Widget*
// - Base class declared elsewhere (but defined in .cpp)

// When full include is required:
// - Inheriting from Widget: class MyWidget : public Widget
// - Accessing Widget members: w.field, w.method()
// - Creating Widget instances: Widget w;
// - Sizeof(Widget)
// - Template instantiation: std::vector<Widget>
```

```cpp
// IWYU-friendly header
#pragma once
class Widget;            // forward declare (saves downstream compilation)

class Container {
    Widget *head_;       // pointer: forward decl is enough
public:
    void add(Widget *w);
    Widget *get(int idx);
};
// Container.cpp includes "widget.h" — only .cpp pays the compile cost
```

### 6. Mapping files for third-party headers

IWYU mapping files teach IWYU about indirect includes (where `#include <vector>` is provided by some internal STL header):

```python
# iwyu.imp — IWYU mapping file
[
  # Map internal LLVM headers to public ones
  { "include": ["<llvm/ADT/StringRef.h>", "private",
                 "<llvm/ADT/StringRef.h>", "public"] },

  # Map system headers to POSIX equivalents
  { "include": ["<bits/types.h>", "private", "<sys/types.h>", "public"] },
  { "include": ["<bits/socket.h>", "private", "<sys/socket.h>", "public"] },

  # Symbol → header mappings
  { "symbol": ["std::string", "private", "<string>", "public"] },
  { "symbol": ["NULL",        "private", "<cstddef>", "public"] },
]
```

```bash
# Use mapping file
iwyu -Xiwyu --mapping_file=iwyu.imp main.cpp

# IWYU ships with common mappings
ls /usr/share/include-what-you-use/
# gcc.stl.headers.imp, boost-1.62.imp, libcxx.imp, etc.

iwyu -Xiwyu --mapping_file=/usr/share/include-what-you-use/gcc.stl.headers.imp
```

### 7. What IWYU does not do

IWYU has limits — be aware:

```bash
# IWYU may give wrong advice for:
# - Macros from headers (hard to track)
# - Template specializations in included headers
# - Headers required for correct ODR linking

# Safe iterative workflow:
# 1. Run IWYU
# 2. Apply fixes with fix_include
# 3. Rebuild and run tests
# 4. Revert any changes that break the build
# 5. Repeat until clean

# Check for compilation cascade: how many TUs include a header
grep -rl '#include "expensive.h"' src/ | wc -l
```

## Related skills

- Use `skills/build-systems/build-acceleration` for ccache and other compile speed techniques
- Use `skills/build-systems/cmake` for CMake integration of build analysis tools
- Use `skills/compilers/cpp-modules` for C++20 modules as a long-term solution to include bloat

© mohitmishra786 · MIT · mohitmishra786/low-level-dev-skills

Похожие скиллы

Все скиллы по теме «Языки программирования» →
qt-cmake-project qt-ai-skills Скилл собирает и правит CMake для проектов на Qt 6: цели, QML-модули, ресурсы. Пригодится, когда агент путает команды Qt 5 и Qt 6. CX Codex +1 530установок what-leaked-about-you UseOSINT Скилл проверяет, в каких утечках засветились email, ник, телефон или имя, и разбирает записи из дампов. Пригодится при аудите своей утечки или разборе инцидента. CX Codex +1 57 800установок cmake-vcpkg официальный github Правило задаёт Copilot контекст проекта на C++: vcpkg в режиме манифеста, настройки через CMakePresets.json и сборка под MSVC, Clang и GCC. ★ 40 418звёзд репо cpp-pro https://github.com/Jeffallan Пишет, оптимизирует и отлаживает C++ с concepts, ranges, корутинами, SIMD и шаблонной метапрограммированием. Пригодится для проектов на C++20/23, где нужна производительность и чёткая типизация. CX Codex +1 5 300установок cpp-testing affaan-m Скилл ведёт агента по циклу red-green-refactor в тестах на C++17/20 и настраивает GoogleTest с CMake/CTest. Пригодится, когда тесты падают или ведут себя нестабильно. CX Codex +1 4 700установок vcpkg официальный github Помогает настроить vcpkg в C++-проекте, закрепить версии библиотек и собрать проект для разных платформ. Пригодится при настройке манифеста или переходе с классического режима. 26установок

Из того же набора62

zig-debugging Скилл для ИИ-агента: разбирает паники Zig, error return traces и сессии GDB/LLDB. Пригодится, когда программа падает, а стек нечитаемый. CX Codex +1 511установок zig-build-system Помогает агенту писать и отлаживать build.zig: исполняемые файлы, библиотеки, C-исходники, опции сборки и тесты. CX Codex +1 508установок build-acceleration Скилл для ИИ-агентов, который помогает разобраться, почему сборка C/C++ идёт медленно, и настроить кэш, распределённую компиляцию и PCH. CX Codex +1 506установок zig-cinterop Скилл объясняет агенту, как связать Zig и C: @cImport, translate-c, extern struct, экспорт функций и сборка смешанных проектов. CX Codex +1 482установок rust-no-std Скилл для разработки на Rust без стандартной библиотеки: разбирает границу core, alloc и std, глобальные аллокаторы и обработчики паник. CX Codex +1 474установок dwarf-debug-format Скилл объясняет агенту, как читать отладочную информацию DWARF: секции ELF, split DWARF, debuginfod, влияние LTO и stripping. CX Codex +1 471установок intel-vtune-amd-uprof Скилл для профилирования процессора: помогает найти горячие функции, разобрать промахи кэша и заторы конвейера через Intel VTune и AMD uProf. CX Codex +1 469установок rust-async-internals Помогает агенту объяснять и отлаживать async Rust: модель poll, Pin и Unpin, планировщик tokio, утечки waker. Пригодится, когда задача виснет или тормозит. CX Codex +1 467установок

Спонсоры проекта

Компании, которые помогают держать аналитику открытой