Skip to content

fix(config): strip ANSI escape sequences from model names#114

Merged
tjb-tech merged 1 commit intoHKUDS:mainfrom
jiakeboge:fix-ansi-escape-in-model-names
Apr 11, 2026
Merged

fix(config): strip ANSI escape sequences from model names#114
tjb-tech merged 1 commit intoHKUDS:mainfrom
jiakeboge:fix-ansi-escape-in-model-names

Conversation

@jiakeboge
Copy link
Copy Markdown
Contributor

Summary

This PR fixes an issue where ANSI escape sequences in the ANTHROPIC_MODEL or OPENHARNESS_MODEL environment variables would cause API requests to fail with 404 errors.

Problem

When users set the model environment variable in a terminal with formatting (e.g., bold text), ANSI escape sequences like \x1b[1m (bold) and \x1b[0m (reset) can be inadvertently included. This results in the API receiving an invalid model name like claude-opus-4-6[1m] instead of claude-opus-4-6.

Fixes #113

Changes

  • Added strip_ansi_escape_sequences() helper function in settings.py to remove ANSI escape codes from text
  • Updated _apply_env_overrides() to strip ANSI sequences from model environment variables
  • Updated merge_cli_overrides() to strip ANSI sequences from CLI --model argument
  • Added comprehensive tests in TestAnsiEscapeSequences test class

Testing

# Test with ANSI escape sequences
export ANTHROPIC_MODEL=$'\x1b[1mclaude-opus-4-6\x1b[0m'
uv run oh
# API requests now work correctly with clean model name

Checklist

  • Added helper function with docstring
  • Applied sanitization to environment variable overrides
  • Applied sanitization to CLI argument overrides
  • Added unit tests for the new functionality
  • All existing tests pass

When setting ANTHROPIC_MODEL or OPENHARNESS_MODEL environment variables
in terminals with formatting (e.g., bold text), ANSI escape sequences like
\x1b[1m can be inadvertently included in the model name. This causes the
API to receive an invalid model name like 'claude-opus-4-6[1m]' instead of
'claude-opus-4-6', resulting in a 404 error.

Changes:
- Add strip_ansi_escape_sequences() helper function
- Apply stripping in _apply_env_overrides() for env vars
- Apply stripping in merge_cli_overrides() for CLI args
- Add comprehensive tests for ANSI escape handling

Fixes HKUDS#113
@tjb-tech tjb-tech merged commit 565e6f1 into HKUDS:main Apr 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: ANSI escape sequences in ANTHROPIC_MODEL env var cause API 404 errors

2 participants