MoonshotAI / MoonshotAI/kimi-cli

ImportError: cannot import name 'Doc' from 'typing_extensions' when project root contains a local `typing_extensions.py`

Open
#1,949 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug
Dominant language
Python
Stars
11.4k
Forks
1.3k
Avg merge
9h 47m
Merged PRs (30d)
2

Description

What version of Kimi Code CLI is running?

v1.36.0

Which open platform/subscription were you using?

Moonshot AI (Kimi)

Which model were you using?

kimi-for-coding

What platform is your computer?

Windows 10 Pro 22H2 (Build 19045) 64-bit

What issue are you seeing?

Kimi Code crashes immediately after opening a project directory that contains a local file named typing_extensions.py in its root. The internal web server fails to start due to a module shadowing conflict.

Full error message (repeated every time the process retries):

Traceback (most recent call last):
File "", line 189, in run_module_as_main
File "", line 112, in get_module_details
File "C:\Users\home\AppData\Roaming\uv\tools\kimi-cli\Lib\site-packages\kimi_cli\web_init
.py", line 3, in
from kimi_cli.web.app import create_app, run_web_server
File "C:\Users\home\AppData\Roaming\uv\tools\kimi-cli\Lib\site-packages\kimi_cli\web\app.py", line 13, in
import scalar_fastapi
File "C:\Users\home\AppData\Roaming\uv\tools\kimi-cli\Lib\site-packages\scalar_fastapi_init
.py", line 1, in
from .scalar_fastapi import (
File "C:\Users\home\AppData\Roaming\uv\tools\kimi-cli\Lib\site-packages\scalar_fastapi\scalar_fastapi.py", line 5, in
from typing_extensions import Annotated, Doc, Literal
ImportError: cannot import name 'Doc' from 'typing_extensions' (C:\Users\home\Desktop\build\serverless_app_rules\typing_extensions.py)

Image Image
What steps can reproduce the bug?
  1. Create a new project directory (e.g., serverless_app_rules).
  2. Inside the project root, create a file named typing_extensions.py. The file can be empty or contain minimal user code.
  3. Open this project directory with Kimi Code (either via kimi CLI or the GUI).
  4. Kimi Code attempts to launch its internal web server (kimi_cli.web).
  5. The process crashes with the ImportError shown above. The error repeats on every auto-retry.

Session context:

  • Working directory: C:\Users\home\Desktop\build\serverless_app_rules\
  • The local typing_extensions.py is a user project file, not the installed package.
  • Python environment: uv-managed, typing_extensions is correctly installed in site-packages.
What is the expected behavior?

Kimi Code's internal web server / language server should start successfully regardless of user project file names. The internal process should isolate its sys.path or launch from a neutral working directory so that user project files cannot shadow its own dependencies (like typing_extensions, json.py, sys.py, etc.).

Ideally, internal server startup should not be affected by filenames in the user's project root.

Additional information

Root Cause Analysis:
Python's module resolution prioritizes the current working directory (sys.path[0]) over site-packages. When Kimi Code spawns its internal web server with the user's project directory as the CWD, the local typing_extensions.py shadows the installed typing_extensions package. Since the local file does not export Doc (introduced in typing_extensions>=4.8.0), the import fails.

Workaround for users until fixed:
Rename or relocate the local typing_extensions.py file in the project root (e.g., to my_typing_extensions.py or into a sub-package directory).

Suggested Fix:
Launch the internal server process with a sanitized PYTHONPATH / sys.path, or change the CWD to a neutral location (e.g., the Kimi Code installation directory) before starting the server, preventing user files from interfering with internal dependency imports.

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 at the kimi_cli.web entry point and kimi_cli.web.app, then reproduce the failure with a project-root typing_extensions.py on Windows. Trace how the internal web server process is launched and how its working directory or import path is set. Done means the server starts successfully without user project files shadowing its dependencies.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.