FERMI is the first seeded EUV-SXR free electron laser (FEL) user facility, and it is operated at Elettra Sincrotrone Trieste. Two of the four already operating beamlines, namely LDM (Low Density Matter) and DiProI (Diffraction and Projection Imaging), use a Kirkpatrick-Baez (K-B) active X-ray optics system for focusing the FEL pulses onto the target under investigation. A wafefront sensor is used as diagnostic for the characterization of the focused spot and for the optimization of the parameters of these active optical systems as well. The aim of this work is, first, to describe in detail the optimization procedure using the wavefront sensor through the minimization of the Zernike coefficients, and second, report on the final results obtained on the K-B optical system at the DiProI endstation. The wavefront sensor, mounted out of focus behind the DiProI chamber, allows to compute the intensity distribution of the FEL beam, typically a mix between several modes resulting in a ”noisy hyper-Gaussian” intensity profile, and the wavefront residual from ideal propagation shape and after tilt correction. Combining these two measures we can obtain the electric field of the wave out of focus. Propagating back the electric field we reconstruct the focal spot in far field approximation. In this way the sensor works as a diagnostic reconstructing the focal spot. On the other hand, after modelling the electric field with a Zernike polynomial it is easy and fast to optimize the mirror bending and the optical system angles by minimizing the aberrations, quantified in terms of Zernike coefficients. Since each coefficient corresponds to a single parameter, they can be minimized one at the time. Online wavefront measurements have made possible the optimization of the bending acting on the mirror curvature, and of the (pitch and roll) angle positions of the K-B system. From the wavefront measurements we have inferred a focal spot for DiProI of 5.5 μm x 6.2 μm at 32 nm wavelength, confirmed by the PMMA ablation imprints. The experimental results were compared with the predictions from simulations obtained using the WISE code, starting from the characterization of the actual mirror surface metrology. The results from simulations were found to be in agreement with the experimental measurements.