{"slug": "how-to-run-a-terminal-coding-agent-on-a-local-model", "title": "How to run a terminal coding agent on a local model", "summary": "A hands-on test on an Apple M5 MacBook with 24 GB of memory found that Ollama's default 4,096-token context window and unreliable tool-call formatting are the two factors deciding whether a local model can drive a terminal coding agent. Running Ollama 0.40.19 with OLLAMA_CONTEXT_LENGTH set to 32,768 and Clixad 0.0.1-beta.55 on 2 December 2026, qwen2.5-coder:7b returned its tool call as plain text with finish_reason stop and left the file unchanged, while qwen3:8b returned a tool_calls entry, read notes.txt, showed a diff and wrote the edit after approval in a little over two minutes, ending at 9,447 tokens with no Clixad credits. The test notes that Ollama's tools capability flag only means a model's template accepts tools, not that the model will emit them, and that Clixad's instructions and tool definitions alone total about 8,000 characters, roughly 2,000 tokens, before any project instructions or user message.", "body_md": "# How to run a terminal coding agent on a local model\n\n            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.\n          \n\n            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.\n          \n\n## What a local model needs\n\nA 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.\n\n- **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.\n- **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.\n\n## Setting up Ollama\n\nWe installed it with Homebrew on a Mac:\n\n```\nbrew install ollama\nOLLAMA_CONTEXT_LENGTH=32768 ollama serve\nollama pull qwen3:8b\n```\n\nThe 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.\n\n          Ollama then serves the model at `http://localhost:11434/v1`, and its OpenAI compatibility page lists\n          tools among the supported features of `/v1/chat/completions`.\n        \n\n## What happened when we tried two models\n\n          We ran one small task through Clixad on two models: read `notes.txt`, then append a line to it. The\n          machine was an Apple M5 MacBook with 24 GB of memory, running Ollama 0.40.19 with the window set to 32,768 tokens,\n          and Clixad 0.0.1-beta.55.\n        \n\n| One task, two models, on 2 December 2026. Both models are Ollama's 4-bit builds. |  |  |  | \n|---|---|---|---|\n| Model | Ollama lists tools | What came back | Result | \n|---|---|---|---|\n| `qwen2.5-coder:7b` | Yes | The tool call written as text in the answer, no `tool_calls` ,`finish_reason`` stop` | Nothing ran; the file was unchanged | \n| `qwen3:8b` | Yes | A `tool_calls` entry,`finish_reason`` tool_calls` | Read the file, showed the edit, wrote it after approval | \n\n          The first result is the one to remember. Ollama reports a `tools` capability for\n          `qwen2.5-coder:7b`, and we confirmed outside Clixad, with a plain request to Ollama's API, that the model\n          still answered with the call as text. So the capability says the model's template accepts tools. It does not\n          say the model will use them. LM Studio's documentation describes the same failure: a smaller model can produce a\n          tool call in a format the server cannot parse, and it comes back as ordinary text.\n        \n\n          The second model did the task. Clixad read the file, showed the change as a diff, wrote it once we approved, and\n          ended the turn with `[local model · 9,447 tokens · no Clixad credits]`. It took a little over two\n          minutes before the edit was ready to approve. `qwen3:8b` thinks before it answers by default, and\n          that is part of the time. This was one run on one machine, so read it as what to expect from a laptop rather\n          than as a benchmark.\n        \n\n          The quickest check before you start a session is the same request we used, sent to the server directly with a\n          tool definition: if the answer has a `tool_calls` field, the model can drive an agent.\n        \n\n## Pointing Clixad at it\n\n          Inside Clixad, `/local` looks for a model server on your machine, at Ollama's and LM Studio's usual\n          addresses (`127.0.0.1:11434` and `127.0.0.1:1234`), and lists every model they report. Pick\n          one and the next turn runs on it. For any other OpenAI-compatible server, set `CLIXAD_LOCAL_URL` to its\n          address first.\n        \n\n- Requests go from your machine to the local server. They do not reach our gateway, and no Clixad credits are used.\n- 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.\n- 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.\n- Web search is not offered on a local model, since it runs on our gateway. Reading a web page still works.\n- `/local off` goes back to Clixad's models.\n\n## LM Studio and llama.cpp\n\nWe did not test these two, so this section is what their documentation says.\n\n**LM Studio** starts its server from the Developer tab or with `lms server start`, and its\n          examples use `http://localhost:1234/v1`. It says \"Through LM Studio, all models support at least some\n          degree of tool use.\" Models with native support carry a hammer badge in the app, and those are the ones to try\n          first for agent work.\n        \n\n**llama.cpp's** `llama-server` lists its port in its README as \"port to listen (default:\n          9931)\". Its function-calling document says tool calls are used by \"llama-server when started w/ --jinja flag\".\n          Because 9931 is not one of the ports Clixad looks at, start Clixad with\n          `CLIXAD_LOCAL_URL=http://127.0.0.1:9931/v1`.\n        \n\n## When a local model is the right choice\n\nA 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.\n\n          It fits well for work you cannot send anywhere, for small edits and questions about code, and for carrying on\n          when other limits have run out. For a long refactor across many files, a larger hosted model usually finishes\n          sooner and needs fewer corrections. In Clixad you can move between the two in the same conversation:\n          `/local` to go local, `/local off` to go back.\n        \n\n## FAQ\n\n## ### Can I use Ollama with a coding agent?\n\nYes, 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.\n\n## ### Why does the agent print JSON instead of editing my files?\n\nThe 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.\n\n## ### How much context does a local model need for a coding agent?\n\nMore 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.\n\n## ### How do I use a local model in Clixad?\n\nStart 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.\n\n## ### Is a local model free?\n\nIt 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.\n\n## Sources\n\n1. Ollama, [OpenAI compatibility](https://docs.ollama.com/api/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](https://docs.ollama.com/faq) , for \"By default, Ollama uses a context window size of 4096 tokens\" and`OLLAMA_CONTEXT_LENGTH` . Ollama,[Tool calling](https://docs.ollama.com/capabilities/tool-calling) . All read 2 December 2026.\n2. LM Studio, [OpenAI compatibility](https://lmstudio.ai/docs/developer/openai-compat) , for the examples at`http://localhost:1234/v1` and starting the server. LM Studio,[Tool use](https://lmstudio.ai/docs/developer/openai-compat/tools) , 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.\n3. llama.cpp, [llama-server README](https://github.com/ggml-org/llama.cpp/blob/master/tools/server/README.md) , for \"port to listen (default: 9931)\". llama.cpp,[Function calling](https://github.com/ggml-org/llama.cpp/blob/master/docs/function-calling.md) , for \"llama-server when started w/ --jinja flag\". Both read 2 December 2026.\n4. 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.\n5. 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](https://github.com/clixad/cli) , and section 4 of our[privacy policy](https://clixad.io/privacy.html) .", "url": "https://wpnews.pro/news/how-to-run-a-terminal-coding-agent-on-a-local-model", "canonical_source": "https://clixad.io/blog/local-model-coding-agent/", "published_at": "2026-12-02 00:00:00+00:00", "updated_at": "2026-12-02 22:46:11.135336+00:00", "lang": "en", "topics": ["ai-tools", "ai-agents", "large-language-models", "developer-tools"], "entities": ["Ollama", "LM Studio", "llama.cpp", "Clixad", "qwen2.5-coder:7b", "qwen3:8b", "Apple M5 MacBook"], "also_reported_by": [], "takeaway": "Set OLLAMA_CONTEXT_LENGTH to 32,768 before serving, since Ollama's 4,096-token default is half consumed by an agent's ~2,000 tokens of instructions and tool definitions, and verify the model returns a real tool_calls field rather than text — qwen2.5-coder:7b failed despite Ollama listing tools for i", "recommendation": {"advice": "Raise the local server's context window (OLLAMA_CONTEXT_LENGTH=32768) and test that your model emits actual tool_calls before relying on it; qwen2.5-coder:7b wrote calls as text and changed nothing, while qwen3:8b completed the edit.", "playbook": "agent-architecture", "playbook_url": "https://wpnews.pro/playbooks/agent-architecture"}, "alternates": {"html": "https://wpnews.pro/news/how-to-run-a-terminal-coding-agent-on-a-local-model", "markdown": "https://wpnews.pro/news/how-to-run-a-terminal-coding-agent-on-a-local-model.md", "text": "https://wpnews.pro/news/how-to-run-a-terminal-coding-agent-on-a-local-model.txt", "jsonld": "https://wpnews.pro/news/how-to-run-a-terminal-coding-agent-on-a-local-model.jsonld"}}