chsh-sk-ncs-clang-format

Formats C/C++ source files using the clang-format binary from the active NCS toolchain.

1|Updated Jan 30, 2026
One-click install
npx skills add https://github.com/chshzh/claude --skill chsh-sk-ncs-clang-format-chshzh
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: chsh-sk-ncs-clang-format
Source: https://github.com/chshzh/claude/tree/main/skills/chsh-sk-ncs-clang-format
Command: npx skills add https://github.com/chshzh/claude --skill chsh-sk-ncs-clang-format-chshzh

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Applying consistent code formatting in NCS/Zephyr projects requires locating the correct clang-format binary bundled with a specific toolchain version and choosing the right style file, which is tedious and error-prone to do manually. ## Core Features & Use Cases - Toolchain-aware formatting: Resolves the active NCS toolchain version and locates the matching clang-format binary under /opt/nordic/ncs/toolchains. - Style resolution: Uses the project's .clang-format if present, otherwise falls back to the Zephyr SDK style file with ColumnLimit 100. - Flexible targets: Formats a whole project, a specific folder, or a single file, with a dry-run mode to preview changes. - Use Case: After editing several driver files in an NCS v3.2.1 project, ask to format the src folder and the skill finds bundle 322ac893fe's clang-format and applies Zephyr style in place. ## Quick Start Format all C files in my current NCS project using the clang-format from the active toolchain.

Frequently Asked Questions about chsh-sk-ncs-clang-format

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I run clang-format on an NCS or Zephyr project?

Use the clang-format binary bundled with your NCS toolchain at /opt/nordic/ncs/toolchains/<bundle_id>/bin/clang-format. Run it with -i on target files, or pipe find results through xargs to format all .c, .h, .cpp, and .hpp files recursively.

How do I find the clang-format binary for my NCS toolchain version?

Look up the bundle ID in /opt/nordic/ncs/toolchains/toolchains.json by matching your NCS version with jq, then the binary is at /opt/nordic/ncs/toolchains/<bundle_id>/bin/clang-format. Common mappings include v3.2.0/v3.2.1 to bundle 322ac893fe.

Which .clang-format style file should I use for Zephyr projects?

A .clang-format in the project root takes priority and is picked up automatically. Otherwise use the Zephyr SDK style at /opt/nordic/ncs/<version>/zephyr/.clang-format passed via --style=file, which sets ColumnLimit to 100.

Can I preview clang-format changes without modifying files?

Yes, run clang-format with --dry-run --Werror instead of -i to see a diff of what would change without writing to disk. This is useful for checking formatting compliance before committing.

Why does clang-format break Zephyr macros like ZBUS_CHAN_DEFINE?

clang-format can misformat Zephyr macros such as HTTP_RESOURCE_DEFINE or ZBUS_CHAN_DEFINE because their layout conflicts with checkpatch style. Wrap those sections in /* clang-format off */ and /* clang-format on */ guards to protect them.