4. Let $\left\{a_{n}\right\}$ be an arithmetic sequence with common difference $d(d \neq 0)$, and the sum of the first $n$ terms be $S_{n}$. If the sequence $\left\{\sqrt{8 S_{n}+2 n}\right\}$ is also an arithmetic sequence with common difference $d$, then the general term of the sequence $\left\{a_{n}\right\}$ is $a_{n}=$ $\qquad$
4. $4 n-\frac{9}{4}$.
$$
\begin{array}{l}
\text { Given } \sqrt{8 S_{n+1}+2(n+1)}-\sqrt{8 S_{n}+2 n} \\
=d(n \geqslant 1) \\
\Rightarrow 8 S_{n+1}-8 S_{n}+2=d+2 d \sqrt{8 S_{n}+2 n} \\
\Rightarrow 8 a_{n+1}+2=d+2 d \sqrt{8 S_{n}+2 n} .
\end{array}
$$

Similarly,
$$
8 a_{n+2}+2=d+2 d \sqrt{8 S_{n+1}+2(n+1)} \text {. }
$$

Subtracting the above two equations, we get
$$
\begin{array}{l}
8\left(a_{n+2}-a_{n+1}\right) \\
=2 d\left(\sqrt{8 S_{n+1}+2(n+1)}-\sqrt{8 S_{n}+2 n}\right) \\
\Rightarrow 8 d=2 d^{2} .
\end{array}
$$

Since $d \neq 0$, we have $d=4$.
$$
\begin{array}{l}
\text { Also, } \sqrt{8 S_{2}+4}-\sqrt{8 S_{1}+2} \\
=\sqrt{16 a_{1}+36}-\sqrt{8 a_{1}+2}=4,
\end{array}
$$

Solving this, we get $a_{1}=\frac{7}{4}$.
Thus, $a_{n}=\frac{7}{4}+4(n-1)=4 n-\frac{9}{4}$.