What happened in the March 2013 fork was that two different versions of the bitcoin client disagreed about what a valid block was. You could look for a block reorg, but that will only show up when the fork is fixed. How could you detect a hard fork as soon as it happens?
Well, you could run 5 different versions of the bitcoin client at once, then figure out when they get out of sync for a few minutes. That's when you know there's a version-specific fork. I should note that this is mainly aimed at getting the client fixed faster, not protecting a merchant.
Detecting being out of sync
You could write a program that polled all of clients looking for their latest block.
Psuedocode:
run on each node
block number = node.getblockcount()
latest block = node.getblockbycount(block number)
latest block hash = latest block['hash']
Oh, by the way, this requires the getblock patch.
Now, if these differ for more than a minute or so (and you're not still in the initial syncing phase) then you might have a hard fork.
Making sure you have a good connection to the network
Let's say that you had a 0.8 client that was only connected to 0.7 clients. Even though it would have accepted the blocks in the March fork, it never even hears about them, meaning we won't detect the fork.
I'm not sure how to solve this. Perhaps upping MAX_OUTBOUND_CONNECTIONS ?
Preventing false alerts
If network conditions were really bad, then it's possible that one client would receive a new block, but the others wouldn't. You should use addnode to make them all talk to each other.
Speifically, a reorg of six or more blocks? – Stephen Gornick – 2013-03-11T10:02:20.613
Amazing the timing of this question... a few hours after I asked it, there was a chain split with version 0.8 ... how did people detect this? – goodguys_activate – 2013-03-12T13:32:06.690
It was expected some devs had automated methods for learning of it, but it was actually first discovered from users questioning why in their logs the "locks" were not allowing blocks that other nodes (v0.8 clients, it was later discovered) were not having a problem with. So it was discovered via a manual process. – Stephen Gornick – 2013-04-01T16:30:06.477