A machine tool having a function of automatically correcting a machining program in tool replacement, comprising: machining means adapted to machine a workpiece using the tool; measurement means adapted to measure an actual dimension of the machined workpiece; detection means adapted to detect a dimensional difference between the measured actual dimension and a target dimension; and automatic correction means adapted to automatically correct the machining program based on the dimensional difference, characterised in that a signal output means is provided which is adapted to output a tool replacement signal when a tool is replaced; a controller is provided which is adapted to replace the machining program for machining the workpiece to a product dimension of the workpiece into a temporary machining program for temporarily machining the workpiece to a target dimension, when the tool replacement signal is output; wherein the machining means is adapted to temporarily machine the workpiece to the target dimension using the replaced tool in accordance with the temporary machining program; the measurement means is adapted to measure an actual dimension of the temporarily machined workpiece; the detection means is adapted to detect a temporary dimensional difference between the measured actual dimension of the temporarily machined workpiece and a target dimension; and a comparison means is provided which is adapted to compare the temporary dimensional difference with a threshold value, wherein the automatic correction means is adapted to automatically correct the machining program when the temporary dimensional difference is within the threshold value; wherein the machining means is adapted to actually machine the workpiece based on the automatically corrected machining program. machining means adapted to machine a workpiece using the tool; measurement means adapted to measure an actual dimension of the machined workpiece; detection means adapted to detect a dimensional difference between the measured actual dimension and a target dimension; and automatic correction means adapted to automatically correct the machining program based on the dimensional difference, characterised in that a signal output means is provided which is adapted to output a tool replacement signal when a tool is replaced; a controller is provided which is adapted to replace the machining program for machining the workpiece to a product dimension of the workpiece into a temporary machining program for temporarily machining the workpiece to a target dimension, when the tool replacement signal is output; wherein the machining means is adapted to temporarily machine the workpiece to the target dimension using the replaced tool in accordance with the temporary machining program; the measurement means is adapted to measure an actual dimension of the temporarily machined workpiece; the detection means is adapted to detect a temporary dimensional difference between the measured actual dimension of the temporarily machined workpiece and a target dimension; and a comparison means is provided which is adapted to compare the temporary dimensional difference with a threshold value, wherein the automatic correction means is adapted to automatically correct the machining program when the temporary dimensional difference is within the threshold value; wherein the machining means is adapted to actually machine the workpiece based on the automatically corrected machining program. <EOS>