4. Given a regular quadrilateral pyramid $P-A B C D$ with all edges of equal length. Taking $A B C D$ as one face, construct a cube $A B C D-E F G H$ on the other side of the pyramid. Then, the cosine value of the angle formed by the skew lines $P A$ and $C F$ is $\qquad$
4. $\frac{2+\sqrt{2}}{4}$.

Assume the edge lengths of the quadrilateral pyramid $P-ABCD$ are all 2. Taking the center $O$ of the square $ABCD$ as the origin, and the directions of $\overrightarrow{DA}$, $\overrightarrow{DC}$, and $\overrightarrow{OP}$ as the positive directions of the $x$-axis, $y$-axis, and $z$-axis, respectively, we establish a spatial rectangular coordinate system.
By calculation, we know $P(0,0, \sqrt{2})$,
$$
\begin{array}{l}
\overrightarrow{PA}=(1,-1,-\sqrt{2}), \overrightarrow{CF}=(2,0,-2). \\
\text{Then }|\overrightarrow{PA}|=2,|\overrightarrow{CF}|=2 \sqrt{2}, \\
\overrightarrow{PA} \cdot \overrightarrow{CF}=2+2 \sqrt{2}.
\end{array}
$$

Let the angle between the skew lines $PA$ and $CF$ be $\theta$. Therefore, $\cos \theta=\left|\frac{2+2 \sqrt{2}}{2 \times 2 \sqrt{2}}\right|=\frac{2+\sqrt{2}}{4}$.