Add beforeTokenWrite hook