﻿---
title: "根目录认错时改 project_root_markers，空列表等于就地当根"
summary: "默认向上找到含 .git 的目录。非 Git、嵌套仓、只想盯当前子目录时改这个顶层键。空数组不再往上搜。"
category: config
level: intermediate
surfaces: [cli, app, ide]
tags: ["project_root_markers", "AGENTS.md", "config.toml"]
canonical: /tips/project-root-markers/
---

# 根目录认错时改 project_root_markers，空列表等于就地当根

默认向上找到含 .git 的目录。非 Git、嵌套仓、只想盯当前子目录时改这个顶层键。空数组不再往上搜。

Codex 从 cwd 往上走，碰到项目根才加载 `.codex/` 和 `AGENTS.md`。默认标记是 `.git`。在 monorepo 子包、Hg/Sapling 仓、或没有 Git 的一次性目录里，根会认错，表现为项目配置根本没加载。

```toml
project_root_markers = [".git", ".hg", ".sl"]
```

只要当前目录、不要继承父仓：

```toml
project_root_markers = []
```

空列表会**跳过**父目录搜索，把 cwd 当成根。这是顶层键，不要写进 `[tui]`。

核对：新开会话后看 `/status` 的工作区路径，以及项目 `.codex/config.toml` 是否真的进了 `/debug-config`。父目录有 `.git`、子目录才是你的任务时，空列表比再写一份 AGENTS.md 更直接。

## 来源

- [OpenAI · Advanced configuration](https://learn.chatgpt.com/docs/config-file/config-advanced)
