If llama.cpp is using more memory than expected, repeating old prompt context, or behaving as though it remembers a previous request, you may be wondering how to clear its cache. The right method depends on what you mean by “cache”: llama.cpp can keep prompt data in memory while a process runs, and some command-line configurations can save prompt state to a file. Model downloads, build files, and caches created by other applications are separate. This guide explains how to identify the cache, clear it safely, and avoid deleting files you still need.
What Does “Cache” Mean in llama.cpp?
In llama.cpp, “cache” can refer to several different things. Most often, people mean the key-value (KV) cache used during text generation. The KV cache holds information about tokens the model has already processed. Keeping that information lets llama.cpp continue generating text without recalculating the entire conversation from scratch.
The KV cache is normally held in system RAM or GPU memory while the relevant llama.cpp process is running. It is not usually a permanent folder that you need to find and delete. When you stop the process, its allocated cache memory is released. Starting a new process creates a new context, unless your application restores saved state or reuses a running server.
Other things may also be called a cache:
- Prompt-cache files: Files used by certain command-line configurations to save and reload prompt state.
- Server prompt reuse: An optimization that lets a running llama.cpp server reuse matching prompt tokens or context between requests.
- Model files: Downloaded GGUF files are the model itself, not a temporary prompt cache.
- Application caches: A desktop interface, wrapper, or model manager may store its own files separately from llama.cpp.
- Build files: Compiled binaries and build-system files are related to compiling llama.cpp, not to generated prompt history.
Identifying which one you mean is important. Clearing a prompt cache will not remove a downloaded model, and deleting a model file will not clear the KV cache held by a running server.
How to Clear the llama.cpp Cache in Memory
To clear the ordinary KV cache, stop the llama.cpp process that is holding it. This is usually the simplest and safest method. If you launched a command-line generation, end that run. If you started a server, stop the server and start it again when you are ready to use it.
-
In a terminal: Press
Ctrl+Cin the terminal running llama.cpp. If it does not stop, close the terminal or use your operating system’s process-management tools. - In a service manager: Stop the service or container that runs llama.cpp, then start it again if needed.
- In a desktop app: Use the app’s stop or quit command. Closing a browser tab may not stop a background server.
After the process exits, its memory allocation should be released by the operating system. On a GPU, memory may take a moment to appear available again, particularly if another process is using the device. Check that the llama.cpp process has actually stopped before concluding that the cache was not cleared.
If you use llama-server, simply sending another request may not clear the cache. A server is designed to stay running and can maintain context or reuse prompt data across requests, depending on its configuration and version. Restarting the server gives you a fresh process and is a reliable way to discard its in-memory state.
How to Delete a Saved Prompt Cache File
Some llama.cpp command-line options and versions support saving prompt state to a file. If you configured a prompt-cache file, deleting that specific file clears the saved state. First, check the command or script you use to launch llama.cpp and look for an option such as --prompt-cache. The option is typically followed by a file path. The exact available options can vary between versions, so confirm them with the help output for your installed executable.
For example, a launch command might specify a cache path like ./prompt-cache.bin. If that is the file you want to remove, stop the program first, then delete that file. On macOS or Linux, you can use a command such as:
rm ./prompt-cache.bin
On Windows Command Prompt, the equivalent is:
del prompt-cache.bin
In PowerShell, you can use:
Remove-Item .\prompt-cache.bin
Replace the example path with the actual path from your configuration. Be careful with deletion commands: a typo in a path can remove the wrong file. If you are unsure, open the containing folder in your file manager and move the cache file to the recycle bin or trash instead of permanently deleting it.
Deleting a saved prompt cache does not normally delete your model, configuration, or conversation records stored by a separate application. It only removes the file you selected. If you want llama.cpp to stop writing a prompt cache in future runs, remove or change the relevant cache option in your launch command or script. Check the help text for your version rather than assuming an option behaves identically across releases.
Clearing Prompt Reuse in llama-server
Some server configurations can reuse prompt processing to make repeated or similar requests faster. This is an optimization, not necessarily a permanent disk cache. If prompt reuse is enabled, the server may retain useful context while it remains running. Restarting the server clears that process’s in-memory state.
To review whether prompt caching or reuse is enabled, inspect the command used to start llama-server, its configuration file, or the startup logs. Then check the options supported by your installed version by running the executable’s help command. For example, use the appropriate form of llama-server --help for your installation. Flags and behavior can change between llama.cpp releases, so the local help output is more dependable than instructions written for a different version.
If you do not want prompt reuse, disable the related option in your server configuration, if your version provides one. Do not assume that every option containing the word “cache” controls the same feature. Some settings affect KV-cache allocation, some affect prompt reuse, and others control how requests are scheduled. Changing a cache-related setting can affect speed, context handling, or memory use.
How to Check Whether the Cache Was Cleared
After stopping a process or deleting a saved cache file, check the specific symptom you wanted to fix. If memory use was the concern, inspect system or GPU memory after the llama.cpp process exits. If old context was the concern, start a fresh process or session and send a new request without restoring previous state. If a prompt-cache file was the concern, confirm that the configured file is no longer present.
Memory readings do not always drop to exactly zero. The operating system may use freed RAM for its own file cache, and GPU drivers or other applications may still reserve memory. This does not necessarily mean llama.cpp kept its KV cache. Look at the process list or resource monitor to see whether the relevant llama.cpp process is still active.
Also check whether a wrapper automatically restarts the server. Some interfaces manage llama.cpp in the background, so quitting a chat window may leave the model process running. In that case, stop the server through the wrapper, service manager, or container controls instead of relying on the window closing.
What You Should Not Delete
Do not delete files simply because they are large or located near llama.cpp. GGUF files are model weights, and removing one will make that model unavailable until you restore or download it again. Likewise, a folder used by a model manager may contain downloaded models, settings, or application data rather than a disposable llama.cpp cache.
Build directories and compiled binaries are not prompt caches either. Removing them may require you to rebuild llama.cpp, but it will not clear the memory used by a server that is still running. If you are trying to free disk space, identify the files first and make sure they are not models or configuration files you need.
Before deleting anything, search your launch script for the exact cache path, check the application’s documentation, and make a backup if the file’s purpose is unclear. This is especially important on shared systems or when a script uses a broad cleanup command.
Common Problems When Clearing the Cache
- Memory stays high: The server may still be running, another process may be using memory, or the operating system may be retaining memory for other purposes. Check active processes before deleting files.
- The model remembers an earlier conversation: The application may be resending chat history, restoring a session, or keeping a server process alive. Start a new session and check the wrapper’s history settings.
- Deleting a file changes nothing: You may have deleted a model or unrelated file rather than the configured prompt-cache file. Verify the path in the launch command.
- The cache comes back: A startup script may recreate the file or re-enable prompt caching. Update the script or application settings if you want to prevent that.
- The command-line option is unavailable: Your llama.cpp build may use different options from the guide you followed. Check the executable’s own help output or update your instructions for the installed version.
Frequently Asked Questions
Does restarting llama.cpp clear its cache? Restarting the process clears its in-memory KV cache. A saved prompt-cache file can remain on disk and may be loaded again if the launch configuration tells llama.cpp to use it.
Where is the llama.cpp cache folder? There is not one universal cache folder for all llama.cpp use. In-memory cache lives with the running process, while a saved prompt cache uses the path specified in the command or configuration. Other applications may choose their own storage locations.
Will clearing the cache delete my model? Not if you stop the process or delete only the configured prompt-cache file. Model weights are separate files, usually in GGUF format. Always verify a file’s purpose before removing it.
Do I need to clear the cache after every prompt? Usually not. The KV cache helps generation work efficiently, and a server may use context reuse to improve performance. Clear it when you need a fresh process, want to release memory, or are troubleshooting unexpected context—not as a routine requirement.
Conclusion
To clear the llama.cpp cache, first identify whether you mean in-memory KV data, a saved prompt-cache file, or storage managed by another application. Stop or restart the llama.cpp process to release its ordinary memory cache. If you configured a disk-based prompt cache, locate its exact path, stop the program, and remove only that file. Check your installed version’s help output, avoid deleting model files, and verify that no background server is still running. These steps clear the relevant cache without putting your models or configuration at risk.
Disclaimer: Articles are written by Humans, AI or Both. Verify Important information.