# How to Set the Context Length for Ollama with OpenClaude

> Learn how to set the context length for Ollama with OpenClaude by configuring environment variables or Ollama yaml. Meet OpenClaude's token requirements easily.

- Repository: [Gitlawb/openclaude](https://github.com/Gitlawb/openclaude)
- Tags: how-to-guide
- Published: 2026-09-06

---

**Set the `OLLAMA_MAX_CONTEXT` environment variable to `32768` or add `max_context: 32768` to `~/.ollama/ollama.yaml`, then restart the Ollama service to meet OpenClaude's default token requirement.**

OpenClaude assumes a **32,768-token context window** when routing chat requests to local Ollama models. If your Ollama instance maintains the default 2,048-token limit, OpenClaude displays a warning because long conversations may be truncated. Configuring Ollama to use the expected context length eliminates this warning and ensures full message history retention.

## Why OpenClaude Requires 32,768 Tokens

According to the source code in [`src/utils/statusNoticeLocalModel.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/statusNoticeLocalModel.ts), OpenClaude automatically checks the active profile provider and generates a warning when it detects Ollama:

```typescript
if (activeProfile?.provider?.id === 'ollama') {
  const ollamaContextContributor = await getOllamaContextInfo();
  if (ollamaContextContributor) {
    warnings.push({
      id: 'ollama_context_length',
      title: 'Ollama Context Length',
      description:
        'OpenClaude requests 32768 tokens for Ollama chats. If `ollama ps` keeps showing a smaller CONTEXT after a new request, restart Ollama and verify with `ollama ps`.',
      ...ollamaContextContributor,
    });
  }
}

```

This warning appears because OpenClaude sends requests assuming a 32,768-token buffer. If Ollama's actual context is smaller, the model discards older messages, leading to incomplete context awareness.

## Checking Your Current Ollama Context Size

Before adjusting settings, verify your current context size using the `ollama ps` command. The `getOllamaContextInfo` function in [`src/utils/ollamaContext.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/ollamaContext.ts) parses this output to extract the `CONTEXT` value:

```typescript
export const getOllamaContextInfo = async (): Promise<LocalModelWarningContributor | null> => {
  try {
    const { stdout } = await execFilePromise('ollama', ['ps']);
    const match = stdout.match(/\bCONTEXT\b\s+(\d+)/i);
    if (match) {
      const context = Number(match[1]);
      return {
        description: `Current Ollama context: ${context} tokens.`,
        details: { context },
      };
    }
  } catch (e) {
    // If ollama is not installed or command fails, silently ignore.
  }
  return null;
};

```

Run the following command to see your current allocation:

```bash
ollama ps

```

Look for the `CONTEXT` column. If it shows a value lower than **32768**, you need to increase the limit.

## Configuring the Ollama Context Length

You can set the maximum context length via environment variables or the Ollama configuration file. Both methods require restarting the Ollama service to take effect.

### Method 1: Environment Variable

Set `OLLAMA_MAX_CONTEXT` before starting the Ollama server:

```bash
export OLLAMA_MAX_CONTEXT=32768
ollama serve &

```

This approach is ideal for temporary testing or containerized deployments where you control the startup environment.

### Method 2: Configuration File

For persistent configuration, edit or create `~/.ollama/ollama.yaml`:

```yaml
host: 127.0.0.1
port: 11434
max_context: 32768

```

After saving the file, restart Ollama:

```bash
pkill -f ollama
ollama serve &

```

## Verifying the Configuration

Once restarted, confirm the new context size is active:

```bash
ollama ps

```

The output should display `CONTEXT 32768`. When you next start a chat session in OpenClaude, the warning in `makeLocalModelWarnings` (located in [`src/utils/statusNoticeLocalModel.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/statusNoticeLocalModel.ts)) will no longer trigger because `getOllamaContextInfo` will report the matching token count.

## Summary

- OpenClaude requests **32,768 tokens** for all Ollama conversations, as defined in the warning description within [`src/utils/statusNoticeLocalModel.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/statusNoticeLocalModel.ts).
- The utility function `getOllamaContextInfo` in [`src/utils/ollamaContext.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/ollamaContext.ts) executes `ollama ps` to detect the current context size at runtime.
- Set `OLLAMA_MAX_CONTEXT=32768` as an environment variable or add `max_context: 32768` to `~/.ollama/ollama.yaml` to meet this requirement.
- Always restart the Ollama service after changing configuration values.
- Verify the setting using `ollama ps` before starting OpenClaude sessions.

## Frequently Asked Questions

### What context length does OpenClaude expect for Ollama?

OpenClaude expects a **32,768-token context window** for Ollama chats. This value is hardcoded in the warning description within [`src/utils/statusNoticeLocalModel.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/statusNoticeLocalModel.ts) and reflects the default buffer size used when constructing chat requests.

### How do I check if my Ollama context is set correctly?

Run `ollama ps` in your terminal and inspect the `CONTEXT` column. If it displays **32768**, your configuration is correct. Internally, OpenClaude runs the same command via the `getOllamaContextInfo` function in [`src/utils/ollamaContext.ts`](https://github.com/Gitlawb/openclaude/blob/main/src/utils/ollamaContext.ts) to validate your setup automatically.

### Why does OpenClaude show a context length warning even after I changed the setting?

The Ollama service loads configuration only at startup. If you edited `~/.ollama/ollama.yaml` or exported the environment variable without restarting the process, the old context limit remains active. Stop all Ollama processes with `pkill -f ollama` and relaunch with `ollama serve` to apply the new context length.

### Can I use a context length different from 32768 tokens?

While Ollama supports arbitrary context sizes via `OLLAMA_MAX_CONTEXT`, OpenClaude specifically warns when the value differs from 32,768 tokens. Using a smaller value may cause conversation truncation, while larger values consume more VRAM without benefitting OpenClaude's current implementation.