contextd is a small Go proxy that sits in front of an Ollama server and injects additional system context into chat requests before forwarding them upstream.
The current target use case is Continue in VS Code. Instead of pointing Continue directly at Ollama, you point it at contextd. The proxy reads a local markdown file, prepends that content as a system message, sends the modified payload to Ollama, and returns Ollama's response back to the client.
For requests sent to /api/chat, contextd:
`
- Accepts the JSON request from the client.
- Unmarshals the request into Go structs.
- Reads a local context file from disk.
- Prepends the file contents as a
systemmessage. - Marshals the modified payload back to JSON.
- Forwards the request to the configured Ollama endpoint.
- Returns the upstream response to the original caller.
This lets you centralize personality, instructions, or user-specific context without modifying each client integration.
The current implementation only handles:
POST /api/chat
It is intentionally narrow while the proxy behavior is being developed and learned in Go.
- Go 1.25+
- A running Ollama server
- A context file on disk, such as
Context.md - A client that can target an Ollama-compatible endpoint, such as Continue
contextd reads its configuration from environment variables.
| Variable | Description | Example |
|---|---|---|
PORT |
Listen address for the Go server. This must be a valid host:port style address. |
:8080 |
OLLAMA_BASE_URL |
Full upstream Ollama chat endpoint. | http://localhost:11434/api/chat |
SYSTEM_CONTEXT_FILE |
Path to the markdown/text file to inject as the system prompt. | Context.md |
Example:
export PORT=:8080
export OLLAMA_BASE_URL=http://localhost:11434/api/chat
export SYSTEM_CONTEXT_FILE=Context.mdStart the proxy:
go run main.goIf the server starts correctly, it will listen on the address configured by PORT.
Point Continue at the proxy instead of Ollama directly.
Example Continue model configuration:
models:
- name: local-llm
provider: ollama
model: llama3.2
apiBase: http://localhost:8080Continue will send requests like:
POST http://localhost:8080/api/chat
contextd receives that request, injects the configured context, and forwards it to:
POST http://localhost:11434/api/chat
Example Context.md:
Your name is (clever name for llm goes here).
You are Caleb Welch's AI assistant.
You are direct, technically rigorous, and concise.That content is inserted into the outbound Ollama chat payload as a system message.
Client request:
{
"model": "llama3.2",
"messages": [
{
"role": "user",
"content": "Explain slices in Go."
}
]
}Modified request sent upstream:
{
"model": "llama3.2",
"messages": [
{
"role": "system",
"content": "<contents of Context.md>"
},
{
"role": "user",
"content": "Explain slices in Go."
}
]
}- Learn idiomatic Go by building a real service
- Centralize LLM personality and persistent context outside the client
- Keep Ollama-compatible clients unchanged
- Expand over time into a more capable local LLM middleware layer
- Only
/api/chatis currently handled - Context is read from disk on each request
- The current proxy flow is designed for local development and experimentation
- Additional Ollama endpoints such as
/api/generateare not yet implemented
This project is intentionally being built incrementally as a Go learning exercise. The implementation favors clarity and directness over abstraction while the core proxy behavior is being established.