MoonshotAI / MoonshotAI/kimi-cli
Config file with UTF-8 BOM causes Invalid TOML error on startup
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 11.4k
- Forks
- 1.3k
- Avg merge
- 9h 47m
- Merged PRs (30d)
- 2
Description
Bug Description
When config.toml contains a UTF-8 BOM (Byte Order Mark) at the beginning, kimi fails to start with:
Invalid TOML in configuration file ~/.kimi/config.toml: Empty key at line 1 col 0
Steps to Reproduce
- Edit
~/.kimi/config.tomlwith a text editor that adds BOM on save (e.g. Windows Notepad, or certain PowerShellOut-Fileoperations). - Run any
kimicommand. - The CLI crashes immediately with the above TOML parse error.
Root Cause
src/kimi_cli/config.py uses tomlkit.loads() to parse the config file, but tomlkit does not handle the UTF-8 BOM (\xef\xbb\xbf) that some Windows editors prepend to UTF-8 files. The BOM bytes are interpreted as part of the first key name, leading to the "Empty key" error.
https://github.com/MoonshotAI/kimi-cli/blob/main/src/kimi_cli/config.py#L298
config_text = config_file.read_text(encoding="utf-8")
data = tomlkit.loads(config_text) # fails if config_text starts with \ufeff
Proposed Fix
Strip the BOM before parsing:
config_text = config_file.read_text(encoding="utf-8")
if config_text.startswith("\ufeff"):
config_text = config_text[1:]
data = tomlkit.loads(config_text)
Environment
- OS: Windows 11
- Editor: Windows Notepad / VS Code with "UTF-8 with BOM" encoding
- kimi-cli version: latest
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in src/kimi_cli/config.py around the configuration loading at line 298, and inspect how config.toml is read before tomlkit.loads() parses it. Reproduce with a UTF-8 BOM-prefixed file, then verify that kimi starts successfully and still reports genuinely invalid TOML errors.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 72/100