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
2. CMake integration
3. Interpreting IWYU output
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
5. Forward declarations vs full includes
IWYU prefers forward declarations (class/struct declarations without definition) when the full type isn't needed:
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):
7. What IWYU does not do
IWYU has limits — be aware:
Related skills
- Use
skills/build-systems/build-accelerationfor ccache and other compile speed techniques - Use
skills/build-systems/cmakefor CMake integration of build analysis tools - Use
skills/compilers/cpp-modulesfor C++20 modules as a long-term solution to include bloat


