Ollama context length controls how many tokens a loaded model can keep available for a request. Larger contexts help coding, agents, and long-document work, but they also raise memory requirements.
Current Ollama defaults context length based on available VRAM, and the server can be overridden with OLLAMA_CONTEXT_LENGTH. Per-model and per-request settings can still limit or expand behavior for a specific workload.
Check ollama ps after loading a model because it shows the context actually allocated to that running model. The value that matters is the one the server accepted, not only the environment variable that was set.
Related: How to start the Ollama server
Related: How to list running Ollama models
Related: How to set Ollama request parallelism
$ printf '%s\n' 64000 64000
Long contexts can force CPU offload or model-load failure on small GPUs.
$ OLLAMA_CONTEXT_LENGTH=64000 ollama serve
[Service] Environment="OLLAMA_CONTEXT_LENGTH=64000"
$ sudo systemctl daemon-reload $ sudo systemctl restart ollama
Related: How to manage the Ollama service
$ ollama ps NAME ID SIZE PROCESSOR CONTEXT UNTIL gpt-oss:20b 17052f91a42e 12 GB 100% GPU 64000 5 minutes from now