           (reify
             clojure.lang.IDeref
             (deref [_]
-              (some-> @state-ref :worker :state-ref deref :build-state :compiler-env))))))))
-
-(defn set-worker [{:keys [session] :as msg}]
-  ;; re-create this for every message so we know exactly which msg started a REPL
-  (swap! session assoc #'api/*nrepl-init* #(repl-init msg %1 %2))
-
-  ;; can only store vars in a session, always put one in though
-  (when-not (contains? @session #'repl-state-ref)
-    (swap! session assoc #'repl-state-ref (atom {})))
-
-  (let [state-ref (get @session #'repl-state-ref)
-        session-id (-> session meta :id)
-        {:keys [build-id worker]} (get @state-ref session-id)]
+              (some-> worker :state-ref deref :build-state :compiler-env))))))))
+
+(defn set-worker [{:keys [op session] :as msg}]
+  ;; re-create this for every eval so we know exactly which msg started a REPL
+  ;; only eval messages can "upgrade" a REPL
+  (when (= "eval" op)
+    (swap! session assoc #'api/*nrepl-init* #(repl-init msg %1 %2)))
+
+  ;; DO NOT PUT ATOM'S INTO THE SESSION!
+  ;; clone will result in two session using the same atom
+  ;; so any change to the atom will affect all session clones
+  (when-not (contains? @session #'*repl-state*)
+    (swap! session assoc #'*repl-state* nil))
+
+  (let [{:keys [build-id worker] :as repl-state} (get @session #'*repl-state*)]
     (if-not build-id
       msg
-      (assoc msg ::state-ref state-ref ::worker worker ::build-id build-id))))
+      (assoc msg ::repl-state repl-state ::worker worker ::build-id build-id))))
 
 (defn do-cljs-load-file [{::keys [worker] :keys [file file-path] :as msg}]
   (when-some [result (worker/load-file worker {:file-path file-path :source file})]

            (recur)

            (= :repl/quit form)
            (do (do-repl-quit state-ref session)
                (send msg {:value ":repl/quit"
                           :printed-value 1
                           :ns (-> *ns* ns-name str)}))

            (= :cljs/quit form)
            (do (do-repl-quit state-ref session)
                (send msg {:value ":cljs/quit"
                           :printed-value 1
                           :ns (-> *ns* ns-name str)}))

            (when-some [{:keys [type text] :as msg} (<! watch-chan)]
              (case type
                :repl/out
                (send @last-msg-ref {:out (str text "\n")})

                :repl/err
                (send @last-msg-ref {:err (str text "\n")})

                ;; not interested in any other message for now
                :ignored)
