@feliz_k I am not a CNC user but I think you should check out the following GCode commands:

G10 with no L parameter, or L1 parameter: https://docs.duet3d.com/en/User_manual/Reference/Gcodes#g10-set-workplace-coordinate-offset-or-tool-offset. This command sets the offset of a tool. The offset (in particular, the Z offset) is what you need to change when changing to a different length tool.

You can calculate the new tool offset to use in the G10 command by measuring the height at which your sensor is triggered by the new tool. However, you may not need to do that because there is also this command:

G30 with S-2 parameter: https://docs.duet3d.com/en/User_manual/Reference/Gcodes#g30-single-z-probe. This uses a Z probe (which could be your sensor) to set the tool offset automatically. Don't forget to use G31 to set the Z probe trigger height to the tool height at which the probe triggers.

HTH David