Tools

AI-generated text

Running a Local Coding Agent Offline with Qwen and OpenCode

A principal engineer describes running an open-source coding agent entirely on a laptop in the foothills of the Himalayas, where network and power outages are frequent.

Running a Local Coding Agent Offline with Qwen and OpenCode

I moved to the foothills of the Himalayas a year ago. While I appreciate the quiet, the location brings frequent network and power outages. As a Principal Engineer at Thomson Reuters, I spend most of my time coding and reviewing teammates’ code. I already use coding agents in my workflow, so I wanted to see how much of that could run with the internet switched off.

This article describes running a coding agent entirely on a laptop: what tasks are feasible offline, which tools I used, and practical limits observed during the experiment.

What you can do without internet

A project already present on your laptop gives an agent plenty to work with. Offline it can read files, explain unfamiliar functions, investigate failing tests, refactor small pieces, or help finish a feature — provided the model, project dependencies and test tools are available locally. Downloading new packages or looking up web information still requires a connection.

Tools and architecture used

  • OpenCode: an open‑source coding agent that can read project files, propose edits and run commands such as the test suite. Its configuration prompts for permission before edits or shell commands.
  • Ollama: a local model service that runs the model on the machine. OpenCode directs model requests to Ollama’s local API.
  • Qwen3.5 9B: an open‑weight model downloaded and run locally for this walkthrough.

OpenCode handles the project interaction and tool usage; Ollama hosts the local model. The open‑weight nature of Qwen makes on‑device running feasible.

Published model results and sizes

According to Qwen’s model card, some published scores on coding benchmarks are:

  • Qwen3.5 4B: LiveCodeBench v6 = 55.8, BFCL‑V4 = 50.3
  • Qwen3.5 9B (used here): LiveCodeBench v6 = 65.6, BFCL‑V4 = 66.1
  • gpt-oss-20b: LiveCodeBench v6 = 74.6 (BFCL‑V4 not reported)

Approximate download sizes:

  • Qwen3.5 4B: ~3.3–4.0 GB
  • Qwen3.5 9B: ~6.6–7.6 GB
  • Qwen3.5 27B: ~17–20 GB

Download size is not the same as RAM requirement. For a 6.6 GB Qwen3.5 9B build, Voltti budgets 12–16 GB of memory; the OpenCode 64k‑token configuration may need additional memory headroom.

OpenCode in prior evaluations

A research preprint, "The Scaffold Effect in Coding Agents," compared OpenCode, Goose and OpenHands‑SDK on 50 Terminal‑Bench Pro tasks using two cloud models. Table 2 reported pass rates such as OpenCode: 50% [36–64%] and 46% [32–60%] on two cloud models (brackets are 95% confidence intervals). The authors note most differences were not statistically clear. The study also reported substantially higher token use for OpenCode (about 40× Goose’s tokens per solved task) in cloud runs; those results don’t directly predict local Qwen3.5 9B behavior.

Initial setup (while online)

Before going offline, follow the repository README to install tools, download the project and install OpenCode 1.19.4. The project includes example code, tests and configuration for using Qwen locally.

The opencode.json file controls OpenCode’s project configuration. In my configuration, both model and small_model select Qwen3.5 9B, and baseURL points to Ollama at http://127.0.0.1:11434/v1. Only the local provider is enabled; web tools are blocked and OpenCode asks before editing files or running shell commands.

I used two terminals:

  • Terminal A: run OpenCode and tests from the project folder.
  • Terminal B: start Ollama and keep it running on localhost, disabling Ollama’s cloud features:

OLLAMA_HOST=127.0.0.1:11434 OLLAMA_NO_CLOUD=1 OLLAMA_CONTEXT_LENGTH=65536 ollama serve

Then pull the model locally:

ollama pull qwen3.5:9b

Verify the agent responds before disconnecting from the network.

Example: fixing a bug in an expense calculator

The example program adds five expenses (one is a refund); the correct total is 25.50. The starting program printed 8.00 because the function overwrote the total on each iteration.

Running the repository tests (python3 -m unittest -v) showed three failing cases: decimal arithmetic, refunds and the sample expenses. Empty and single‑item inputs already passed.

While still online, I opened OpenCode with the --pure option (disables external plugins) so the behavior would be consistent when disconnected:

.tools/node_modules/.bin/opencode --pure

I asked OpenCode to read expense_total.py and run the tests, and to explain the bug without editing files. The agent found the tests and requested permission to run the test command. It initially proposed pytest even though the project used unittest — a reminder to provide the exact test command (python3 -m unittest -v) to avoid detours.

Turning off the internet and confirming local service

I turned off Wi‑Fi and disconnected any Ethernet/tethering. Localhost remained reachable. I checked Ollama’s local API:

curl --noproxy '*' --fail http://127.0.0.1:11434/api/tags

Ollama responded and listed the downloaded qwen3.5:9b model. An external request failed (Could not resolve host), confirming the environment was offline while the local service worked.

Fixing the bug offline

Restarting OpenCode in Terminal A (.tools/node_modules/.bin/opencode --pure), I asked the agent to fix the bug and run the tests without changing tests or installing packages. Qwen proposed a one‑line edit and requested permission to apply it and run tests.

The change was:

  • before: total = Decimal(amount)
  • after: total += Decimal(amount)

The agent ran the test cycle and reported five passing tests. I then ran python3 -m unittest -v manually and confirmed all five tests passed. The saved source contained total += Decimal(amount) and the test file remained the same; the sample program now returns 25.50.

Additional exercises and next steps

The companion project includes two further exercises I haven’t yet completed offline with the agent:

  • CSV report: complete examples/csv-report/csv_report.py to group rows by product, calculate quantities and revenue, and produce a readable report. The example contains sample data and seven tests covering grouping, decimal arithmetic, ordering and empty input.
  • Log analyzer: fix examples/log-analyzer/log_analyzer.py where bugs affect error counting and selecting the slowest request; its seven tests cover malformed lines and empty input.

Each walkthrough provides exact test commands and expected results; run them with the same local setup and then inspect diffs and test output.

Practical tips for offline coding-agent use

  • Prepare both the project and the model in advance: download dependencies and keep necessary documentation on disk.
  • Launch the exact local setup once while online so runtime components and the model are available.
  • Give the agent the precise test command to avoid unnecessary detours (for example, python3 -m unittest -v).
  • Keep tasks small and focused; review diffs and run tests yourself. Leaving tests unchanged helps ensure a passing result validates the intended behavior.
  • Monitor memory pressure: model download is only part of memory use; large context windows and other apps consume RAM.
  • Record attempts that need help: permission prompts, retries and failures are useful for debugging and future guidance.

Lessons learned

Seeing the tests pass after turning Wi‑Fi off answered the central question: a coding agent can read a local file, make a change and run checks without an internet connection, provided the model and project artifacts are present locally. I still reviewed the edit and ran the original tests myself. For practical offline usage, start with small, self‑contained tasks; larger repositories or unfamiliar frameworks remain open questions, and the CSV report is the next useful check beyond a one‑line fix.