Ther are 3 ways to modify Mercurial's behavior: writing "hooks" in a user's (or system-wide) hgrc file, writing and "extension" for hg and finally modifying hg itself. I will cover those briefly below.
Hooks
A hook is an action that gets executed before or after a command is issued. For example, to see the differences before committing changes, you could write it as a "precommit" hook:
[hooks] # Before we commit, make sure we know what we are committing precommit = hg diff|less
In this case, precommit says when to perform the action and