Codex CLI with a Local Model: Config, and 12 \"expected i32\" Errors

Point Codex CLI at llama-server with a custom model_provider. On LFM2.5-24B it passed 12/12, but made 12 tool-argument type errors and recovered by retrying. The first bug-fix run took 599 s.

Config

Define [model_providers.<name>] with a base_url in ~/.codex/config.toml, then set model_provider to it. Custom providers can't use the reserved IDs openai, ollama or lmstudio. Provider keys in a project-level .codex/config.toml are ignored, so put them in your user-level config.

The config.toml we actually tested:

model = "lfm25"            # must match llama-server --alias
model_provider = "llamacpp"
model_context_window = 32768
model_auto_compact_token_limit = 28000
approval_policy = "never"
sandbox_mode = "workspace-write"

[model_providers.llamacpp]
name = "llama.cpp local"
base_url = "http://127.0.0.1:8080/v1"
env_key = "OPENAI_API_KEY"   # any dummy key in the env works
wire_api = "responses"

model_context_window tells Codex the local context is only 32K, and model_auto_compact_token_limit makes it compact early, at 28K.

For Ollama or LM Studio you can instead use codex --oss with oss_provider = "ollama". We didn't try that.

Run:

codex exec --skip-git-repo-check -s workspace-write "Fix the bugs in calc.py so pytest passes"

The server flags are the same as in the Claude Code post, and --jinja is required.

Results

Model Bug fix Timer page Pelican Tool errors
LFM2.5-24B (3 runs) 3/3, median 85 s 3/3, median 161 s 3/3, median 407 s 12
Qwen3.6-35B (1 run) 1/1, 74 s 1/1, 99 s 1/1, 268 s 0

Almost every error is the same one, an integer passed to a tool as a string:

failed to parse function arguments: invalid type: string "96787", expected i32

Codex reads the error, fixes the call and gets there in the end. LFM's first bug-fix run took 599 s, with an 85 s median; pi did the same task in 47 s.

The first request is ~6.4K prompt tokens (pi ~1.4K, Claude Code ~15.8K). Later runs show smaller numbers in the log because llama.cpp caches the prefix and counts only new tokens.

Related

FAQ

How do I connect Codex to a local model? Define [model_providers.xxx] with a base_url in ~/.codex/config.toml and set model_provider; project-level config ignores provider keys.

References