diff --git a/shake-ats.cabal b/shake-ats.cabal
--- a/shake-ats.cabal
+++ b/shake-ats.cabal
@@ -1,5 +1,5 @@
 name:                shake-ats
-version:             0.3.0.2
+version:             0.3.0.3
 synopsis:            Utilities for building ATS projects with shake
 description:         Various helper functions for building [ATS](http://www.ats-lang.org/) with the [shake](http://shakebuild.com/) library
 homepage:            https://github.com/vmchale/shake-ats#readme
diff --git a/src/Development/Shake/ATS.hs b/src/Development/Shake/ATS.hs
--- a/src/Development/Shake/ATS.hs
+++ b/src/Development/Shake/ATS.hs
@@ -103,10 +103,10 @@
         mapM_ ghcExport ((-<.> "") <$> hs)
 
     out %> \_ -> do
-        sources <- transitiveDeps [sourceFile]
         h <- patsHome v'
         h' <- pkgHome
         let home = h ++ "lib/ats2-postiats-" ++ show v
+        sources <- transitiveDeps (snd <$> atg) [sourceFile]
         need (sources ++ hs)
         copySources v v' sources
         cmd_ ["mkdir", "-p", dropDirectory1 out]
@@ -136,7 +136,7 @@
 
 handleSource :: Version -> Version -> FilePath -> Action ()
 handleSource v v' sourceFile = do
-        sources <- transitiveDeps [sourceFile]
+        sources <- transitiveDeps [] [sourceFile]
         need sources
         copySources v v' sources
 
@@ -163,14 +163,14 @@
 trim :: String -> String
 trim = init . drop 1
 
-transitiveDeps :: [FilePath] -> Action [FilePath]
-transitiveDeps [] = pure []
-transitiveDeps ps = fmap join $ forM ps $ \p -> do
+transitiveDeps :: [FilePath] -> [FilePath] -> Action [FilePath]
+transitiveDeps _ [] = pure []
+transitiveDeps gen ps = fmap join $ forM ps $ \p -> if p `elem` gen then pure mempty else do
     contents <- liftIO $ readFile p
     let ats = fromRight mempty . parseATS . lexATS $ contents
     let dir = takeDirectory p
-    deps <- filterM doesFileExist $ fixDir dir . trim <$> getDependencies ats
-    deps' <- transitiveDeps deps
+    deps <- filterM (\f -> ((f `elem` gen) ||) <$> doesFileExist f) $ fixDir dir . trim <$> getDependencies ats
+    deps' <- transitiveDeps gen deps
     pure $ (p:deps) ++ deps'
 
 -- | This uses @pats-filter@ to prettify the errors.
