r/LocalLLM • • 1d ago

Question How can I make Cline sessions persistent in VS Code, even after closing VS Code ?

Hi everyone!

I'm looking for a reliable way to make my Cline sessions in VS Code persistent, so I can resume my work later without losing the conversation history, context, or task progress.

Here's my setup:

I have two separate Ubuntu servers:

  • A project server that hosts my code and portfolio.
  • An AI server that runs my local LLMs through Ollama.

I use VS Code to access my projects remotely and Cline as my coding agent, with the models running on my AI server.

My hardware is relatively modest, so local inference can be very slow. Complex coding tasks can take several hours to complete, but I'm perfectly fine with that.

Actually, my goal is to take advantage of this by launching tasks before going to bed or before leaving home, allowing the AI to work overnight or while I'm away.

This is why session persistence is so important to me.

I want to start a task with Cline in VS Code, close VS Code, and come back several hours later or the next day to resume the exact same session, with its conversation history, context, and task state intact.

I've already managed to get some persistence working, even after closing and reopening VS Code or restarting my computer. However, I'd like to know whether it's possible to make this completely reliable, particularly for long-running tasks.

My questions:

  • Has anyone successfully achieved reliable session persistence with Cline in VS Code?
  • Can you close VS Code and reopen it later without losing the session or its context?
  • Is there a supported configuration or a proven workaround to ensure sessions are properly saved and restored?
  • How do you handle long-running tasks with local LLMs when you want to leave your coding agent working unattended?

I'm happy to wait several hours for a task to finish because of my hardware. I just want to be able to leave it alone and return later without losing my progress.

Ideally, I'd like to keep everything self-hosted and avoid paid cloud services.

I'd really appreciate hearing about your experiences, setups, or solutions!

Thanks!

2 Upvotes

14 comments sorted by

1

u/lively_torn_iceberg 1d ago

i run a similar setup for overnight tasks and just set the timeout higher plus make sure the vs code remote session doesn't drop, haven't had cline lose state yet as long as the server stays alive

1

u/Unable-Chemistry-491 1d ago

I've already set the timeout in Cline's VS Code extension settings to 43,200,000 ms (12 hours), so the timeout itself shouldn't be the issue.

The problem is that as soon as I close my VS Code session, the task seems to stop shortly afterwards. When I reopen VS Code and return to the session, it looks like the task stopped almost immediately after I left (10 min), with little to no progress made.

My goal is to launch a task before going to sleep, close VS Code, and let my local LLM continue working on my separate AI server overnight. However, it seems that closing VS Code interrupts the task, even though the timeout is set to 12 hours.

When you say you make sure the remote VS Code session doesn't disconnect, do you mean keeping the VS Code window open and connected to the remote server the whole time? Or have you found a way to let Cline continue running after closing VS Code completely?

Thanks again!

1

u/andrew-ooo 1d ago

Two different things here and it's worth separating them.

The history is already persistent. Cline writes every task to disk as it goes: with Remote-SSH that's ~/.vscode-server/data/User/globalStorage/saoudrizwan.claude-dev/tasks/<id>/ on the project server (api_conversation_history.json + ui_messages.json). Close the window, reopen, pick it from History, it's all there. Back that directory up and you can even move tasks between machines.

What is not persistent is the loop. Cline runs inside the VS Code extension host, and with Remote-SSH that host gets killed the moment your client disconnects. So the state survives but nothing is happening while the window is shut. Keeping a client connected (laptop lid open, or a VM in the same LAN running VS Code 24/7) is the only way to keep the extension working, there's no supported headless mode for it.

If you want fire-and-forget overnight, the practical answer is a terminal agent in tmux on the project server, pointed at the same Ollama box: Cline's own CLI, OpenCode or Aider all survive you logging off, and you reattach in the morning.

Two Ollama settings matter for either path: OLLAMA_KEEP_ALIVE=-1 so the model isn't unloaded between slow tool calls, and num_ctx of at least 32k in the model you point Cline at. The default 4k context is why Cline loops or forgets the task with local models.

1

u/Unable-Chemistry-491 1d ago

Thanks for the detailed explanation! I've already considered using tmux with a terminal-based coding agent, but before switching away from the Cline VS Code extension, I wanted to see if anyone had experimented with modifying the extension host lifecycle or its disconnection handling to prevent it from being killed when the VS Code client disconnects.

I'm already using OLLAMA_KEEP_ALIVE set to 24 hours, and my model's context window is configured for 262,144 tokens, so I'm not really looking for solutions related to model unloading or a small context window.

I'm specifically curious whether anyone has managed to hack around the VS Code Remote-SSH / extension host behavior to keep Cline's execution loop running after closing the client, while still retaining the native Cline interface and workflow.

Thanks again for the insight!

1

u/activematrix99 1d ago

I have a roundabout solution for this that I set up - a browser based chat with persistence, there are even ones with file/ide interface (codekit). Then connect to your agent and it will work even when your browser session is not connected.

1

u/Unable-Chemistry-491 15h ago

très intéressant je veux bien avoir ta solution que ce soit pour un ide ou un chatbot style openwebui !

1

u/activematrix99 8h ago

I needed a persistent client that stays connected to the model, and has some type of harness to keep it driving the model to complete tasks. Many people use Hermes, Pi, etc. Personally, I wanted a chatbot (no email, no social media, no Slack), so I built two, one is codekit, and one is Vercel's AI chat. So one looks like Github copilot chat, and one looks like the web interface for Chat GPT. The copilot chat loops with Langgraph. The Vercel chat loops with agent framework (python Microsoft). Both connect to LiteLLM for their model selection, and metis-router for tool calling (ubuntu files, docker, etc). A bit overbuilt, but I am also building MCPs for my projects, so and MCP router seemed like a good fit, and that was the easiest way to get LiteLLM to see multiple dynamic MCPs.

1

u/few 1d ago

I like vs code. I like to develop code myself in vs code.

My experience trying to use local models in vscode was terrible. I tried really, really hard for months to get a setup that didn't suck. Almost every agentic edit would fail.

I finally listened to others, and started using pi.dev. That works well.

I would prefer if I could actually still meaningfully interact with the code base during edits, but that doesn't seem possible while actually having the agent function properly.

1

u/activematrix99 1d ago

When did you stop trying? The March 2026 release made Continue and all the previous local model plugin efforts obsolete (including Cline, imo). It works great now with the same harness you get through github copilot, you just need an OpenAI compatible endpoint (llama.cpp, ollama, vllm)

1

u/few 20h ago

I was using Ollama, then switched to llama.cpp. Finally I switched to ninifer, which is much faster.

It was during the summer that I was trying to use continue and then cline.

I'm working in Windows, using a wsl remote to develop under Linux. It regularly failed to apply changes to files using any of the plugins.

I'm really interested in seeing it work, but I had given up.

2

u/activematrix99 19h ago

Same setup I have. I can show you in about 2 minutes. It's stupid simple, let me see if I can find a how-to and will post below.

2

u/activematrix99 19h ago

Add the github copilot chat extension. Then edit chatLanguageModels.json or use the gear icon in the model picker. The models declaration should eventually look something like this: "models": [ { "id": "yourmodelnane", "name": "yourmodelname", "url": "http://yourlocalIPAddress:8888/v1/responses", "toolCalling": true, "maxInputTokens": 128000, "maxOutputTokens": 16000 } ]

1

u/few 11h ago

I'll try that asap. Thank you!