Replace your halyard rope at first signs of wear before it breaks! Remember you need enough rope to go up and back down again.
How to change your rope on an external halyard: buy enough rope to go up and down the pole (20’ pole requires 40’ of halyard). Holding the rope tightly cut the old halyard, being careful not to let it loose. Trim the end of the new rope and, using electrical tape, tape the two ends together very carefully so they are secure. Slowly raise the new rope by pulling the old rope and gently pull through the truck’s pulley system. Bring it all the way down and tie the new rope with a sturdy knot. Raise the knot to the top of the pole, attach the snap hooks (now is a good time to replace them as well) and hoist your flag. This places the knot below the cleat and alleviates it from having wind stress pull your knot apart.
Below see the choices of halyard first as "cut to length" and then by full spools of halyard.