The invention discloses a castor oil-based quaternary ammonium salt anti-mud agent and a preparation method thereof. The anti-mud agent is prepared from ricinoleic acid, N, N-dimethyl-1, 3-propane diamine and epoxy chloropropane; and the specific preparation method comprises the following steps: putting castor oil and a catalyst into a reaction container, introducing nitrogen, dropwise adding N, N-dimethyl-1, 3-propane diamine while stirring at room temperature, heating for reaction after dropwise adding is finished, and treating to obtain ricinoleic acid amide; and putting ricinoleic acid amide into a reaction container, introducing nitrogen, slowly dropwise adding epoxy chloropropane while stirring, controlling the temperature at 48 DEG C, heating to 50 DEG C after dropwise adding is finished, carrying out heat preservation reaction for 1 hour, removing excessive epoxy chloropropane with n-hexane, and carrying out vacuum drying to obtain a finished product. The anti-mud agent can quickly adsorb mud, reduce the mixing amount of polycarboxylate superplasticizers and ensure the performance of concrete, and the preparation method has the advantages of easily available synthesis raw materials, mild reaction conditions, biodegradable product, no influence on the environment, and low synthesis cost and post-treatment cost.