Multi-line git commit messages use literal “\n” instead of newlines

Resolved 💬 2 comments Opened Sep 4, 2025 by paulmaunders Closed Sep 4, 2025
💡 Likely answer: A maintainer (gpeal, contributor) responded on this thread — see the highlighted reply below.

What version of Codex is running?

codex-cli 0.23.0

Which model were you using?

gpt-5 medium

What platform is your computer?

Darwin 24.6.0 arm64 arm

What steps can reproduce the bug?

Steps To Reproduce

  • In Codex CLI, ask the agent to “commit with a multi-line message” and it runs:
  • git commit -m "Subject\n\nBody"
  • View the commit in git log or on GitHub; it displays “\n” instead of actual newlines.

What is the expected behavior?

Expected

  • Multi-line messages render with real newlines:
  • Subject line
  • Blank line
  • Body text on following lines

What do you see instead?

Actual

  • Commit message contains literal “\n” characters.

Additional information

Impact

  • Reduces readability of commit history and violates conventional commit formatting (subject line + blank line + body).

Workarounds

  • Use a temp file and -F:
  • cat > .git/COMMIT_MSG_TMP << 'MSG'
  • <message with real newlines>
  • MSG
  • git commit -F .git/COMMIT_MSG_TMP

Proposed Fix

  • Default behavior: when a message contains line breaks or needs a body, always write it to a temp file and use git commit -F <file>.
  • Add a small helper in the agent:
  • Detect “\n” or multi-line content in the requested message.
  • Serialise to a temp file (e.g., .git/COMMIT_MSG_TMP), then run git commit -F.
  • Clean up the temp file afterward.
  • Training:
  • Update training or prompts to avoid recommending embedded “\n” in -m args.

Acceptance Criteria

  • Any commit created by the agent with multi-line content renders correctly with real newlines in git log and on GitHub.
  • No occurrences of literal “\n” in recent commit messages produced by the agent in test scenarios.

View original on GitHub ↗

2 Comments

gpeal contributor · 11 months ago

Try asking the model to use a separate -m per line of the commit message for now. I'll let the research team know about this behavior though.

Grimshad · 11 months ago

This doesn't only apply to git comments and is still happening. codex is adding literal \n\r directly to my code when it applies powershell edits breaking builds regularly. It also replaces emoji's in the codebase with random jibberish and symbols even though i forced it to utf8