The part of you code where your character ducks, just add a code of line there to change the collision shape :
$CollisionShape2D.scale.x = Your value
$CollisionShape2D.scale.y = Your Value
You can use the Inspector tab which is the window on your right hand side where you will see Transform option under which there will be Scale in x and y provided. Tweak the shape using those and once you get a shape that fits well with your character when he is ducking, use the above code to put the values of x and y.