I tried gcc clean to clean up a gcode file that was created by freecad cam workbench. This code was full of unnecessary intermediate moves, after running gcc clean all of the z moves were removed except for the first one:
original code:
test.txt
gcc cleaned code:
test-gcc.txt
I hope this helps.