Minimising the presence and size of magnetic islands in the core of stellarators is necessary to retain the advantageous confinement properties of nested flux surfaces. Therefore, efficient optimisation schemes to reduce island size in stellarator configurations are desirable. However, a configuration with small islands may not be good enough: it may be sensitive to the exact positions of the coils, which also tend to have complex shapes that make them more difficult to manufacture precisely. Therefore, it is also crucial to reliably and efficiently quantify the sensitivity of island size with respect to coils. For example, in NCSX tight coil tolerances — also related to island sensitivity — inflated the construction cost, which was one of the reasons that led to the experiment being cancelled.An adjoint approach to calculating the gradient of two quantities related to magnetic island size is presented. The first quantity is the full radial width of an island calculated using a method developed by Cary and Hanson, which relies on the island size being small compared to the system size. The island width calculation is verified using an analytical magnetic field configuration. The second quantity, known as Greene’s residue, is simpler to calculate and can be calculated for any periodic field line; for an island centre (O point) the residue is strongly correlated with the island width. Convergence tests for the gradients of island width and residue are presented. The result of a gradient-based optimisation of residues in a magnetic configuration produced by a pair of helical coils are presented. To our knowledge this is the first optimisation for good flux surfaces using analytic derivatives. Furthermore, the shape gradient— a measure of sensitivity — of the island width with respect to coils is calculated and numerically verified for a magnetic island in the NCSX configuration. The applications and extensions of this work in the area of stellarator optimisation and design are discussed.