New Tool Radar

Local AI

How to Set the Context Size for a llama.cpp Model on the Command Line

Pass -c to llama-cli or llama-server to set the context size in tokens, and check the model's own limit before raising it.

Schematic diagram with three steps: check the model's context limit, pass -c with the token count, and test a long prompt that fits inside it.

The context size is how many tokens of prompt plus reply the model can hold at once. Ask for more than the context and the earliest tokens are dropped; ask for far more than you need and you pay for it in memory. The llama.cpp server README documents -c, --ctx-size N as the size of the prompt context, with a default of 0 — and 0 means the value is loaded from the model itself.

Related guide: How to Run a llama.cpp Model with GPU Offload

Set it when you start the model

llama-cli -m model.gguf -c 8192 -p "Summarise this document: ..."

For the server the same flag applies:

llama-server -m model.gguf -c 8192

Older llama.cpp documentation quoted a default of 512 for the server, with LLaMA models built for 2048 — the current README says the default is 0, loaded from the model, so run llama-cli -h on your installed build to confirm what your version does. Pick a size the model was actually trained for: a model that advertises 8192 tokens of context will not reason well at 32768 just because you asked.

Check it worked

Send a prompt that is long but inside your chosen size, then one that is longer than it. Inside the limit the model should use the whole prompt; beyond it, early content is lost or the run errors. If the process fails to start with an out-of-memory error, the context is too large for your RAM or VRAM — halve it and try again.

Expected result. We checked the llama.cpp server README and the llama-cli man page for the -c/–ctx-size flag and its default. We did not run this software ourselves for this guide, so no output here is a recorded result; steps marked UNTESTED were checked against the sources below, not run.

Limits

A bigger context costs memory roughly in proportion to its size, and it does not make the model smarter — it only lets it see more text at once. The context you set is shared across parallel slots on the server, so raising it while serving several requests multiplies the cost. We did not run llama.cpp, so no memory figure here is measured.

Sources

Checked 2026-11-28.

See all