עברית 📰 Blog
← Back to Blog
AI Tools

How to Build a Local AI Coding Assistant with Ollama (Linux First)

Masterphub Editorial
AI Product Team
October 14, 2026

Share this article

How to Build a Local AI Coding Assistant with Ollama (Linux First)

Run AI coding models on your own computer, connect them to coding agents, and build a workflow with more control over your data and running costs.

Definition: A local AI coding assistant uses a language model running on your own computer to help write, explain, debug and edit code. Ollama is the model runtime. A coding agent such as Claude Code, Codex or OpenCode adds access to project files and multi-step work.

🎧 Listen to this guide on the Masterphub Podcast
Episode 14: Local AI Coding Assistants With Ollama

All episodes · Spotify

You do not need to build a model from scratch. With Ollama you download compatible models, run them locally and connect them to tools that work on real project files. Local models run on your hardware, so your limits are your computer, the model you choose and the quality of the agent you connect.

What you will build

  • Run a language model locally with Ollama.
  • Pick a coding model that fits your hardware.
  • Connect Ollama to Claude Code, Codex or OpenCode.
  • Set a context length for larger coding tasks.
  • Test the setup, fix common problems and work more safely.

1. How a local coding assistant works

Ollama downloads and runs models and exposes an interface other applications can call. The model is the reasoning engine. The coding agent is the working environment: it reads files, runs commands and carries out multi-step tasks, within its permission settings.

These parts are not interchangeable. Ollama alone does not let a model edit files or run commands. That comes from the agent and its integration.

2. Check your computer first

Note your RAM, CPU, GPU, VRAM, operating system and free storage. Model size matters, but so do quantization, context length and GPU memory. A smaller model that answers quickly is often more useful than a larger one that makes the machine struggle.

  • 8 GB RAM: a small quantized model and simple tasks.
  • 16 GB RAM: a reasonable start for light coding help.
  • 32 GB RAM: more room for model size and larger contexts.
  • 64 GB RAM or more: room for demanding models, though GPU memory can still limit you.

These are starting points, not guarantees. A computer with a capable GPU can behave very differently from a CPU-only one with the same RAM.

To get a first recommendation, ask an AI assistant:

Based on these hardware specifications, recommend three coding models that can run locally through Ollama. Prioritize reliable code generation, debugging quality, reasonable response speed, and compatibility with coding agents. Explain the expected memory requirements, limitations, and best use case for each model. Do not recommend a model that exceeds the available hardware without clearly explaining the trade-offs.

3. Install Ollama on Linux (command line first)

On Linux the fastest route is the official install script. Read it before you run it if you prefer: ollama.com/install.sh.

curl -fsSL https://ollama.com/install.sh | sh

Check that it installed:

ollama --version

On most distributions the installer sets Ollama up as a service. Check that it is running and starts on boot:

systemctl status ollama
sudo systemctl enable --now ollama

If something fails, read the service log:

journalctl -u ollama -f

If you have an NVIDIA GPU, confirm the driver sees it before you blame the model:

nvidia-smi

Windows and macOS: download the installer from ollama.com/download. On Windows use PowerShell or Windows Terminal for the commands below.

Browse the official model library at ollama.com/library and pick a model that fits your hardware.

4. Choose a coding model

There is no single best model. Quality, memory use, speed, context support and tool-calling reliability all matter. Three starting points to evaluate:

Option A: Qwen3 Coder

A coding-focused family for code generation, repository analysis, debugging and multi-file work. Model page. Some variants are demanding, so check the requirements of the exact variant, especially with limited GPU memory.

Option B: GPT-OSS 20B

An option for local inference and coding workflows. Model page. Let your agent and hardware guide the choice.

Option C: GLM-4.7-Flash

Another model to evaluate for coding. Model page. Check current variants and requirements. Parameter count alone does not tell you how fast it will run on your computer.

Download and start one:

ollama run gpt-oss:20b

or

ollama run qwen3-coder

Ollama downloads the model if needed and opens a session. The first download can take a while. Later launches reuse the files. If a name or tag is not found, check the current name in the library.

Useful commands:

ollama list      # models on this computer
ollama ps        # models loaded now, and whether they run on GPU or CPU
ollama stop gpt-oss:20b   # unload a model

Test the model before moving on

Start simple: "Explain what a Python function is, show a small example, and identify two common mistakes beginners make." Then something practical: "Write a Python function that validates an email address using a basic pattern. Explain the limitations of the validation and provide three test cases." Check correctness, clarity and whether it follows your instructions. A plausible snippet does not make a model suitable for autonomous development.

5. Connect Ollama to a coding agent

The agent supplies the workflow: inspecting files, editing code, running tests and doing multi-step work. What works depends on the agent, the model and the configuration. Ollama documents integrations with Claude Code, Codex and OpenCode. Start with one.

Option A: Claude Code

Install Claude Code from its official documentation, open a terminal in your project folder and run:

ollama launch claude

Follow the prompts to pick a compatible model. See the official integration guide. Using Claude Code with an Ollama model does not mean you are running Anthropic''s Claude model locally. The tool and the model are separate parts.

Option B: OpenAI Codex

Install Codex CLI from its official repository, then:

ollama launch codex

A documented alternative is:

codex --oss

See the official guide. As with Claude Code, an alternative model does not bring every feature of the native hosted model.

Option C: OpenCode

Install it from the OpenCode docs, then:

ollama launch opencode

Worth testing if another integration has trouble with tool calls.

Recommendation: get a simple project working with one agent before adding anything else.

6. Open the correct project folder

Open a terminal in your project folder (for example my-project/ with src/, tests/ and a README), then launch the agent. Ask it to inspect before it changes anything:

Inspect this project without modifying any files.

Explain:

  1. The purpose of the project.
  2. The main folders and important files.
  3. The programming languages and frameworks used.
  4. How the application is started and tested.
  5. Any obvious risks or missing dependencies.

Do not install packages, execute destructive commands, or modify files. Ask for permission before making changes.

If it cannot explain a small project, do not move on to refactoring.

7. Set the context window

The context window is how much the model can consider in one request: instructions, files, conversation, tool results and test output. Bigger helps with multi-file work and costs memory. Ollama''s default may be too small for agent workflows, and its integration docs recommend at least 64K tokens for supported setups. That is a target, not a requirement every computer handles well.

On Linux with the systemd service, set it as an environment variable:

sudo systemctl edit ollama

Add these lines in the editor that opens, then save:

[Service]
Environment="OLLAMA_CONTEXT_LENGTH=65536"

Apply it:

sudo systemctl daemon-reload
sudo systemctl restart ollama

On Windows or macOS, use the context length option in Ollama''s settings. Details: Ollama context length documentation. Watch memory and speed after you raise it. If the system gets unstable, lower the value or use a smaller model. A big window does not guarantee the model uses it well.

8. Run your first real task

Pick a small task with a clear result, such as a simple bug:

Analyze this project and identify one small, verifiable bug.

Before making changes:

  1. Explain the problem.
  2. Identify the file or files involved.
  3. Describe the proposed fix.
  4. Explain how the fix will be tested.

Wait for my approval before editing files.

After approval:

  1. Make the smallest reasonable change.
  2. Run the relevant tests if available.
  3. Report the files changed.
  4. Show the test results.
  5. Explain any remaining uncertainty.

Do not claim that tests passed unless they were actually run.

This shows whether the agent reasons correctly, uses tools properly and reports honestly. If it works, try something slightly bigger, like input validation or tests for an existing function.

9. Troubleshooting

The model runs too slowly

Likely causes: not enough GPU memory, CPU-only inference, a model that is too large, or a very large context. Run ollama ps to see whether the model is on GPU or CPU. Try a smaller model, close heavy applications and compare on a simple task.

The model downloads but will not start

Check the exact name and tag, free storage and memory, and that the service is running (systemctl status ollama on Linux).

The agent cannot connect

Update Ollama and the agent, re-read the official integration steps and confirm the model is compatible. Make sure Ollama is running and the endpoint and environment variables are correct.

The agent ignores instructions or makes poor edits

Use a smaller task, give clearer acceptance criteria and ask it to read the relevant files first. Poor tool use can mean the model is a weak fit for agent work.

The model loses track of the project

Trim conversation history, split large tasks and check the context setting. If things get worse after raising the context, lower it and test again.

The agent cannot finish multi-step tasks

Check that the model supports the tool calling the agent needs and that the agent has the permissions it needs. Try another compatible model or agent.

10. Security and privacy

Running a model locally can reduce how much code goes to an outside provider, but it does not guarantee your whole workflow is offline.

  • Confirm the model runs locally and not through a cloud endpoint. Ollama also offers cloud models, which are a different thing.
  • Check whether the agent or extensions make outside network requests.
  • Never paste API keys, passwords, private certificates or production credentials into prompts.
  • Use Git or another backup before allowing automated changes.
  • Review commands before running them, especially ones that delete files, install software or change system settings.
  • Give the agent only the permissions the task needs.
  • Keep your tools updated.

For your first project, work in a test repository or a copy.

11. Your first 15-minute checklist

  • Check RAM, CPU, GPU, VRAM and storage.
  • Install Ollama (Linux: the install script).
  • Pick a model that fits.
  • Download and run it.
  • Test it with a simple coding prompt.
  • Install one compatible coding agent.
  • Connect the agent with ollama launch.
  • Open a test project in the right folder.
  • Ask the agent to inspect without changing files.
  • Try one small fix and review every change.

Fifteen minutes is realistic for a prepared computer and a straightforward install. Large downloads and compatibility problems take longer.

Frequently asked questions

What is a local AI coding assistant?

A language model running on your own computer that helps generate, explain, debug and modify code. Ollama runs the model, and a coding agent adds project access and workflows.

How do you set up Ollama for coding?

Install Ollama, choose a compatible coding model, download it and connect it to a supported coding agent. Start with a small test project and check that it completes a simple task correctly.

Can I run an AI coding assistant for free?

Ollama and many downloadable models are free to use. You still need suitable hardware, storage and electricity. Cloud models and some third-party tools have their own pricing or limits.

Does it work offline?

After you download the model and install the tools, local inference can work offline. Initial downloads, updates and some agent features need a connection. Test your full setup before relying on it offline.

Can I use Ollama with Claude Code or Codex?

Yes. Use ollama launch claude or ollama launch codex and follow the prompts. Supported features depend on the model and integration.

How much RAM do I need?

There is no universal minimum. Smaller models run on modest hardware. Larger models and long contexts need more. Check the exact model and leave room for the system and other applications.

Is a local model as good as a premium cloud model?

Not necessarily. Local models can be effective for explanations, smaller fixes and many everyday tasks. Hard reasoning and large projects may favor stronger hosted models.

What should my first project be?

A small existing app or a script with tests. Begin with inspection and explanation, then a change that is easy to verify.

Final thoughts

A local assistant is not magic, and installing a model does not create a reliable developer. The value comes from a suitable model, a capable agent, clear instructions and disciplined testing. Start small, measure what works, and improve the setup only when you understand its limits.

Explore more AI tools, workflows and prompts at Masterphub.

Editorial note: model names, commands and integrations change. Recheck the official Ollama library and docs before relying on them. Last checked: October 14, 2026.

Share this article