Knife-edge imaging is a successful method for determining the wavefront distortion of focusing optics such as Kirkpatrick-Baez mirrors or compound refractive lenses. In this study, the wavefront error of an imperfect elliptical mirror is predicted by developing a knife-edge program using the SHADOW/OASYS platform. It is shown that the focusing optics can be aligned perfectly by minimizing the parabolic and cubic coefficients of the wavefront error. The residual wavefront error provides precise information about the figure/height errors of the focusing optics suggesting it as an accurate method for in situ optical metrology. A Python program is developed to design a customized wavefront refractive corrector to minimize the residual wavefront error. Uniform beam at and out of focus and higher peak intensity are achieved by the wavefront correction in comparison with ideal focusing. The developed code provides a quick way for wavefront error analysis and corrector design for non-ideal optics especially for the new-generation diffraction-limited sources, and saves considerable experimental time and effort.