How to run a terminal coding agent on a local model

Short answer

Ollama, LM Studio and llama.cpp serve a model on your machine behind an OpenAI-compatible API, so a coding agent can use them. Two things decide whether it then works: the model has to return real tool calls, and the server's window has to be larger than Ollama's default of 4,096 tokens.

In our test on an Apple M5 with 24 GB, qwen2.5-coder:7b wrote its tool calls as text and changed nothing, although Ollama lists tools for it. qwen3:8b read a file and made the edit, in a little over two minutes. In Clixad, /local finds the server and uses no credits.

What a local model needs

A terminal coding agent talks to a model through a chat API. Ollama, LM Studio and llama.cpp's server each serve a model on your machine behind an OpenAI-compatible endpoint, so an agent that can be pointed at such an endpoint can use them. Two things decide whether it then does any work.

  • Tool calls the server can return. An agent edits files and runs commands by asking for a tool, and the API returns that request in a field of its own. If the model writes the request into its answer as text instead, the agent sees a reply, not a request, and nothing runs.
  • A window large enough for an agent. The agent's instructions and its tool definitions come before your first word, and every file it reads is added after. A short window cuts the conversation without saying so.

Setting up Ollama

We installed it with Homebrew on a Mac:

brew install ollama
OLLAMA_CONTEXT_LENGTH=32768 ollama serve
ollama pull qwen3:8b

The second line matters more than it looks. Ollama's FAQ says "By default, Ollama uses a context window size of 4096 tokens", and the default "can be overridden with the OLLAMA_CONTEXT_LENGTH environment variable." Setting it through the API is not an option: "The OpenAI API does not have a way of setting the context size for a model." In Clixad the instructions and the tool definitions alone come to about 8,000 characters, roughly 2,000 tokens at four characters a token, before the project's own instructions and your first message. A 4,096-token window is half gone before the work starts.

Ollama then serves the model at http://localhost:11434/v1, and its OpenAI compatibility page lists tools among the supported features of /v1/chat/completions.

What happened when we tried two models

We ran one small task through Clixad on two models: read notes.txt, then append a line to it. The machine was an Apple M5 MacBook with 24 GB of memory, running Ollama 0.40.19 with the window set to 32,768 tokens, and Clixad 0.0.1-beta.55.

One task, two models, on 2 December 2026. Both models are Ollama's 4-bit builds.
ModelOllama lists toolsWhat came backResult
qwen2.5-coder:7bYesThe tool call written as text in the answer, no tool_calls, finish_reason stopNothing ran; the file was unchanged
qwen3:8bYesA tool_calls entry, finish_reason tool_callsRead the file, showed the edit, wrote it after approval

The first result is the one to remember. Ollama reports a tools capability for qwen2.5-coder:7b, and we confirmed outside Clixad, with a plain request to Ollama's API, that the model still answered with the call as text. So the capability says the model's template accepts tools. It does not say the model will use them. LM Studio's documentation describes the same failure: a smaller model can produce a tool call in a format the server cannot parse, and it comes back as ordinary text.

The second model did the task. Clixad read the file, showed the change as a diff, wrote it once we approved, and ended the turn with [local model · 9,447 tokens · no Clixad credits]. It took a little over two minutes before the edit was ready to approve. qwen3:8b thinks before it answers by default, and that is part of the time. This was one run on one machine, so read it as what to expect from a laptop rather than as a benchmark.

The quickest check before you start a session is the same request we used, sent to the server directly with a tool definition: if the answer has a tool_calls field, the model can drive an agent.

Pointing Clixad at it

Inside Clixad, /local looks for a model server on your machine, at Ollama's and LM Studio's usual addresses (127.0.0.1:11434 and 127.0.0.1:1234), and lists every model they report. Pick one and the next turn runs on it. For any other OpenAI-compatible server, set CLIXAD_LOCAL_URL to its address first.

  • Requests go from your machine to the local server. They do not reach our gateway, and no Clixad credits are used.
  • After each such turn the agent tells our server how many calls and tokens it took and the model's name, which we add to a daily total that names no account.
  • The conversation is kept under 32,768 tokens, and the agent says so when you switch, because a server set to less cuts prompts short.
  • Web search is not offered on a local model, since it runs on our gateway. Reading a web page still works.
  • /local off goes back to Clixad's models.

LM Studio and llama.cpp

We did not test these two, so this section is what their documentation says.

LM Studio starts its server from the Developer tab or with lms server start, and its examples use http://localhost:1234/v1. It says "Through LM Studio, all models support at least some degree of tool use." Models with native support carry a hammer badge in the app, and those are the ones to try first for agent work.

llama.cpp's llama-server lists its port in its README as "port to listen (default: 9931)". Its function-calling document says tool calls are used by "llama-server when started w/ --jinja flag". Because 9931 is not one of the ports Clixad looks at, start Clixad with CLIXAD_LOCAL_URL=http://127.0.0.1:9931/v1.

When a local model is the right choice

A local model costs no tokens and sends nothing off your machine, which no hosted service can match. What it costs instead is memory, time and capability. An 8-billion-parameter model on a laptop is slower than a hosted one and weaker at long multi-step work, which is exactly what an agent asks of it.

It fits well for work you cannot send anywhere, for small edits and questions about code, and for carrying on when other limits have run out. For a long refactor across many files, a larger hosted model usually finishes sooner and needs fewer corrections. In Clixad you can move between the two in the same conversation: /local to go local, /local off to go back.

FAQ

Can I use Ollama with a coding agent?

Yes, if the agent can use an OpenAI-compatible endpoint. Ollama serves one at http://localhost:11434/v1. Start it with a larger window than its default of 4,096 tokens, for example OLLAMA_CONTEXT_LENGTH=32768 ollama serve, and use a model that returns real tool calls.

Why does the agent print JSON instead of editing my files?

The model wrote its tool call into the answer as text instead of returning it as a tool call, so the agent never received a request to act. In our test qwen2.5-coder:7b did this although Ollama lists tools for it. Try a model that returns a tool_calls field, such as qwen3:8b did.

How much context does a local model need for a coding agent?

More than Ollama's default of 4,096 tokens: in Clixad the instructions and tool definitions alone take roughly 2,000 tokens before your first message. Clixad keeps a local conversation under 32,768 tokens, and the server should be set to at least that.

How do I use a local model in Clixad?

Start Ollama or LM Studio, then type /local in Clixad and pick a model from the list. For another OpenAI-compatible server, set CLIXAD_LOCAL_URL to its address first. /local off goes back to Clixad's models.

Is a local model free?

It uses no credits and no tokens from any provider. It costs memory, electricity and time: in our test on an Apple M5 with 24 GB, qwen3:8b took a little over two minutes to read a file and propose an edit.

Sources

  1. Ollama, OpenAI compatibility, for the base URL, tools among the supported features, and "The OpenAI API does not have a way of setting the context size for a model." Ollama, FAQ, for "By default, Ollama uses a context window size of 4096 tokens" and OLLAMA_CONTEXT_LENGTH. Ollama, Tool calling. All read 2 December 2026.
  2. LM Studio, OpenAI compatibility, for the examples at http://localhost:1234/v1 and starting the server. LM Studio, Tool use, for "Through LM Studio, all models support at least some degree of tool use.", the hammer badge, and tool calls that come back as text. Both read 2 December 2026.
  3. llama.cpp, llama-server README, for "port to listen (default: 9931)". llama.cpp, Function calling, for "llama-server when started w/ --jinja flag". Both read 2 December 2026.
  4. The test: our own run on 2 December 2026, on an Apple M5 MacBook with 24 GB of memory, Ollama 0.40.19 installed with Homebrew, and Clixad 0.0.1-beta.55 driven in a terminal, with a direct request to Ollama's /v1/chat/completions to confirm each model's answer outside Clixad.
  5. What /local looks for, the 32,768-token window and the count it sends: the source of the command line tool at github.com/clixad/cli, and section 4 of our privacy policy.