During the operation of 5-axis CNC machine tools, the angle deviation of the rotation axis greatly affects the tool path control. Therefore, a post-processing algorithm of five-axis CNC machine tool with optimized rotation angle was proposed. Firstly, the basic The structure of the machine tool was analyzed, the Hausdoff distance was used to obtain the matching error between the actual machined surface and the difference surface, and the error compensation method was used to compensate the obtained error, and the rotation axis angle of the machine tool was completed according to the processing result. Based on the optimization results, the machine tool coordinate system was established, and the machine tool post-processor was developed through the coordinate transformation results and integrated into the relevant software to realize the post-processing of the machine tool. The experimental results show that the proposed method achieves better processing results when used for post processing of machine tools.