How to Increase Ollama Context Length (num_ctx)

Your model may be using a smaller context window than you expect, because Ollama picks the default from your VRAM, and the fix is to set a larger num_ctx that your VRAM can still hold. Here is how to increase Ollama context length, pick the right method for how Ollama starts on your machine, and prove it worked with ollama ps.

The order matters: read the current value, change it, read it again. Skipping the last read means you will not see whether the model still runs fully on the GPU.

Key takeaways

  • Run ollama ps before and after every change and compare the CONTEXT and PROCESSOR columns.
  • The default depends on VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB, 256k at 48 GiB or more.
  • On the macOS app use launchctl setenv, and on a Linux systemd service use systemctl edit ollama.service. On those setups, set the variable with the platform method instead.
  • For agents and coding tools the docs suggest at least 64000 tokens, but only if the model stays at 100% GPU.

Ollama picks the default context from your VRAM, so raise num_ctx only as far as memory allows

Context length is the maximum number of tokens the model has access to in memory. Ollama chooses the default from the VRAM it finds, and a larger value needs more memory, so the setting is a trade against what your GPU holds.

The Ollama context length docs (opens in a new tab) list these defaults:

VRAMDefault context
Under 24 GiB4k
24 to 48 GiB32k
48 GiB or more256k

Many tutorials repeat a flat 4096. The Ollama FAQ (opens in a new tab) still says "By default, Ollama uses a context window size of 4096 tokens", while the context-length page ties the default to VRAM. Trust the context-length page, and trust ollama ps over both. Cloud models are set to their maximum context length by default, so this article applies to local models.

Run ollama ps first to read the CONTEXT and PROCESSOR columns

Load the model, run ollama ps, and write down two things: the CONTEXT value and whether PROCESSOR says 100% GPU. This is your baseline, and the last step compares against it.

Bash
ollama run llama3.2

In a second terminal:

Bash
ollama ps

The context-length docs show this sample output:

Text
NAME            ID            SIZE    PROCESSOR   CONTEXT   UNTIL
gemma4:latest   c6eb396dbd59  9.6 GB  100% GPU    131072    2 minutes from now

The FAQ explains the PROCESSOR column: 100% GPU means fully on the GPU, 100% CPU means fully in system memory, and a split such as 48%/52% CPU/GPU means the model sits partly in both. The FAQ’s sample output has no CONTEXT column, while the context-length page’s sample does. On macOS and Windows use "Restart to update" from the menubar or taskbar item, and on Linux re-run the install script.

Choose a target your memory can hold, and treat 64000 as a ceiling to test

The docs say tasks that need large context, such as web search, agents and coding tools, should be set to at least 64000 tokens. That advice only holds if the model still fits in VRAM, so pick a target from your tier and verify it.

The sources give no GB-per-token figure. The memory cost depends on the model and the context length you choose, so any number you see without a source is a guess. Measure it instead: raise the value, then watch SIZE and PROCESSOR in ollama ps.

My rule: if you have under 24 GiB and the model already fills most of it, do not jump to 64000. Step up in stages, for example from 4k to 8192, then higher, and stop the moment PROCESSOR shows a CPU share. A model split across CPU and GPU is slow enough that a smaller window is usually the better trade. The docs advise avoiding CPU offload for the same reason.

Match the method to how Ollama starts: app slider, launchctl, systemd or ollama serve

The right method is the one that controls the process that actually loads your model. For the desktop app that is the slider, and for a service it is the service’s environment.

Start with the simplest route:

  1. Ollama app: open the app settings and move the context length slider to the value you want, as described in the context length docs (opens in a new tab).
  2. Foreground server: if you start Ollama yourself, set the variable in front of the command.
Bash
OLLAMA_CONTEXT_LENGTH=64000 ollama serve
  1. macOS app: the FAQ (opens in a new tab) says environment variables must be set with launchctl. Run the first command, then quit and restart the Ollama app.
Bash
launchctl setenv OLLAMA_CONTEXT_LENGTH "64000"
  1. Linux systemd service: run the edit command, which opens an editor.
Bash
systemctl edit ollama.service

Add these lines under [Service], then save and exit:

INI
[Service]
Environment="OLLAMA_CONTEXT_LENGTH=64000"

Reload systemd and restart Ollama:

Bash
systemctl daemon-reload
systemctl restart ollama
  1. Windows: Ollama inherits your user and system environment variables. Quit Ollama from the taskbar, edit the variables for your account, click OK, and start Ollama again from the Start menu.

Warning: If Ollama runs as a macOS app or a systemd service, the FAQ says to set the variable with launchctl or systemctl, so use the platform steps above. Use the platform steps above.

Set num_ctx per session, per model or per request when one global value is wrong

A server-wide value is a blunt tool. If one model needs 64000 and the rest should stay small, set num_ctx closer to the model or the call. Each of these applies at a different level, so check which one you are changing.

MethodApplies toLasts
App slider, OLLAMACONTEXTLENGTHServer defaultUntil you change it
/set parameter num_ctxCurrent ollama run sessionUntil the session ends
Modelfile PARAMETER num_ctxOne named modelSaved in that model
API options.num_ctxOne requestThat request only

For a session, the FAQ gives this command inside ollama run:

Text
/set parameter num_ctx 32768

To persist a value for one model, write a Modelfile. Ollama’s GitHub repository (opens in a new tab) links the Modelfile reference for the full syntax.

Text
FROM llama3.2
PARAMETER num_ctx 32768
Bash
ollama create llama3.2-32k -f Modelfile
ollama run llama3.2-32k

For one API call, pass the value in options, as shown in the FAQ:

Bash
curl http://localhost:11434/api/generate -d '{
  "model": "llama3.2",
  "prompt": "Why is the sky blue?",
  "options": {
    "num_ctx": 32768
  }
}'

The docs I read do not state which setting wins when the slider, the variable, a Modelfile and a request disagree. I did not test precedence for this article. Set one method at a time and check the result with ollama ps rather than assuming an order.

Run ollama ps again and confirm the new value and 100% GPU

The change worked only if CONTEXT shows your new number and PROCESSOR still says 100% GPU. Anything else needs a smaller value or a different method.

Follow this check:

  1. Stop the loaded model so the next load picks up the new setting.
Bash
ollama stop llama3.2
  1. Send a prompt, then run ollama ps.
  2. Compare CONTEXT with the baseline you wrote down.
  3. If CONTEXT is unchanged, the setting did not reach the process. Recheck that you used the method that matches how Ollama starts.
  4. If PROCESSOR shows a CPU share, lower num_ctx and repeat.

Example: If the model ran at 100% GPU at the default and ollama ps shows a CPU/GPU split after you raise num_ctx, halve the value and check again. The largest value that keeps it at 100% GPU is your ceiling for that model on that card.

The docs say to use the maximum context length a model supports for best performance while avoiding CPU offload. In practice, your VRAM sets the limit before the model does.

Next step: run ollama ps on the model you use most today, write down CONTEXT and PROCESSOR, then read the Ollama context length docs (opens in a new tab) and the Modelfile reference linked from the Ollama repository (opens in a new tab) before you save a value into a custom model. Source check: the app slider, OLLAMACONTEXTLENGTH, launchctl, systemctl, /set parameter and API examples come from the Ollama docs pages linked here. The Modelfile and ollama create steps do not. I did not run them on a specific Ollama build for this article, so confirm each with ollama ps on your machine.

Frequently Asked Questions

How do I change Ollama context length?

Pick the method that matches how Ollama starts. Use the app slider in settings, set OLLAMACONTEXTLENGTH for the server, run /set parameter numctx in a session, add PARAMETER numctx to a Modelfile, or pass options.num_ctx in an API call. Then run ollama ps to confirm the CONTEXT value.

How do I change Ollama context size on macOS or Linux?

On the macOS app, run launchctl setenv OLLAMACONTEXTLENGTH "64000" and restart the app. On a Linux systemd service, run systemctl edit ollama.service, add Environment="OLLAMACONTEXTLENGTH=64000" under [Service], then run systemctl daemon-reload and systemctl restart ollama. Both steps come from the Ollama FAQ.

How do I change the context length of one Ollama model only?

Write a Modelfile with FROM and PARAMETER numctx, then run ollama create with a new model name. That model keeps the value and other models keep the server default. For a single request, use options.numctx in the API call instead.

What is the Ollama context window default?

The context-length docs tie it to VRAM: 4k under 24 GiB, 32k from 24 to 48 GiB, and 256k at 48 GiB or more. The FAQ still says 4096 tokens, so read your real value from the CONTEXT column of ollama ps.

Why does a bigger context slow my model down?

A larger context needs more memory. If the model no longer fits in VRAM, part of it loads into system memory, and ollama ps shows a CPU/GPU split under PROCESSOR. Lower num_ctx until it reads 100% GPU again.