Running AI Coding Agents Locally with Ollama and Claude Code

本文为原文前 6,000 字符的节选翻译,完整内容请查看原文。

Running AI Coding Agents Locally with Ollama and Claude Code

Can an AI coding agent analyze your project, create files, implement features, fix bugs, and run commands directly on your own machine, without a monthly AI subscription? I have been exploring how to build a local AI-powered development environment with Ollama and Claude Code, and I want to share the setup process with other developers, especially students and beginners interested in AI-assisted coding. The idea is simple: run an AI model locally, connect it to a coding agent, and use it to work on real software projects. Below is a step-by-step guide for Windows users.

AI 编码智能体能否在无需每月订阅的情况下,直接在您的机器上分析项目、创建文件、实现功能、修复错误并运行命令?我一直在探索如何利用 Ollama 和 Claude Code 构建本地 AI 驱动的开发环境,并希望与包括学生和初学者在内的其他开发者分享这一设置过程。其核心理念很简单:在本地运行 AI 模型,将其连接到编码智能体,并利用它处理实际的软件项目。以下是针对 Windows 用户的分步指南。

1. Understand the Tools

Ollama runs AI models locally on your computer. Claude Code is an AI coding agent that can inspect a codebase, edit files, execute commands, and work through multi-step development tasks. Local integration connects a compatible model to an agent so you can move beyond asking questions and start working on actual project files. Important distinction: using Claude Code with Ollama does not mean Anthropic’s Claude model is running locally. Ollama runs the local model, while Claude Code provides the agent interface. Compatibility depends on the integration and the model you choose.

1. 了解工具

Ollama 在您的计算机上本地运行 AI 模型。Claude Code 是一款 AI 编码智能体,能够检查代码库、编辑文件、执行命令并完成多步骤的开发任务。本地集成将兼容的模型连接到智能体,使您能够超越简单的问答,开始处理实际的项目文件。需要特别注意的是:将 Claude Code 与 Ollama 结合使用并不意味着 Anthropic 的 Claude 模型在本地运行。Ollama 负责运行本地模型,而 Claude Code 提供智能体接口。兼容性取决于集成方式以及您所选择的模型。

2. Install Ollama

Download Ollama for Windows: https://ollama.com/download. After installation, open PowerShell and verify the installation: ollama --version. Check which models are already installed: ollama list. If you do not have a model yet, download a coding model. For example: ollama pull qwen3.5:0.8b. Other available models can be found here: https://ollama.com/search. Once the download is complete, launch the model: ollama run qwen3.5:0.8b. Try a simple prompt: “Write a Java method that checks whether a string is a palindrome, and explain how it works.” If the model responds, your local AI model is running. To exit the interactive session: /bye. Screenshot 1: PowerShell showing the Ollama version, installed model, and its response.

2. 安装 Ollama

下载适用于 Windows 的 Ollama:https://ollama.com/download。安装完成后,打开 PowerShell 并验证安装:ollama --version。查看已安装的模型:ollama list。如果您还没有模型,请下载一个编码模型。例如:ollama pull qwen3.5:0.8b。其他可用模型可以在此处找到:https://ollama.com/search。下载完成后,启动模型:`ollama run qwen3.5:0.8b。尝试一个简单的提示词:“编写一个 Java 方法来检查字符串是否为回文,并解释其工作原理。”如果模型有响应,说明您的本地 AI 模型正在运行。退出交互会话:/bye`。截图 1:PowerShell 显示了 Ollama 版本、已安装的模型及其响应。

3. Install Claude Code

Install Claude Code using the official Windows installation command: irm https://claude.ai/install.ps1 | iex. Follow the installation instructions. Official documentation: https://docs.anthropic.com/en/docs/claude-code/overview. Important: installing Claude Code and Ollama does not automatically connect them. Claude Code normally uses Anthropic’s supported services and authentication. To use a local Ollama model, you need a compatible integration and configuration. Ollama’s documented integration instructions are available here: https://docs.ollama.com/integrations/claude-code.

3. 安装 Claude Code

使用官方 Windows 安装命令安装 Claude Code:irm https://claude.ai/install.ps1 | iex。按照安装说明进行操作。官方文档:https://docs.anthropic.com/en/docs/claude-code/overview。重要提示:安装 Claude Code 和 Ollama 并不会自动将它们连接起来。Claude Code 通常使用 Anthropic 支持的服务和身份验证。要使用本地 Ollama 模型,您需要进行兼容的集成和配置。Ollama 的集成说明文档可在此处获取:https://docs.ollama.com/integrations/claude-code。

4. Connect Ollama to the Coding Agent

First, confirm that your local model is available: ollama list. Then follow Ollama’s current Claude Code integration instructions to check the required version and configure the agent. The documented launch command is: ollama launch claude. Follow the prompts to select a supported model and complete the setup. Once configured, navigate to your project directory, replacing the example path with the actual path to your project: cd "D:\MQL\S3\AI skills\TP1\biblio". Launch the agent: ollama launch claude. The agent should start in your project context, with access to the tools enabled by your integration and permissions. Model compatibility matters. Not every local model supports tool calling or works correctly with every agent. If the model only returns text instead of editing files, check the model’s compatibility and the agent’s available tools. Screenshot 2: The terminal showing the project path and the coding agent starting.

4. 将 Ollama 连接到编码智能体

首先,确认您的本地模型可用:ollama list。然后按照 Ollama 当前的 Claude Code 集成说明检查所需版本并配置智能体。文档中的启动命令为:ollama launch claude。按照提示选择支持的模型并完成设置。配置完成后,导航到您的项目目录,将示例路径替换为您项目的实际路径:cd "D:\MQL\S3\AI skills\TP1\biblio"。启动智能体:ollama launch claude。智能体应在您的项目上下文中启动,并拥有集成和权限所启用的工具访问权限。模型兼容性很重要。并非每个本地模型都支持工具调用或能与每个智能体正常工作。如果模型只返回文本而不编辑文件,请检查模型的兼容性以及智能体可用的工具。截图 2:终端显示了项目路径和正在启动的编码智能体。

5. Test It on a Real Project

Suppose you are working on a Java, Spring Boot, React, or Node.js project. Instead of asking the model to return code in the chat, give the agent a task that requires actual changes. Example prompt: “Analyze the structure of this project. Identify the main components and explain how they interact. Then create a README.md file containing the project description, technologies used, installation steps, and commands to run the application. Create the file directly in the project and verify that it exists.” You can also experiment with the following tasks: Generate files, Implement a feature, Fix bugs, Understand an existing codebase. The objective is to let the agent inspect your project, plan its work, modify files, and execute commands, rather than simply generate code snippets. Screenshot 3: The agent creating or modifying files and running tests.

5. 在实际项目上进行测试

假设您正在处理一个 Java、Spring Boot、React 或 Node.js 项目。不要让模型在聊天中返回代码,而是给智能体分配一个需要实际更改的任务。示例提示词:“分析此项目的结构。识别主要组件并解释它们如何交互。然后创建一个 README.md 文件,其中包含项目描述、所用技术、安装步骤以及运行应用程序的命令。直接在项目中创建该文件并验证其是否存在。”您还可以尝试以下任务:生成文件、实现功能、修复错误、理解现有代码库。目标是让智能体检查您的项目、规划工作、修改文件并执行命令,而不是仅仅生成代码片段。截图 3:智能体正在创建或修改文件并运行测试。

6. Use It with IntelliJ IDEA

You can keep IntelliJ IDEA as your main development environment and use the agent through its integrated terminal. A simple workflow: Open your project in IntelliJ IDEA. Open the integrated terminal. Navigate to the project root directory. Launch your configured coding agent. Describe the task you want to complete. Review the changes in IntelliJ IDEA and run your tests. Note: ollama run qwen3.5:0.8b starts a conversation with the model. It does not automatically provide filesystem access or the ability to execute project tasks. For that, you need an agent integration with the appropriate tools and permissions.

6. 在 IntelliJ IDEA 中使用

您可以保留 IntelliJ IDEA 作为您的主要开发环境,并通过其集成终端使用智能体。一个简单的工作流程:在 IntelliJ IDEA 中打开您的项目。打开集成终端。导航到项目根目录。启动您配置好的编码智能体。描述您想要完成的任务。在 IntelliJ IDEA 中审查更改并运行测试。注意:ollama run qwen3.5:0.8b 只是与模型开启对话。它不会自动提供文件系统访问权限或执行项目任务的能力。为此,您需要一个具备适当工具和权限的智能体集成。

7. Why Run AI Locally?

No per-request inference fees for models running on your own hardware. Offline inference after the model is downloaded, provided the rest of your workflow does not require an internet connection. Greater control over the models and development environment you use. Privacy advantages when prompts and source code remain on your machine. A strong learning opportunity for exploring local AI, automation, and agentic development. Limitations: lo

7. 为什么要本地运行 AI?

在您自己的硬件上运行模型,无需支付每次请求的推理费用。模型下载后可离线推理,前提是您的其余工作流程不需要互联网连接。对所使用的模型和开发环境有更大的控制权。当提示词和源代码保留在您的机器上时,具有隐私优势。这是探索本地 AI、自动化和智能体开发的绝佳学习机会。局限性:lo