It’s super easy to ruin a perfectly good spool of filament. Learn what to avoid if you want to keep your 3D printer’s filament in perfect shape!
https://www.youtube.com/watch?v=WlmCc-vRNr0
I might have gone too far with the thumbnail
i am using a tweaked end g-code that slowly retract the filament out of the hot zone when the print is finished (there is also a start g-code to prime that) another advantage is you can change the Filament without heating.
I retract the filament out of the hot zone in my end code too, but not slowly. Seems like you’d need a longer retraction to ensure that it’s disconnected. Trying to automate a cold pull seems too tedious and unreliable, and a long, wispy strand of filament can fold over and cause a jam if you try to push the filament back in without clipping the end.
This is mine (removed some xy - movement and other msg/restart code)
G91
G1 E-2 F300
G1 Z+10 E-15 X-20 Y50 F1500
G1 E+7 F50
so its pulling out fast - moving back in slowly … works very reliable on my hotend - and i can remove the filament when cold without force. When starting a print it will prime 40mm - enough for a filament change and to ensure proper extrusion as the rest material within the hotend is pushed out.
I just have the end gcode wait until the extruder is at 50 degrees and then shut off the power automatically (ATX PSU). That’s how I know the print is done, OctoPrint’s camera feed is “black” (well, either the print is done or my wifi has dropped out… again). 
I often let the hot end cool a bit (~15 degrees) and then retract/pull the filament very quickly. This way it also removes any dirt left in it (then clip/snap the end of the filament and round it slightly with a lighter for the next insertion). Retracting slowly when the hot end is still very hot is asking for trouble: the tiny elongated strings that may be left will easily melt at places where you really do not want molten material (typically above the transition zone). Either they may stick to the walls or they will impede the new filament you want to load into the printer.
Finally on all metal hot ends (actually on actively cooled down hot ends), never shut the printer down before the idle hot end goes below the melt point, else heat will creep up into the hot end and possibly result in a clog. The only way out is then to re-heat without the fan in order to have a chance to pull the filament out (but this is a risky business nonetheless as heating a long portion of the hot end is certainly out of the specifications)…
Thank you for that wisdom about messy filament! That will save me some future grief!
@Thomas_Sanladerer we think we have a solution to your number one filament problem http://e-nable.org/2017/10/17/do-your-prints-fail-because-filament-gets-tangled-or-because-filament-runs-out/. In our lab we have tested the Filament FAULT Detector on 5 printers over the past several weeks. We have finished up the ends of 6 spools of filament without a printing failure and have avoided two failed prints from tangled filament! (One event I’m calling tangled filament was actually the bent end of the filament being stuck on the spool.) Since we always look for a good squish at the beginning of a print job, we are hoping that failed prints are going to become rare events for us. Please try it out and let us know if it works for you.