Effects of caffeine on task switching were studied using ERPs in a cued task-switch paradigm. The need for advance preparation was manipulated by varying the number of task-set aspects that required switching. In a double-blind, within-subjects experiment, caffeine reduced shift costs compared to placebo. ERPs revealed a negative deflection developing within the preparatory interval, which was larger for shift than for repeat trials. Caffeine increased this shift-induced difference. Furthermore, shift costs increased as a function of the number of task-set features to be switched, but this pattern was not modulated by caffeine. The results suggest that caffeine improves task-switching performance by increasing general effects on task switching, related to task-nonspecific (rather than task-specific) anticipatory processes. Caffeine's actions may be mediated by dopaminergic changes in the striatum or anterior cingulate cortex.