# Rjv Codex Ollama Subagents

Run local Ollama models as separate Codex or opencode processes with repo tools (gemma-explorer, gemma-worker) or as a one-shot text function (ollama-chat.sh). Includes setup, Ollama serve tuning, runner scripts, and time-budget flags.

**Canonical URL:** https://skillshunter.net/skills/discovered-a4959b98de43d1b406ffed6b917ae1f9cd41ab94838e8b10

**JSON URL:** https://skillshunter.net/api/public/v1/skills/discovered-a4959b98de43d1b406ffed6b917ae1f9cd41ab94838e8b10

**Markdown URL:** https://skillshunter.net/skills/discovered-a4959b98de43d1b406ffed6b917ae1f9cd41ab94838e8b10.md

**Instructions download URL:** https://skillshunter.net/skills/discovered-a4959b98de43d1b406ffed6b917ae1f9cd41ab94838e8b10/download

**Category:** Software & Development

**Source URL:** https://github.com/rjvim/ai-skills/blob/9a942086adef21dbd0c061d9d9e8fd5f43328bf6/skills/rjv-codex-ollama-subagents/SKILL.md

**Source commit:** 9a942086adef21dbd0c061d9d9e8fd5f43328bf6

**Listing approved at:** 2026-12-03

**Created at:** 2026-12-02T09:09:37.000000Z

**Updated at:** 2026-12-03T16:19:55.000000Z

## Catalog information

The following descriptions are catalog information. Listing approval does not mean the skill has been tested or is safe for every environment.

### Editor's note

Before running, ensure Ollama is installed and serving with the tuned flags. Set `OLLAMA_CHAT_MINUTES` and `LOCAL_AGENT_MINUTES` to define time budgets for each runner. Review all generated code, as the model may miss subtle bugs.

### When to use it

- Run local Ollama models as separate Codex processes with repo tools
- Use one-shot text function for local model generation without repo tools
- Configure and tune Ollama serve with setup scripts
- Manage time budgets for model execution using environment variables

### Setup

When the user asks to configure this machine (install the `~/.codex-ollama` profile),
or wants to run local Gemma agents now and Ollama is not yet serving with the tuned
flags, read [`SETUP.md`](SETUP.md). It holds the installer, the `ollama serve`
flags and the expected model-load evidence.

## Skill instructions

---
name: rjv-codex-ollama-subagents
description: "Mechanism: run local Ollama models as separate Codex or opencode processes with repo tools (gemma-explorer, gemma-worker) or as a one-shot text function (ollama-chat.sh). Covers setup, Ollama serve tuning, runner scripts and time-budget flags. Delegation policy lives in rjv-delegate; host rungs and boxes in rjv-subagents-codex. Triggers: local Ollama, local model, gemma-explorer, gemma-worker, ollama-chat, local-codex-agent, opencode-local, one-shot local model."
---

# Codex + local Ollama

Two ways to put a local Ollama model to work:

```text
(a) Separate Ollama-backed Codex processes WITH repo tools
    main OpenAI Codex = orchestrator / reviewer
    gemma-explorer = local read-only repo scout
    gemma-worker   = local scoped coding worker
(b) One-shot local text function, NO repo tools  → see the last section
    qwen2.5-coder:14b-instruct = fast checker when Codex supplies exact context
```

**Which mode:** if the model must read files or edit through the harness, use (a),
a local Codex process. If you can hand it a complete self-contained prompt and it needs
nothing else from the repo, use (b), the one-shot runner. If you find yourself wishing
a (b) run could "check the other file", the job needs repo tools: route it to (a).

Mode (a) runs as separate processes because native subagents spawned by an OpenAI
parent inherit its provider in Codex 0.155.1, so those roles cannot switch to Ollama.

## Setup

When the user asks to configure this machine (install the `~/.codex-ollama` profile),
or wants to run local Gemma agents now and Ollama is not yet serving with the tuned
flags, read [`SETUP.md`](SETUP.md). It holds the installer, the `ollama serve`
flags and the expected model-load evidence.

## Routing and time budgets

Delegation policy lives in `rjv-delegate`; which worker to pick and the
time boxes are owned by `rjv-subagents-codex`. Every runner refuses to
start without a box: set
`OLLAMA_CHAT_MINUTES` for `ollama-chat.sh` and `LOCAL_AGENT_MINUTES` for the
explorer, worker and `opencode-local.sh`.

Local Ollama models save main-model tokens and context. Expect no wall-clock gain
from running several at once: Ollama queues concurrent requests.

## Repository-tool examples

Run from the repository root. These are separate Codex processes and can be
started in parallel by the main agent when memory allows.

```sh
RUNNER=~/.agents/skills/rjv-codex-ollama-subagents/scripts/local-codex-agent.sh

LOCAL_AGENT_MINUTES=10 $RUNNER gemma-explorer \
  "Read _docs/architecture/frontend.md. Return five bullets. Do not edit files."

LOCAL_AGENT_MINUTES=10 $RUNNER gemma-worker \
  "Edit only .plans/local-demo.md. Add three findings, read it back, and report changed files."
```

`scripts/opencode-local.sh <provider/model> "<brief>" [dir]` does the same
through a shared opencode server, from any host. It also takes
`LOCAL_AGENT_MINUTES`. It refuses to start below `OPENCODE_MIN_FREE_PCT` free
memory (default 25), and unloads every other model when more than
`OPENCODE_MAX_LOADED` (default 2) are resident.

Through the watcher: `rjv-opencode-agents` can also run a local model
(`OPENCODE_MODELS="ollama/<name>"`, the model listed under
`provider.ollama.models` in `~/.config/opencode/opencode.jsonc`). Then:

- **Context.** opencode's own system prompt and tool list take most of a
  32k window. A 32k model answered "I'm ready to help!" to a real brief
  (2026-11-30). Use a variant built with `PARAMETER num_ctx 65536`
  (`qwen3-coder-next-64k`), and give that window as the config's `limit.context`.
- **Brief small.** Ask one narrow question per file, or give a tight spec
  to type out. An open "find every bug in 600 lines" missed the HIGH. The
  same model answered "every unavailable path: throws or returns?" in 30 s and found it.
- **Text mode, code pasted.** Paste the numbered code into the brief and
  run `text`. In `repo` mode the same model read the file itself and got
  the answer wrong. With the code pasted, it listed every path correctly
  (2026-11-30, 2 min).
- **Never the gate.** A local hit is a lead. Check it against the code
  before acting.

## One-shot local text generation (no repo tools)

Mode (b): a single local HTTP call, `complete prompt in → local text out`. No
Codex, no subagents, no harness. **The local model types; you spec and review.**
From a tight spec a 30B-class model produces ~90% production-quality code at zero
token cost. It misses subtle bugs in its own and others' output, so you review and
test every result before it ships.

**Hard limits.** It is a one-shot text function. When a job needs any of the
following, use mode (a):

- It sees only the pasted prompt: no file reads, shell, web or filesystem.
- One prompt in, one answer out; no multi-turn self-correction.
- Its context is only what the prompt holds: the code, signature, conventions.
- It is weak at judgment and misses subtle and platform bugs. It is never the
  reviewer.

When a local draft is worth it at all, and why high-stakes drafts stay on a
cloud model: `rjv-delegate` §3 and `rjv-subagents-codex`.

**How to run.** Use the bundled runner (relative to this skill dir). `ollama run`
emits TTY escape codes into stdout even when redirected, so it is the wrong tool here.

```sh
OLLAMA_CHAT_MINUTES=5 scripts/ollama-chat.sh <model> <prompt-file> <out-file> [num_ctx=16384] [keep_alive=30m]
```

It calls `localhost:11434/api/chat` (non-streaming), writes the raw response to
`<out-file>`, and prints timing (`wall / prompt tok/s / output tok/s / load`). Put
prompt files in your scratchpad. `keep_alive=30m` keeps the model resident so only
the first call within that window pays load; check with `ollama ps`.

**Model choice** (`ollama list` to see what's installed):

| Class | Use for |
|---|---|
| Largest available (30B+) | code from spec, test-writing, harder extraction |
| Small/fast (7–9B) | classification, summaries, quick extraction |
| Coder variants | small code transforms |

**Writing the prompt.** Quality is won here. The model sees only the prompt file:

1. The spec, decided by you first: algorithms, edge cases, API shapes. Ask it to
   implement your design.
2. Real code context inline: the route, function or schema it must fit, plus file
   conventions (imports, error shapes, validation style). Copy actual snippets.
3. An exact output contract: "Output ONLY the code, no markdown fences." Models
   ignore the fences rule ~50% of the time, so strip fences on receipt.
4. For tests: harness conventions verbatim (imports, seeding, how to invoke).

**Verify the output yourself, every time.**

- Run it: type-check, lint, and tests with known expected values. Reading clean
  proves nothing; a spike RFC-2047 decoder read cleanly and failed 3/9 vectors.
- Review for subtle platform bugs, the class local models miss. Example: SQLite
  `LIKE` needs an explicit `ESCAPE`, and many ORMs' `like()` don't emit one.
- Keep final review and open-ended bug-hunting on the main OpenAI model. A local
  checker may challenge exact supplied code; the main model owns the conclusion.

