update: I've taken the headset apart, cleaned it, regreased it and reassembled everything. It's been fine since. The bike has sealed cartridge bearings, so I'm not sure what it was - it's not like they were dirty and didn't have proper lubrication. Maybe something wasn't positioned correctly or some dirt got in there somehow.
My bike, a two year old Trek Domane (aluminium frame, carbon fork, 4000mi/6500km mileage) makes a cracking sound when the handlebars are turned. Here's a recording:
This noise has been present for a while, but recently started happening much more frequently and is easier to reproduce than before. I've also noticed that a similar clunking noise happens under hard braking with the front brake - it makes me think this might be a headset issue. It does not happen during normal riding, probably because you'd rarely turn the handlebars this much at speed.
The bike recently had its annual inspection and nothing came up - the noise got worse later (though not immediately, so I don't think the shop messed something up). The bike was never in any crashes and the headset, fork etc are all stock.
Could this be a headset problem? Would it be good to take it apart, clean & inspect?