Rats, flies, and ants in the compost
Finding pests in your compost is annoying, but it’s also useful information. Different pests are attracted to different conditions, so which one you’re seeing tells you a fair amount about what’s actually going on inside the heap.
Quick fix
- Rats: stop adding food waste that isn’t buried, and check the base isn’t giving them shelter.
- Fruit flies: bury fresh scraps under existing material instead of leaving them exposed on top.
- Ants: usually means the pile has gone too dry — rewet it.
Rats
Rats are drawn to two things: an easy food source, and shelter. A compost heap can offer both if it’s not managed carefully. The biggest single cause is exposed food waste, especially anything that shouldn’t be in the heap in the first place, like meat, dairy, or cooked food (see the guide on what not to add). Even appropriate scraps like vegetable peelings can attract rats if they’re left sitting on the surface rather than mixed into the pile.
The fix starts with what you put in and how. Bury fresh scraps under a layer of existing material or browns rather than leaving them on top, and cut out meat, dairy, and cooked food entirely. A solid base — a wire mesh underneath an open heap, or a bin design with a closed or mesh bottom — makes it much harder for rats to burrow up into the pile from below, which is often how they get established in the first place. If you’re using a bin with a lid, make sure it’s actually closing properly; rats are persistent and will find a gap.
Fruit flies
Small flies hovering around the heap, especially near the surface, are almost always fruit flies, and they’re drawn to exposed fresh fruit and vegetable scraps. They’re mostly a nuisance rather than a genuine problem — they don’t damage the compost or attract larger pests on their own — but they’re unpleasant if the heap is anywhere near where you sit or hang washing.
The fix is simple: bury fresh scraps rather than leaving them sitting on the surface. A few inches of existing compost or a scattering of browns over the top of new additions is usually enough to stop flies from being able to reach the scraps to lay eggs. If you’re adding scraps often, keeping a small covered container in the kitchen and emptying it into the heap every couple of days, burying it each time, keeps exposure to a minimum.
Ants
Ants turning up in numbers usually means one specific thing: the pile has gone too dry. Ants prefer dry, undisturbed conditions, and a properly moist, actively decomposing heap is generally too damp and too active for them to want to nest in. If you’re seeing ant activity, it’s worth doing the squeeze test described in the too-dry guide — grab a handful from the middle and squeeze; if it crumbles apart without holding together, that’s your answer.
Rewetting the pile (in layers, as you turn it, not just poured on top) and getting decomposition active again usually moves ants on within a week or two, since the conditions that suit them stop being available. This is a case where the pest is doing you a favour: without the ants, you might not have noticed the pile had dried out and stalled.
The general pattern
Across all three, the pattern is the same: pests show up when a heap offers something they want — food, shelter, or dry undisturbed ground — that a well-run heap generally doesn’t provide. Burying scraps, keeping the base secure, and keeping the moisture and activity level where it should be solves the large majority of pest problems without needing anything beyond the compost heap itself. If a serious rat problem persists despite all of this, it’s worth considering whether the heap’s location, right up against a fence or a shed with existing rat activity, is part of the problem, independent of anything you’re doing with the compost.