Clocking of lens elements is frequently used as an effective method of compensating for two-dimensional tolerances such as material inhomogeneity and surface figure errors. Typically, the lens designer has to determine the optimum angles of rotation by manually modeling lens element clocking in the commercial optical design software because the nature of errors resolved by lens clocking does not lead to good convergences for clocking optimization. In this paper, a method of automatic clocking optimization is developed. The method is implemented using a combination of particle swarm optimization algorithm and commercial optical design software. The optimum angles of rotation and predicted imaging performance are automatically calculated using this method. Methods of implementation and optimization examples are also given.