# REPL Save/restore

**URL:** <https://discourse.julialang.org/t/repl-save-restore/130774>\
**Category:** General Usage\
**Tags:** repl, replicability\
**Created:** [July 16, 2025, 12:11pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774 "2025-07-16T12:11:46Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![benc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benc/32/46974_2.png) [@benc](https://discourse.julialang.org/u/benc)\
**Post date:** [July 16, 2025, 12:11pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774/1 "2025-07-16T12:11:46Z")

</div>

When using the REPL, is it possible to save the state (memory) of the session, and restore it?  
(State being defined as all datastructures and functions loaded)

When prototyping I need to load large-ish datasets, with intermediate results, I need to interrupt at times my work to switch to other tasks, saving the state could allow (similar to R) to restore a session as-is and resume.

I try to keep my current workflows 100% reproducible, so in principle re-executing the script would allow me the same behavior (minus load/processing time), and Julia’s precompilation (with Revise, PreCompile, ..) has become so fast that package related latency is (for me) negligible.  
However, the compute cost can be non trivial, when I want to switch between projects, having save/restore REPL state would be very powerful.  
I realize I can serialize the datastructures, and resume, but I was wondering if there’s any interest in REPL save/restore behavior.  
Or, if there are other ways to achieve the same results, e.g. serialize recursively and reload on start.

Similar thread [Save/load REPL state - #8 by mkitti](https://discourse.julialang.org/t/save-load-repl-state/102433/8)

Thanks!

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [July 16, 2025, 1:21pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774/2 "2025-07-16T13:21:10Z")

</div>

AFAIK this not possible or better, available up to now.  
Coming from R and being used to this feature I want to say, that even in R, it was nearly always better not to rely on it, and, over time, I am avoiding it completely and I am typically annoyed from the question if the session should be saved.  
Not relying on it means, to code in that way, so that restarting from a intermediate state is explicitly coded by me. In Julia this is, in my opinion, much easier than in R.  
So for me, I am not interested in such a feature.

---

<div class="post-metadata">

**Author:** ![xgdgsc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xgdgsc/32/608_2.png) [@xgdgsc](https://discourse.julialang.org/u/xgdgsc)\
**Post date:** [July 16, 2025, 1:44pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774/3 "2025-07-16T13:44:02Z")

</div>

The default setting isn’ t ideal for this. You should set

```julia
 "julia.persistentSession.enabled": true,
    "julia.persistentSession.tmuxSessionName": "julia_vscode_${workspaceFolderBasename}",

```

to use project REPLs.

If you use a server and set this. The need to restore should be minimal.

And my branch of the vscode extension [Looking for opinion on dot methods completion implementation](https://discourse.julialang.org/t/looking-for-opinion-on-dot-methods-completion-implementation/97153) contains saving and restore of inline results on switching devices that connect to the remote server.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [July 16, 2025, 2:02pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774/4 "2025-07-16T14:02:39Z")

</div>

You can do

```julia
using JLD2
@save "foo.h5"

```

to save all of the variables in the interactive scope to a file `foo.h5` and

```julia
using JLD2
# ...load other packages and struct definitions first...
@load "foo.h5"

```

to restore them in another session. (It doesn’t save certain things like functions and `struct` definitions, but those you can easily re-load.)

---

<div class="post-metadata">

**Author:** ![Benny](https://avatars.discourse-cdn.com/v4/letter/b/49beb7/32.png) [@Benny](https://discourse.julialang.org/u/Benny)\
**Post date:** [July 16, 2025, 2:11pm UTC](https://discourse.julialang.org/t/repl-save-restore/130774/5 "2025-07-16T14:11:07Z")

</div>

Some things just aren’t feasibly serialized and deserialized. Precompilation itself has limitations e.g. memory address-based hashes, and active code is a nightmare. Even if we make a reasonable limitation to only let the `save` function run in the global scope so we’re not trying to save in the middle of a function call, we can still have queued or running code in other tasks. Sysimages and package images from precompilation are the result of determining the limits of serializing Julia, and we wouldn’t want to do all that just to save data. After all, why shouldn’t we load that same data in a different environment with different packages and functions?

---

<div class="post-metadata">

**Author:** ![benc](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/benc/32/46974_2.png) [@benc](https://discourse.julialang.org/u/benc)\
**Post date:** [July 17, 2025, 8:44am UTC](https://discourse.julialang.org/t/repl-save-restore/130774/6 "2025-07-17T08:44:17Z")

</div>

Thanks everyone for the replies/feedback, with the solutions from @stevengj and @xgdgsc I can achieve my use case of switching sessions and restoring the compute results without recomputing.  
I realize that full save/restore is both non-trivial as @Benny notes, and can lead ot non-ideal workflows as @oheil note. and reflecting on what I really needed, made me realize the above 2 solutions achieve what I really needed.  
Thanks!
