AgentLint Verified 89/10095 C++ repos analyzed

    C++ CLAUDE.md & AGENTS.md Template

    CMake/Ninja presets, clang-format, sanitizers, and RAII safety distilled from C++ repos.

    # C++ Project — C++20 Harness
    
    C++20 project built with CMake presets + Ninja and verified with GoogleTest and AddressSanitizer.
    
    ## Commands
    
    - Configure: `cmake --preset debug`
    - Incremental build: `cmake --build --preset debug -j`
    - Fast single test: `ctest --preset debug -R TargetTest --output-on-failure`
    - Format check: `clang-format --dry-run --Werror src/*.cpp include/*.hpp`
    
    ## Rules
    
    - Don't invoke raw `g++` or `clang++` directly. Instead build through CMake presets. Because direct compilation bypasses project defines and sanitizer flags.
    - Don't use raw owning `new`/`delete`. Instead use RAII (`std::unique_ptr`, `std::vector`, `std::span`). Because manual ownership leaks under early returns.
    - When modifying public headers or ABI structs, read `docs/abi-policy.md`.
    
    ## Continuity
    
    - Keep `build/` and `CLAUDE.local.md` gitignored and record benchmark deltas in `HANDOFF.md`.

    Most Adopted C++ Rules Across Real Open-Source Repos

    Measured across 95 public C++ repositories in the 4,533-repo harness study:

    cmaketooling

    CMake build system

    52.7%29 repos
    modern-cpppatterns

    Modern C++ (C++17/20/23)

    45.5%25 repos
    stlpatterns

    Use STL algorithms and containers

    34.5%19 repos
    unit-teststesting

    Write unit tests for all changes

    32.7%18 repos
    smart-pointerspatterns

    Use smart pointers (unique_ptr, shared_ptr)

    25.5%14 repos
    namespacespatterns

    Use namespaces appropriately

    23.6%13 repos
    error-handlingpatterns

    Proper error handling with context

    20.0%11 repos
    ci-cdtooling

    CI/CD pipeline must pass

    20.0%11 repos
    Essential Commands (Checks W1 & W7)
    install
    cmake --preset debug
    fastTest
    ctest --preset debug -R TargetTest --output-on-failure
    fullTest
    ctest --preset debug --output-on-failure
    lint
    clang-format --dry-run --Werror src/*.cpp include/*.hpp
    build
    cmake --build --preset debug -j
    Common C++ Agent Pitfalls
    • 01Agents trigger raw g++ commands instead of CMake presets, missing include paths and sanitizer flags.
    • 02Manual new/delete introduces leaks when std::unique_ptr is available.

    More Verified Stack Templates