diff --git a/CHANGELOG b/CHANGELOG
--- a/CHANGELOG
+++ b/CHANGELOG
@@ -1,3 +1,6 @@
+v0.9.1.0
+
+  * #109, Use the correct DynFlags when parsing refactoring templates
 
 v0.9.0.0
 
diff --git a/apply-refact.cabal b/apply-refact.cabal
--- a/apply-refact.cabal
+++ b/apply-refact.cabal
@@ -1,7 +1,7 @@
 cabal-version:       2.4
 
 name:                apply-refact
-version:             0.9.0.0
+version:             0.9.1.0
 synopsis:            Perform refactorings specified by the refact library.
 description:         Perform refactorings specified by the refact library. It is primarily used with HLint's --refactor flag.
 license:             BSD-3-Clause
diff --git a/src/Refact/Internal.hs b/src/Refact/Internal.hs
--- a/src/Refact/Internal.hs
+++ b/src/Refact/Internal.hs
@@ -35,6 +35,7 @@
 import Data.Functor.Identity (Identity(..))
 import Data.Generics (everywhereM, extM, listify, mkM, mkQ, something)
 import Data.Generics.Uniplate.Data (transformBi, transformBiM, universeBi)
+import Data.IORef.Extra
 import qualified Data.Map as Map
 import Data.Maybe (catMaybes, fromMaybe, listToMaybe, mapMaybe)
 import Data.List.Extra
@@ -59,6 +60,7 @@
 import StringBuffer (stringToStringBuffer)
 import System.IO.Error (mkIOError)
 import System.IO.Extra
+import System.IO.Unsafe (unsafePerformIO)
 
 import Debug.Trace
 
@@ -606,8 +608,9 @@
   let replExprLocation = pos
       uniqueName = "template" ++ show seed
 
-  (relat, template) <- withDynFlags (\d -> parser d uniqueName orig) >>=
-    either (onError "replaceWorked") pure
+  (relat, template) <- do
+    flags <- maybe (withDynFlags id) pure =<< readIORef dynFlagsRef
+    either (onError "replaceWorker") pure $ parser flags uniqueName orig
 
   (newExpr, (newAnns, newKeyMap)) <-
     runStateT
@@ -773,11 +776,10 @@
     -- TODO: report error properly.
     Left err -> pure . Left $ mkErr initFlags (UnhelpfulSpan mempty) err
     Right flags -> do
-      _ <- GHC.setSessionDynFlags flags
+      liftIO $ writeIORef' dynFlagsRef (Just flags)
       res <- parseModuleApiAnnsWithCppInternal defaultCppOptions flags fp
       pure $ postParseTransform res rigidLayout
 
-
 -- | Parse the input into (enabled extensions, disabled extensions, invalid input).
 -- Implied extensions are automatically added. For example, @FunctionalDependencies@
 -- implies @MultiParamTypeClasses@, and @RebindableSyntax@ implies @NoImplicitPrelude@.
@@ -873,3 +875,9 @@
     , (StandaloneKindSignatures, False, CUSKs)
 #endif
   ]
+
+-- TODO: This is added to avoid a breaking change. We should remove it and
+-- directly pass the `DynFlags` as arguments, before the 0.10 release.
+dynFlagsRef :: IORef (Maybe DynFlags)
+dynFlagsRef = unsafePerformIO $ newIORef Nothing
+{-# NOINLINE dynFlagsRef #-}
