Set Up a Local AI Coding Agent

Run a private AI pair programmer on your GPU to edit your Laravel codebase.

Introduction

30 Second Summary

AI coding assistants are powerful, but most of them send your code to someone else's servers. If you work on private projects or just want to keep your workflow offline, there's a better option sitting right on your own machine.

In this project, you will set up a fully private AI coding agent that runs on your local GPU and understands your Laravel project. You'll use it to generate, refactor, and edit code across multiple files without any data ever leaving your computer.

What You'll Build

A fully offline AI pair programming workflow that reads your Laravel codebase, understands how files relate to each other, and edits code on your command with every change tracked in Git.

By the end of this project, you'll have:

  • Ollama installed with a GPU-accelerated coding model running entirely on your machine.
  • Aider connected to your local model and mapped to your Laravel project's codebase.
  • A real feature built by your AI agent with auto-committed, undoable changes you can review and revert.
  • Secret Mission: Configure an extended context window and use the agent to extract shared logic into a Laravel service class across multiple files.

Are there any prerequisites?

You need a Windows PC with an NVIDIA GPU (this project uses an RTX 5060 with 8 GB VRAM), an existing Laravel project with Git initialized, and a working internet connection for the initial downloads. No Python experience is required.

Install Ollama and Pull the Coding Model

Your RTX 5060 GPU can run AI models locally, giving you a private coding assistant that never sends data to the internet. Ollama is a tool that downloads and serves large language models on your own hardware.

In this step, you will install Ollama and download a code-specialized model called Qwen 2.5 Coder 7B. This model will power your AI coding agent for the rest of the project.

In this step, get ready to:
  • Install Ollama on Windows.
  • Download the Qwen 2.5 Coder 7B model.
  • Verify GPU-accelerated inference is working.
Install Ollama on Windows

Ollama is a lightweight runtime that downloads, manages, and serves LLMs on your machine. Once installed, it runs in the background and exposes a local API that other tools (like Aider) can connect to.

  • Press the Windows key to open your search bar.
  • Type PowerShell and press Enter to open it.
  • Install Ollama by running this command:
irm https://ollama.com/install.ps1 | iex

What does this command do?

irm (short for Invoke-RestMethod) downloads the official Ollama install script from their website.

The | iex pipe passes that script directly to PowerShell to execute. This installs Ollama into your user account without needing Administrator rights.

The installer may trigger a Windows security prompt asking for permission to install the Visual C++ runtime. Click Yes if you see this.

After installation completes, Ollama runs in the background automatically.

  • Close your current PowerShell window and open a new one (the installer adds Ollama to your PATH, but only new terminals pick it up).
  • Confirm the installation by running:
ollama version

✔️ I see a version number

Ollama is installed and ready. The CLI is available system-wide.

ⓧ Command not found or error

The terminal cannot find the ollama command. Try these fixes:

  • Make sure you opened a brand new PowerShell window after the install finished. The old window does not have the updated PATH.
  • Check that your system meets the requirements: Windows 10 22H2 or newer, and NVIDIA drivers 452.39 or newer.
  • If Windows Smart App Control blocked the installer, try downloading the installer directly from https://ollama.com/download and running it manually.

After fixing, close and reopen PowerShell, then run ollama version again.

Pull the Qwen 2.5 Coder 7B model

Ollama hosts a library of pre-packaged models you can download with a single command. You will pull Qwen 2.5 Coder 7B, a model specifically trained for code generation and reasoning.

Why this model?

Qwen 2.5 Coder 7B uses Q4_K_M quantization to compress 7.62 billion parameters into a 4.7 GB file. This fits entirely in your RTX 5060's 8 GB VRAM with room left for context, so every response is fully GPU-accelerated.

Larger models like DeepSeek 14B would not fit in your VRAM and would partially run on CPU, making responses much slower.

  • Download the model by running this command (this will take a few minutes depending on your internet speed):
ollama pull qwen2.5-coder:7b
  • Confirm the model downloaded by running:
ollama list
  • You should see qwen2.5-coder:7b listed with a size of approximately 4.7 GB.

Download stuck or failing?

  • Check your internet connection. The model file is 4.7 GB and needs a stable connection to download.
  • If the download interrupted, run the same ollama pull command again. Ollama resumes partial downloads automatically.
  • Make sure you have at least 5 GB of free disk space on your system drive.

Need more help? Help me troubleshoot my Ollama model download on Windows.

Test the model

The final check confirms that your GPU is actually running the model, not your CPU. A GPU-accelerated response should arrive in a few seconds. A CPU-only response would take 30 seconds or more.

  • Run a quick test prompt by running this command:
ollama run qwen2.5-coder:7b "Write a PHP function that returns the sum of an array"
  • You should see a coherent PHP function appear within a few seconds.
  • If the command drops you into interactive mode instead of printing and exiting, type /bye to exit.

How do I know it's using my GPU?

Speed is the indicator. If the response appears within 2-5 seconds, the model is running entirely on your RTX 5060's VRAM. If it takes 30+ seconds, the model may have fallen back to CPU.

Ollama automatically detects NVIDIA GPUs via CUDA. As long as your NVIDIA drivers are up to date, GPU acceleration is enabled by default.

Response is very slow or you see an error?

  • Make sure your NVIDIA drivers are version 452.39 or newer. Open NVIDIA Control Panel and check under System Information.
  • Close GPU-heavy applications (games, video editors) that might be consuming VRAM.
  • If you see an error mentioning the runner process, try closing and reopening PowerShell, then run the command again.

Still stuck? Help me figure out why Ollama is slow or not using my GPU.

Your local model server is ready. Next up, you will install Aider and connect it to this model so it can read and edit your Laravel project.

Install Aider

Your local model is downloaded and GPU-accelerated. Now you need a tool that can actually read your Laravel project, understand how files relate to each other, and apply edits across multiple files on your command.

That tool is Aider. It connects to your local Ollama model, maps your entire codebase, and auto-commits every change to Git so you can undo anything instantly.

In this step, get ready to:
  • Install Aider using the official Windows one-liner.
  • Set a permanent environment variable so Aider knows where Ollama's API is running.
Install Aider using the Windows one-liner

Aider's installer handles Python automatically. You do not need Python installed separately. If Python is not already on your system, the installer adds Python 3.12 in an isolated environment that does not interfere with anything else on your machine.

  • Install Aider by running this command in PowerShell:
powershell -ExecutionPolicy ByPass -c "irm https://aider.chat/install.ps1 | iex"

What does this command do?

This downloads and runs Aider's official install script. The -ExecutionPolicy ByPass flag allows the script to run without changing your system's security settings permanently.

The installer creates a self-contained Python environment just for Aider. Your system stays clean.

  • Close your current terminal window completely.
  • Open a new PowerShell window (press the Windows key, type PowerShell, and press Enter).
  • Confirm Aider is installed by running:
aider --version

You should see a version number printed (e.g. aider v0.x.x). This confirms the CLI is available system-wide.

Command not found?

Make sure you opened a brand new terminal window after installation. The old terminal does not know about the new path.

If it still fails, try closing all terminal windows and reopening one. Some systems need a full restart of the shell process.

Why can't my terminal find the aider command after installation?

Set the Ollama environment variable

Aider needs to know where Ollama's API is running so it can send your prompts to the local model. Ollama serves its API at http://127.0.0.1:11434 by default.

  • Set the OLLAMA_API_BASE environment variable permanently by running this command:
setx OLLAMA_API_BASE http://127.0.0.1:11434

Why setx instead of set?

The setx command writes the variable permanently to your Windows user profile. It persists across reboots and new terminal sessions.

The regular set command only lasts for the current session. If you used set, Aider would lose the connection every time you opened a new terminal.

  • Close your terminal and open a new one. The setx command requires a fresh session to take effect.
  • Verify the variable is set by running this in your new terminal:
$env:OLLAMA_API_BASE

You should see http://127.0.0.1:11434 printed in the output.

Using Command Prompt instead?

If you prefer Command Prompt over PowerShell, verify with echo %OLLAMA_API_BASE% instead. Both will show the same value.

Seeing a blank line or no output?

You must open a completely new terminal after running setx. The variable is not available in the same session where you set it.

If you closed and reopened but still see nothing, try restarting your computer. Some Windows configurations require a full restart for user environment variables to propagate.

Why is my OLLAMA_API_BASE environment variable empty in a new terminal?

Aider is installed and knows where to find your local model. Next up, you'll connect Aider directly to your Laravel project and watch it map your entire codebase.

Connect Aider to Your Laravel Project

You have Ollama serving the Qwen 2.5 Coder model on your GPU, and Aider installed and ready to go. Now it's time to connect them and point the agent at your actual Laravel project.

Aider works by scanning your Git repository to build a map of how files relate to each other. Once it has this map, it can understand your project structure and make targeted edits across multiple files.

In this step, get ready to:
  • Navigate to your Laravel project root.
  • Launch Aider connected to your local Qwen model.
  • Verify the agent can read and understand your codebase.
Navigate to your Laravel project

Aider needs to launch from the root of your Laravel project. This is the folder where artisan, composer.json, and the .git folder live.

  • Open your terminal and navigate to your Laravel project root by running this command:
cd [[LARAVEL_PATH="C:\path\to\your\laravel-project"]]

What counts as the project root?

The project root is whichever folder contains your artisan file, composer.json, and the .git directory. If you are unsure, open File Explorer and look for the folder with those items inside it.

Launch Aider with your local model
  • Start Aider pointing at the Ollama-hosted model by running this command:
aider --model ollama_chat/qwen2.5-coder:7b

What does this command do?

The --model flag tells Aider which LLM to use. The ollama_chat/ prefix is required because it tells Aider to use Ollama's chat endpoint rather than the completion endpoint.

When Aider launches, it detects your Git repo, counts the files, and builds a repo map. The repo map is a lightweight index of how your files relate to each other, so the model can pull in relevant context automatically.

  • Wait for Aider to finish scanning. You should see output showing your Git repo detected and the repo map built.
  • Confirm the Aider prompt (>) appears. This means Aider is ready to accept commands.

Ignore the model warning

You will likely see a warning that says Unknown context window size and costs, using sane defaults. This is normal. It appears because Aider does not have built-in metadata for every Ollama model. Aider uses safe defaults and this does not affect functionality.

Aider won't start or shows a connection error?

Make sure Ollama is still running in the background. Check the system tray for the Ollama icon. If it is not there, open a separate terminal and run ollama serve to start it again.

Confirm your OLLAMA_API_BASE environment variable is set correctly by running echo %OLLAMA_API_BASE% in a new Command Prompt window. It should show http://127.0.0.1:11434. If it does not, rerun the setx command from Step 2 and reopen your terminal.

help me troubleshoot why Aider cannot connect to my local Ollama instance

Verify Aider can read your codebase

Before you start building features, confirm that Aider can actually read and understand your project files.

  • At the Aider prompt, add your controllers directory to the chat context by typing:
/add app/Http/Controllers/

What does /add do?

The /add command tells Aider to read specific files or directories into the active conversation. Only files you add are directly editable by the model. Aider still uses its repo map to pull in context from related files automatically.

  • Now ask the model about your code by typing this at the prompt:
What controllers do I have and what do they do?
  • Read the response. The model should describe your controllers based on the actual code in your project.

Model gives a generic or incorrect response?

If the model describes controllers that do not exist in your project, the /add command may not have found the files. Check that you launched Aider from the correct directory (the one containing artisan).

You can verify your current directory by typing /ls at the Aider prompt to see which files are in the chat.

help me figure out why Aider is not reading my Laravel controllers correctly

Your agent is mapped to your codebase and ready to take instructions. Next up, you'll put it to work building a real feature in your Laravel project.

Build a Feature With Your AI Agent

Your AI agent can read your Laravel project and understand its structure. Now it's time to put it to work building a real feature.

The key to getting useful results from a local AI agent is specificity. You need to tell it exactly which files to touch, describe what you want in plain language, then review and accept (or undo) the changes it proposes.

In this step, get ready to:
  • Add relevant files to the chat so the agent can edit them.
  • Ask the agent to build a new feature using natural language.
  • Practice undoing and iterating on the agent's output.
Add the relevant files to the chat

Aider can only edit files that have been explicitly added to the chat session. Its repo map gives it read-only awareness of your entire project, but you need to grant edit access to the specific files you want changed.

  • At the Aider prompt (>), add the files relevant to building a new API endpoint by typing this command:
/add routes/api.php app/Http/Controllers/

What does this command do?

The /add command tells Aider which files it is allowed to edit. You only need to add the files that will actually change.

Aider will automatically pull in context from related files (like models or config) without you needing to add every single file in your project.

Aider confirms the files have been added to the chat. You should see the file paths listed in the output.

Ask the agent to build your feature

With the right files added, you can describe what you want in plain English. The more specific you are about the feature, the better the result.

  • Type the following request at the Aider prompt to ask it to build a new feature:
Create a new ProductController with an index method that returns all products as JSON. Add the route to api.php. Create the Product model if it doesn't exist.

What happens next?

Aider proposes diffs for each file it wants to create or edit. You will see exactly what lines are being added or changed in each file before anything is applied.

If the diffs look good, Aider applies them and auto-commits the changes to Git with a descriptive commit message. Every change the agent makes is tracked and reversible.

  • Review the diffs Aider shows you. Look for the new ProductController.php, the Product.php model, and the route added to api.php.
  • Let Aider apply the changes. It will auto-commit them to Git.

Model not generating useful code?

If Aider produces incomplete or incorrect code, try being more specific in your request. Mention exact method names, return types, and which files should be created or modified.

If you see a warning about an "unfamiliar model," this is normal. Aider does not have built-in metadata for all Ollama models, but this does not affect functionality.

Why is my local model producing low-quality code in Aider?

Practice undoing and iterating

One of Aider's strengths is that every change it makes is a Git commit you can instantly undo. This makes experimenting risk-free.

  • Undo the last commit Aider made by typing this command at the Aider prompt:
/undo

What does /undo do?

The /undo command reverts the last commit Aider made. Your files go back to exactly how they were before that commit. You can also use /diff to see what changed before deciding whether to keep or undo.

Now try a second request that builds on your original goal. This time, ask Aider to separate the business logic into a dedicated service class.

  • First, re-apply the feature by asking Aider to rebuild it (since you just undid it). Then ask it to refactor by typing this at the prompt:
Can you separate the business logic from the controller into a service class? Create app/Services/ProductService.php and move the logic there.

Why separate into a service class?

In Laravel, keeping controllers thin and moving business logic into service classes is a common pattern. Controllers handle HTTP concerns (request validation, response formatting). Services handle the actual work (calculations, queries, transformations).

This is exactly the kind of multi-file refactoring where an AI agent shines. It understands how the files relate and can move code between them consistently.

  • Review the diffs Aider proposes. You should see a new app/Services/ProductService.php file and updates to your controller.
  • Let Aider apply and commit the changes.
  • Verify your Git history by running this command in a separate terminal window (not inside Aider):
git log --oneline -5

You should see multiple commits from Aider with descriptive messages describing what each change accomplished.

Not seeing Aider's commits in git log?

Make sure you run git log from inside your Laravel project root directory (where the .git folder lives).

If you only see your own previous commits, Aider may not have applied the changes yet. Go back to the Aider session and check if it is waiting for your confirmation.

Why doesn't git log show any Aider commits in my Laravel project?

Feeding web documentation to your local agent

Your local model cannot browse the internet on its own. However, Aider has a built-in /web command that fetches any web page and adds its content to the chat context. This is useful when you need the model to understand the latest Laravel documentation or a new package's API.

For example, to fetch the Laravel routing docs:

/web https://laravel.com/docs/11.x/routing

Aider scrapes the page, converts it to text, and adds it to the conversation. You can then ask questions about it or tell the agent to apply patterns from that documentation to your code. Your code is never sent to any external service. Only the web page content is downloaded into your local chat session.

  • Try running the /web command above in your Aider session to see how it adds documentation context.

Secret mission

Extended Context and Multi-File Refactoring

Your local agent can do more than single-file edits. Configure an extended context window so the model holds more of your codebase in memory at once, then use it to extract shared logic into a Laravel service class across multiple files.

Clean Up Your Resources

Clean Up Your Resources

This project runs entirely locally with no cloud services or paid APIs. There are no ongoing costs. Decide whether to keep your resources running, pause them to come back later, or delete them entirely.

Resources you used:

  • Ollama installed at %LOCALAPPDATA%\Programs\Ollama with the Qwen 2.5 Coder 7B model (~4.7 GB) stored at %HOMEPATH%\.ollama.
  • Environment variable OLLAMA_API_BASE set permanently via setx.
  • Aider configuration file .aider.model.settings.yml in your Laravel project root.
  • Files created and modified by Aider in your Laravel project (controllers, services, models, routes).
  • Git commits made by Aider in your Laravel project.

Keep everything running

No action needed. Choose this if you plan to keep using Aider with your local Ollama model.

  • Ollama continues running in the background and serves the model on demand.
  • Aider remains installed in its isolated Python environment and is available system-wide.
  • Your OLLAMA_API_BASE environment variable stays set for future sessions.
  • All Aider-generated code and Git commits remain in your Laravel project.

Pause - I'll come back to this later

Stop Ollama from running in the background to free up system memory. Your model and configuration stay on disk.

  • Right-click the Ollama icon in your system tray (bottom-right of the taskbar) and select Quit Ollama.
  • When you want to resume, open Ollama from your Start menu. It will start serving the model again automatically.

Delete - I don't want to use this again

Remove all project resources completely.

  • Uninstall Ollama by opening Settings > Apps > Add or remove programs. Find Ollama in the list and click Uninstall. When prompted, check the option to remove models to reclaim the ~4.7 GB of disk space.
  • Remove the OLLAMA_API_BASE environment variable by opening Settings > System > About > Advanced system settings > Environment Variables. Under User variables, select OLLAMA_API_BASE and click Delete.
  • Delete the Aider configuration file from your Laravel project root by running:
Remove-Item .aider.model.settings.yml
  • Revert all Aider-generated commits from your Laravel project. Run this command to see how many Aider commits exist:
git log --oneline --all | Select-String "aider"
  • For each Aider commit you want to undo, use git revert <commit-hash> to safely reverse it. Alternatively, if all Aider commits are the most recent, use git reset --hard <commit-before-aider> to go back to the state before Aider's first change.

Nice Work!

Nice Work!

You now have a fully private, zero-cost AI pair programmer running on your own hardware. Your Laravel project has a local coding agent that reads your codebase, generates multi-file changes, and tracks everything in Git.

Here's what you accomplished:

  • Installed Ollama and downloaded Qwen 2.5 Coder 7B running fully GPU-accelerated on your RTX 5060.
  • Connected Aider to your local model with zero API keys and mapped your Laravel project so the agent understands your codebase structure.
  • Built a real feature using natural language commands with auto-committed, undoable changes tracked in Git.
  • Secret Mission: Configured an extended 16K context window and performed a multi-file refactoring to extract a service class from a controller across multiple files.

Ready to quiz yourself?