One of the more surprising things about ghee to a lot of home cooks is that it doesn't need to be refrigerated, unlike the butter it's made from. Understanding why makes it easier to store correctly and get the longest possible shelf life out of a batch.
Butter spoils relatively quickly at room temperature mainly because of its water content and milk solids, both of which support bacterial growth. The entire point of making ghee is removing both of those things - what's left after straining is nearly pure butterfat, which doesn't support the same kind of spoilage. Properly made ghee, strained thoroughly and stored in a clean, dry, sealed container, can sit at room temperature for several months without going bad.
Stored properly at room temperature, ghee typically stays good for 2 to 3 months, and often considerably longer - many home cooks and traditional practices keep it for up to a year without refrigeration. If you'd rather not take any chances, refrigerating ghee extends this even further, up to a year or more, at the cost of the ghee becoming firmer and slightly less convenient to scoop straight from the fridge.
Discard ghee if you notice an off, rancid smell (distinct from its normal nutty aroma), any visible mold, or a change in color toward gray or unusually dark. Properly made and stored ghee should remain a consistent golden color and smell pleasantly nutty for the duration of its shelf life - any deviation from that is a sign something has gone wrong, whether from moisture contamination or simple age.
While not strictly necessary, refrigerating ghee is a reasonable choice if you live somewhere very warm, don't go through it quickly, or just prefer the extra peace of mind. Refrigerated ghee will solidify into a firmer, more butter-like texture, which some people actually prefer for spreading. Ghee also freezes well for very long-term storage, though this is rarely necessary given how long it already lasts at room temperature when made and stored correctly.
Ghee's shelf stability is part of what makes it such a convenient pantry staple compared to butter - it can sit out on a counter or in a cupboard, ready to scoop straight into a hot pan, without the softening-at-room-temperature dance that butter requires for some recipes, or the concern about it going bad if left out.
For everything else about using ghee once you've got a properly stored batch, see the complete ghee guide.