diff --git a/.githooks/pre-commit b/.githooks/pre-commit
new file mode 100755
index 0000000000..f623b5d524
--- /dev/null
+++ b/.githooks/pre-commit
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Redirect output to stderr.
+exec 1>&2
+
+# Run clang-format on staged files; abort the commit if any files are changed
+if ! git clang-format ; then
+ echo "linting made changes to source files; aborting commit"
+ exit 1
+fi
diff --git a/.github/workflows/clang-format-check.yml b/.github/workflows/clang-format-check.yml
new file mode 100644
index 0000000000..fc2bc633d7
--- /dev/null
+++ b/.github/workflows/clang-format-check.yml
@@ -0,0 +1,18 @@
+name: clang-format check
+on: [pull_request]
+jobs:
+ formatting-check:
+ name: Formatting Check
+ runs-on: ubuntu-latest
+ strategy:
+ matrix:
+ path:
+ - 'include'
+ - 'src'
+ steps:
+ - uses: actions/checkout@v4
+ - name: Run clang-format style check
+ uses: jidicula/clang-format-action@v4.13.0
+ with:
+ clang-format-version: '17'
+ check-path: ${{ matrix.path }}
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 0328da85ce..bf11e02cc9 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -1,14 +1,15 @@
# Contributing to pret/pokeplatinum
-This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.
-
-## Contents
+
- [Editor Enhancements](#editor-enhancements)
- [Code Formatting](#code-formatting)
+
+
+This document provides a synopsis and loose guidelines for how to contribute to this project. It is a work in progress. Maintainers should expand this document.
-
## Editor Enhancements
+
This repository includes a script to generate a `compile_commands.json` that is compatible with C language servers such as `clangd`.
### Requirements
@@ -25,20 +26,25 @@ This repository includes a script to generate a `compile_commands.json` that is
This will create a file named `compile_commands.json` in the project root, overwriting the previous copy.
-
## Code Formatting
-This repository includes an opinionated `clang-format` specification which is integrated into the build system for convenience in ensuring that your code adheres to repository style guidelines.
+This repository includes an opinionated `clang-format` specification to ensure that we maintain a common code style. For convenience, a pre-commit hook is also provided in `.githooks` which will run `clang-format` against any staged changes prior to executing a commit.
### Requirements
-- `clang-format`
+- `clang-format@17` or newer
### Usage
-```bash
-./build.sh format
+To set up the pre-commit hook:
+
+```sh
+git config --local core.hooksPath .githooks/
```
-This will traverse the source tree and format all found C sources and headers according to the specified style rules.
+To run the formatter on the full source tree:
+
+```bash
+./format.sh
+```