﻿---
title: "workspace-write 仍保护 .git / .codex / .agents"
summary: "这三处在工作区可写模式下仍只读。需要写它们时用 --add-dir 或 named permission profile，而不是直接满权限。"
category: sandbox
level: intermediate
surfaces: [cli]
tags: [".git", "sandbox", "--add-dir"]
canonical: /tips/protected-dirs/
---

# workspace-write 仍保护 .git / .codex / .agents

这三处在工作区可写模式下仍只读。需要写它们时用 --add-dir 或 named permission profile，而不是直接满权限。

这是防自我破坏：agent 不应重写自己的规则、钩子或 Git 元数据，除非你明确允许。

需要让它改 skill 或 hooks 时：

```bash
codex --add-dir .agents --add-dir .codex
```

或定义更窄的 permission profile，而不是 `danger-full-access`。

## 来源

- [Codex CLI Cheat Sheet](https://www.agenticcodingweekly.com/p/codex-cli-cheat-sheet)
