A new technique of undulator field correction for cryogenic permanent magnet undulators (CPMUs) is proposed to correct the phase error induced by temperature gradient. This technique takes advantage of two important instruments: one is the in-vacuum self-aligned field analyzer with laser instrumentation system to precisely measure the distribution of the magnetic field generated by the permanent magnet arrays placed in vacuum, and the other is the differential adjuster to correct the local variation of the magnet gap. The details of the two instruments are described together with the method of how to analyze the field measurement data and deduce the gap variation along the undulator axis. The correction technique was applied to the CPMU with a length of 1.7 m and a magnetic period of 14 mm. It was found that the phase error induced during the cooling process was attributable to local gap variations of around 30 m, which were then corrected by the differential adjuster.