AI Learn
Anthropic · Claude Code Tutorial

Set Claude Code permissions before an agentic coding task

Use allow, ask and deny rules to reduce accidental writes and dangerous commands while keeping a real coding workflow usable.

Reviewed September 19, 2026Independent tutorialFeatures may vary
Not official support. AI Learn is an independent education site and is not affiliated with Anthropic. Check the provider’s current documentation for plan-specific limits, pricing and feature availability.
Before you start

Permissions are a security boundary, not a prompt preference. Start restrictive, then allow only the operations that a specific repository and task genuinely need.

1. Map the task’s required capabilities

Write down what the task needs: read files, edit source, run tests, access the network, invoke package managers or touch deployment configuration.

2. Deny obvious high-risk operations

Block secrets, credential files, destructive shell commands, production deployment and unrelated directories unless the workflow explicitly requires them.

3. Use ask for ambiguous actions

Actions that may be legitimate but expensive or risky—installing dependencies, broad shell commands, network access—should pause for approval rather than being always allowed.

4. Allow routine narrow actions

Let safe repeated commands run without friction when you understand them: reading the repository, editing within the workspace, running a known test target.

5. Run one boundary test

Ask Claude Code to describe what it is allowed to do, then try a harmless action in each category. Confirm denied actions really stop and approval prompts appear where expected.

Try this prompt

Before starting, summarize the filesystem, command and network permissions available in this session. If an action is outside the routine test/edit workflow, ask before doing it. Never read credential files or deploy production.

Common mistakes

Using a prompt to “forbid” something that should be enforced by permissions; globally allowing a shell wildcard; granting network access by habit; forgetting that repository trust can change.

Finish check

Routine repository work is smooth, but secrets, destructive commands, production changes and unexpected network actions are blocked or require explicit approval.

开始之前

权限是安全边界,不只是提示词偏好。默认先保守,再只开放当前仓库和任务真正需要的操作。

1. 先列出任务真正需要的能力

写清这次任务需要什么:读文件、改源码、运行测试、访问网络、调用包管理器,还是接触部署配置。

2. 先拒绝明显高风险操作

默认禁止读取密钥、凭证文件、破坏性 Shell 命令、生产部署和无关目录,除非当前任务确实需要。

3. 不确定的动作放到 ask

安装依赖、范围很大的 Shell 命令、网络访问等可能合理但有成本或风险的动作,优先设为需要批准,而不是永久允许。

4. 只对日常窄动作放行

你已经理解并且经常重复的安全动作可以减少摩擦,例如读取仓库、在工作区内编辑、运行已知测试目标。

5. 实际做一次边界测试

让 Claude Code 先总结它现在能做什么,然后分别尝试一个安全的 allow、ask、deny 示例,确认拒绝真的会阻止,审批也会在正确位置出现。

可以直接套用的提示词

开始前请总结本会话的文件系统、命令和网络权限。超出常规“检查/编辑/测试”工作流的动作先询问我;不要读取凭证文件,也不要执行生产部署。

常见错误

应该靠权限强制限制的事情只写在提示词里;用过宽的 Shell 通配规则永久放行;习惯性打开网络;忘记同一个仓库的可信程度也会变化。

完成检查

完成后,常规仓库操作仍然顺畅,但密钥、破坏性命令、生产改动和意外网络行为会被阻止或要求明确批准。

開始之前

權限是安全邊界,不只是提示詞偏好。預設先保守,再只開放當前倉庫和任務真正需要的操作。

1. 先列出任務真正需要的能力

寫清這次任務需要甚麼:讀檔案、改來源碼、運行測試、訪問網絡、調用包管理器,還是接觸部署配置。

2. 先拒絕明顯高風險操作

預設禁止讀取密鑰、憑證檔案、破壞性 Shell 指令、生產部署和無關目錄,除非當前任務確實需要。

3. 不確定的動作放到 ask

安裝依賴、範圍很大的 Shell 指令、網絡訪問等可能合理但有成本或風險的動作,優先設為需要批准,而不是永久允許。

4. 只對日常窄動作放行

你已經理解並且經常重復的安全動作可以減少摩擦,例如讀取倉庫、在工作區內編輯、運行已知測試目標。

5. 實際做一次邊界測試

讓 Claude Code 先總結它現在能做甚麼,然後分別嘗試一個安全的 allow、ask、deny 示例,確認拒絕真的會阻止,審批也會在正確位置出現。

可以直接套用的提示詞

開始前請總結本會話的檔案系統、指令和網絡權限。超出常規“檢查/編輯/測試”工作流的動作先詢問我;不要讀取憑證檔案,也不要執行生產部署。

常見錯誤

應該靠權限強制限制的事情只寫在提示詞里;用過寬的 Shell 通配規則永久放行;習慣性打開網絡;忘記同一個倉庫的可信程度也會變化。

完成檢查

完成後,常規倉庫操作仍然順暢,但密鑰、破壞性指令、生產改動和意外網絡行為會被阻止或要求明確批准。

Official references

Check current product details at the source

Related practical tutorials

Continue with another single-task workflow.

All tutorials →