running about like a headless chicken

running (or rushing) about like a headless chicken

acting in a panic-stricken manner and not thinking clearly about what should be done.
A decapitated chicken may continue to flap about for a few moments before finally expiring.