MoonshotAI / MoonshotAI/kimi-cli

Config file with UTF-8 BOM causes Invalid TOML error on startup

Open Beginner friendly
#2,043 1 comment 0 reactions 0 assignees View on GitHub

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

  1. Edit ~/.kimi/config.toml with a text editor that adds BOM on save (e.g. Windows Notepad, or certain PowerShell Out-File operations).
  2. Run any kimi command.
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.