[proofplan]
We first reduce to a homogeneous invariant polynomial and use its symmetric polarisation. On a local trivialising neighbourhood, the connection is represented by a Lie-algebra-valued $1$-form $a$ and the curvature by a Lie-algebra-valued $2$-form $\Omega$, so the Chern-Weil form is locally $q(\Omega,\dots,\Omega)$. Differentiating this expression gives terms involving $d\Omega$, and the Bianchi identity rewrites $d\Omega$ as a commutator term $-[a,\Omega]$. The infinitesimal form of $\operatorname{Ad}$-invariance makes those commutator terms cancel, so the local [exterior derivative](/theorems/1525) is zero; since closedness is local, the global form is closed.
[/proofplan]
[step:Reduce to one homogeneous invariant polynomial]
Write the invariant polynomial as a finite sum of homogeneous invariant polynomials,
\begin{align*}
q=q_0+q_1+\cdots+q_N,
\end{align*}
where $q_k\in I^k(G)$ and $q_k=0$ for all but finitely many $k$. The Chern-Weil form is the corresponding inhomogeneous form
\begin{align*}
q(F_A)=q_0(F_A)+q_1(F_A)+\cdots+q_N(F_A).
\end{align*}
Since the exterior derivative is linear, it suffices to prove
\begin{align*}
d\bigl(q_k(F_A)\bigr)=0
\end{align*}
for a fixed homogeneous component $q_k\in I^k(G)$. If $k=0$, then $q_0(F_A)$ is the constant $0$-form $q_0$, hence its exterior derivative is zero. We therefore assume $k\geq 1$.
Let
\begin{align*}
Q:\mathfrak g^k\to \mathbb R
\end{align*}
be the symmetric $k$-linear polarisation of $q_k$, so that
\begin{align*}
q_k(X)=Q(X,\dots,X)
\end{align*}
for every $X\in\mathfrak g$. The characteristic form associated to $q_k$ is obtained by applying $Q$ to $k$ copies of the curvature:
\begin{align*}
q_k(F_A)=Q(F_A,\dots,F_A)\in \Omega^{2k}(M).
\end{align*}
[/step]
[step:Write the calculation in a local gauge]
Let $U\subset M$ be an [open set](/page/Open%20Set) over which $P$ admits a smooth local section
\begin{align*}
s:U\to P.
\end{align*}
Define the local connection form
\begin{align*}
a:=s^*A\in\Omega^1(U;\mathfrak g)
\end{align*}
and the local curvature form
\begin{align*}
\Omega:=s^*F_A\in\Omega^2(U;\mathfrak g).
\end{align*}
By the definition of the Chern-Weil form through local gauges, the restriction of $q_k(F_A)$ to $U$ is
\begin{align*}
q_k(F_A)|_U=Q(\Omega,\dots,\Omega).
\end{align*}
Here $Q(\Omega,\dots,\Omega)$ denotes the scalar $2k$-form obtained by pairing the $\mathfrak g$-components with $Q$ and wedging the ordinary differential-form components.
Because closedness of a differential form is local on $M$, it is enough to show
\begin{align*}
dQ(\Omega,\dots,\Omega)=0
\end{align*}
on every such open set $U$.
[/step]
[step:Differentiate the polarised Chern-Weil expression]
Since $\Omega$ has even degree $2$ and $Q$ is $k$-linear, the ordinary graded Leibniz rule gives
\begin{align*}
dQ(\Omega,\dots,\Omega)=\sum_{j=1}^{k} Q(\Omega,\dots,d\Omega,\dots,\Omega),
\end{align*}
where $d\Omega$ appears in the $j$-th argument. Since $Q$ is symmetric and moving the $3$-form $d\Omega$ past a $2$-form $\Omega$ introduces the sign $(-1)^{3\cdot 2}=1$, all summands are equal. Hence
\begin{align*}
dQ(\Omega,\dots,\Omega)=k\,Q(d\Omega,\Omega,\dots,\Omega).
\end{align*}
The local Bianchi identity for the connection form $a$ states that
\begin{align*}
d\Omega+[a,\Omega]=0,
\end{align*}
where $[a,\Omega]\in\Omega^3(U;\mathfrak g)$ is obtained by wedging the scalar form parts and applying the Lie bracket to the $\mathfrak g$-parts. Therefore
\begin{align*}
dQ(\Omega,\dots,\Omega)=-k\,Q([a,\Omega],\Omega,\dots,\Omega).
\end{align*}
[guided]
We now compute the exterior derivative in a form where the Bianchi identity can be used. The local representative of the Chern-Weil form is
\begin{align*}
Q(\Omega,\dots,\Omega)\in\Omega^{2k}(U),
\end{align*}
where each argument is the same $\mathfrak g$-valued $2$-form $\Omega$. The exterior derivative acts on the wedge-product part of this expression, while $Q$ contracts only the Lie-algebra coefficients. Thus the graded Leibniz rule gives one term for each argument:
\begin{align*}
dQ(\Omega,\dots,\Omega)=\sum_{j=1}^{k} Q(\Omega,\dots,d\Omega,\dots,\Omega).
\end{align*}
There is no sign change when we compare these terms. Indeed, $d\Omega$ has form degree $3$, and each copy of $\Omega$ has form degree $2$. Moving $d\Omega$ past a copy of $\Omega$ contributes the sign $(-1)^{3\cdot 2}=1$. Since $Q$ is symmetric in its Lie-algebra arguments, every summand equals $Q(d\Omega,\Omega,\dots,\Omega)$. Hence
\begin{align*}
dQ(\Omega,\dots,\Omega)=k\,Q(d\Omega,\Omega,\dots,\Omega).
\end{align*}
The point of rewriting the derivative this way is that $d\Omega$ is controlled by the Bianchi identity. In the local gauge determined by $s$, the Bianchi identity says
\begin{align*}
d\Omega+[a,\Omega]=0.
\end{align*}
Equivalently,
\begin{align*}
d\Omega=-[a,\Omega].
\end{align*}
Substituting this identity into the preceding formula gives
\begin{align*}
dQ(\Omega,\dots,\Omega)=-k\,Q([a,\Omega],\Omega,\dots,\Omega).
\end{align*}
Thus closedness has been reduced to proving that the invariant polynomial kills this commutator expression.
[/guided]
[/step]
[step:Use infinitesimal invariance to cancel the commutator term]
We claim that
\begin{align*}
Q([a,\Omega],\Omega,\dots,\Omega)=0.
\end{align*}
This is a pointwise identity of scalar $3+2(k-1)$ forms. To verify it, expand locally
\begin{align*}
a=\sum_{\alpha} \eta_{\alpha}Y_{\alpha}
\end{align*}
and
\begin{align*}
\Omega=\sum_{\beta}\omega_{\beta}X_{\beta},
\end{align*}
where each $Y_{\alpha},X_{\beta}\in\mathfrak g$, each $\eta_{\alpha}\in\Omega^1(U)$, and each $\omega_{\beta}\in\Omega^2(U)$. It is enough by multilinearity to check each coefficient expression.
The infinitesimal form of $\operatorname{Ad}$-invariance of $Q$ says that, for every $Y,Z_1,\dots,Z_k\in\mathfrak g$,
\begin{align*}
\sum_{j=1}^{k}Q(Z_1,\dots,[Y,Z_j],\dots,Z_k)=0.
\end{align*}
Apply this with $Z_1=\cdots=Z_k=X$. Since $Q$ is symmetric, every term in the sum is equal, and therefore
\begin{align*}
k\,Q([Y,X],X,\dots,X)=0.
\end{align*}
Because $k\geq 1$, this gives
\begin{align*}
Q([Y,X],X,\dots,X)=0.
\end{align*}
By polarising this identity, equivalently by applying the same infinitesimal invariance identity before setting the curvature arguments equal and using the even degree of the curvature forms to avoid sign changes, each coefficient in $Q([a,\Omega],\Omega,\dots,\Omega)$ vanishes. Hence
\begin{align*}
Q([a,\Omega],\Omega,\dots,\Omega)=0.
\end{align*}
[/step]
[step:Conclude local and global closedness]
Combining the derivative computation with the commutator cancellation gives
\begin{align*}
dQ(\Omega,\dots,\Omega)=0
\end{align*}
on every trivialising open set $U\subset M$. Since
\begin{align*}
q_k(F_A)|_U=Q(\Omega,\dots,\Omega),
\end{align*}
we have
\begin{align*}
d\bigl(q_k(F_A)\bigr)|_U=0
\end{align*}
for every member of a trivialising [open cover](/page/Open%20Cover) of $M$. Therefore
\begin{align*}
d\bigl(q_k(F_A)\bigr)=0
\end{align*}
on $M$.
This proves closedness for every homogeneous component $q_k$ of $q$. By linearity of $d$, the full inhomogeneous Chern-Weil form satisfies
\begin{align*}
d(q(F_A))=0.
\end{align*}
[/step]