Worms are living creatures, and their living quarters need to provide them with the right conditions to thrive.
When the worms are all in the lid or stuck to the sides of the bin, it can be just because worms are sensitive to changes in the weather and naturally move to a high point before heavy rain to protect themselves from floods.
However, it can also indicate that your wormery is developing a serious problem.
Too much food - if you overfeed the worms, the excess food will rot and heat up, and may become too acid for the worms to survive.
Too wet. Check the drainage tap is not blocked. (Tip: when setting up the bin, place a small empty plastic flowerpot as a sleeve over the inside of the tap to help prevent it becoming clogged by drainage materials or compost). Leave the tap open for a while to allow the compost to drain. If it has become a really smelly, slimy nasty mess you may have to start over again. Try mixing through shredded paper and cardboard to help the compost dry out, and add some garden soil or leaf mould. There will still be cocoons in the compost even if all the worms have died, and if you've put all the conditions right they are very likely to hatch out and start the wormery up again for you.
Lack of air - If the wormery smells unpleasant it may have gone anaerobic. Normally the wormery should have an earthy compost smell. Anaerobic means that there isn't any oxygen in the mixture. Worms need oxygen to survive, so turning the compost over now and then to loosen it will help to keep them happy. Adding plenty of slightly damp shredded cardboard or paper will help too.
Too hot or too cold. Site the wormery away from direct sunlight, and out of strong winds, and insulate or put it in a shed in the winter.
Wrong foods - check the type of waste you have put in, eg too many onions or citrus fruit are bad for worms. If you add dog waste just after your dog has been wormed it can kill your composting worms too.
Pesticide contamination. Some wastes, such as cut flowers, may have been heavily treated.
Winter/cold weather - Worms will survive cold weather outside if protected in the worm bin. If possible put the bin in a shed or cover with bubble wrap. During cold weather the worms slow down and are not able to digest as much food waste, so you need to reduce the food supply in winter.
Holidays - worms can be left for up to a few weeks between feeds. Leave them a good supply of food well mixed with lots of damp shredded paper and cardboard. If you will be away for some time, leave the tap open so the compost doesn't get too wet.
Fruit flies - these are very small brown flies. They won't harm either you or the worms but can be a nuisance if a cloud of them appear every time you open up your wormery. The fruit fly eggs are generally on the waste before it is put into your wormery, so eradicating them is virtually impossible. The simplest solution is to make sure that each layer of food is well covered either with soil, moist cardboard or shredded paper. If you really have a problem with them, boil or microwave all fruit and vegetable peelings to stop the problem. Or pop a fly trap in the top of the bin made from a jar with holes in the lid and containing a little jam and water.
Ants - If there are ants living in the wormery this indicates that it is too dry. Dampening the compost will make the ants leave.
Mould/Fungi - As food starts to decay it often becomes covered in mould or fungi. This should not cause any problems.
Slugs/Snails - Some species will eat earthworms so best removed from wormery
Spider Mites - These small white or red mites like moist conditions so could indicate that the wormery is too wet.
Spiders/woodlice/beetles - Generally not a problem.
See also: Worm composting