Codex - Using Tabs vs. Spaces

I :heart: Codex, but have run into a single problem that I just can’t seem to prompt around.

Specifically, I am working in a codebase that uses tabs and not spaces. No matter what I put in the AGENTS.md file or the other markdown documentation, it just refuses to use tabs instead of spaces. I put it in multiple places. I used asterisks. I’ve used capitals and it still won’t default to tabs.

When providing feedback on each PR, I can often have it fix the mistake while I point to the code styling documentation, so it definitely knows how to do it, but even then it sometimes misses places.

I’m at a loss. Any tips from others in similar codebases?

That’s a classic frustration when working with AI code assistants like Codex or ChatGPT—getting them to consistently respect tabs instead of spaces can be tricky.

Here are some practical tips to improve how Codex or ChatGPT outputs tabs rather than spaces:

  1. Explicitly Specify in the Prompt
    Make your prompt or instructions very explicit and upfront. For example:

“Please use tabs (not spaces) for indentation throughout all code snippets.”

  1. Use Code Comments or Docstrings to Reinforce
    Inside the code snippet, add a comment at the top:
    Use tabs for indentation, no spaces
    This sometimes helps nudge the model.
  2. Include a Minimal Example with Tabs
    Show a short snippet with tabs in your prompt. Models tend to mimic examples.
    Example:
    def example():
    ↹print(“This uses tabs”)
    (Here, ↹ means a literal tab character)
  3. Avoid Markdown Code Blocks That May Normalize Spaces
    Some markdown or editors convert tabs into spaces visually or when copied. Make sure your environment actually retains tabs.
  4. Post-Processing
    If you can’t control it 100% from the prompt side, consider a post-processing step that converts leading spaces to tabs based on your tab size.
  5. File Configuration & Editor Settings
    Make sure your editor or your project config (like .editorconfig) is set to prefer tabs, so even if the AI slips, the editor auto-corrects on save.
  6. Fine-tune or Custom Instructions
    If you have an option to customize the model or agents configuration, reinforce tab usage there. Although you mentioned trying AGENTS.md, double-check placement and formatting.
  7. Feedback on PRs
    You’re already doing this — continue prompting fixes on each PR. Sometimes multiple passes help.
    If you want, I can help draft a specific prompt template or a small script to convert spaces to tabs automatically after generation, if you’re interested? Also curious—what language or framework are you mostly coding in? Sometimes conventions vary.

Alas, I have tried all of these. Still not working on multi-file tasks.

I had a “no duh” moment this past weekend on this one. I haven’t tried it just yet, but wanted to share – add a linter.

I think if I just add a linter and tell Codex to always use the linter before submitting code, it will eliminate the lack of clarity for it around tabs vs. spaces because the linter will return clear errors that it will need to fix, particularly if the linter can auto-correct the spaces and replace them with tabs. I’m almost certain this will work, but adding the linter will take a little bit, so I didn’t want to wait before posting.