When your company uses Claude Code or Codex, are you handling "files the AI must not read" and "rules everyone must follow" just by writing them in AGENTS.md or CLAUDE.md? Rule files are a request to the AI, not a mechanism that enforces anything.

This article splits what you need to decide for company use into four layers and lays out, for Claude Code and Codex, what protects each one. Setting names and locations were checked against the original text of the official documentation.

Layer 1Share the rules

AGENTS.md and CLAUDE.md. Input for the AI's judgment, not enforcement

Layer 2Block with settings

Read-blocking settings and the sandbox. They stop actions regardless of the AI's judgment

Layer 3Distribute as an admin

Push company settings to everyone so personal settings cannot loosen them

Layer 4Make it visible

Check usage analytics, activity records, and data handling

The company's usage guidelines themselves (what may be entered, how violations are handled) are covered in how to create corporate AI usage guidelines. This article covers turning those guidelines into tool settings.

1. The big picture: building four layers with two tools

Here are the tools for each of the four layers, side by side for Claude Code and Codex. The names differ, but the ideas are almost the same.

LayerClaude CodeCodex
1 Sharing rulesCLAUDE.md, .claude/rules/, and an organization-wide CLAUDE.md (placed by admins). Reads AGENTS.md under certain conditionsAGENTS.md (the personal global file is ~/.codex/AGENTS.md) and skills
2 Blocking with settingsPermission deny rules + sandboxdeny in permission profiles (beta) + sandbox
3 Admin distributionmanaged settings (admin console, MDM, managed-settings.json)requirements.toml (Agent security in the admin console, macOS MDM, a file)
4 VisibilityUsage analytics dashboard, OpenTelemetry, audit logs, Compliance APICodex analytics dashboard, Analytics API, Compliance API, OpenTelemetry

Setting names, locations, and the plans they are available on were checked in each company's official documentation on November 29, 2026. They can change, so confirm them on each source page before rolling out.

The most important points

Rule files
Claude Code's official documentation also says CLAUDE.md is treated as context, not as enforced configuration. The AI can forget rules or get their priority wrong
What to block
"Don't read," "don't delete," and "don't send outside" are stopped with Layer 2 settings. Use the rule files to explain why
Enforcing for all
Admins distribute the Layer 2 settings through Layer 3. If they are only in personal files, the user can remove them

How to tell why rules are not being followed is covered in why AI ignores your rules and how to fix it.

2. Block files from being read with settings

For .env files, private keys, and customer data, the most reliable step is to keep them outside the working folder. Then use settings to block anything that has to live in the same place.

Claude Code: write deny rules and enable the sandbox

On their own, Claude Code's deny rules do not cover some shell commands. Enabling the sandbox merges the deny rule paths into OS-level restrictions as well, closing that gap.

SetupWhat it blocksWhat it does not block
Deny rules only (Read(./.env) and so on)Built-in tools such as Read, and file commands that Claude Code can recognize (cat, head, tail, sed, and so on)Commands that read without naming the file, such as grep -r. Scripts in Python or other languages that open the file
Deny rules + sandboxAll of the above, plus shell commands and the processes they start (deny rule paths are also applied to the sandbox)Things that run outside the sandbox (MCP servers, hooks, and so on; manage these with permission rules)

Here is an example .claude/settings.json shared in the project.

{
  "permissions": {
    "deny": ["Read(./.env)", "Read(./.env.*)", "Read(./secrets/**)"]
  },
  "sandbox": {
    "enabled": true,
    "allowUnsandboxedCommands": false,
    "filesystem": { "denyRead": ["~/.aws", "~/.ssh"] }
  }
}

What doesn't work

Creating a file called .claudeignore has no effect (the official documentation says so explicitly). Move those entries to deny rules

Windows caveat

The sandbox only works on macOS, Linux, and WSL2. Run natively on Windows, commands execute without a sandbox. On Windows, use it inside WSL2

Close the escape hatch

Setting allowUnsandboxedCommands: false stops commands that fail in the sandbox from being retried outside it

With nothing configured, the sandbox can read most of the computer, including ~/.ssh and ~/.aws/credentials. List credentials outside the project in filesystem.denyRead, as in the example above. In project settings, ./ in a path points to the project root.

How to write deny rules and their precedence are covered in Claude Code permission rules (allow, ask, deny), and the sandbox's scope and settings in what Claude Code sandboxing is.

Codex: write deny in a permission profile and make it the default

The Codex sandbox limits writes to the working folder, but it can read broadly. Block files you do not want read with deny in a permission profile (beta). A profile is not used just because it exists, so make it the default with default_permissions.

default_permissions = "team_workspace"

[permissions.team_workspace]
extends = ":workspace"

[permissions.team_workspace.filesystem]
glob_scan_max_depth = 3

[permissions.team_workspace.filesystem.":workspace_roots"]
"**/*.env" = "deny"

Codex deny caveats (from the official documentation)

Legacy settings
If sandbox_mode remains anywhere in the loaded configuration, permission profiles are not used and the old sandbox settings apply instead
New files
On Linux, WSL, and Windows, patterns like **/*.env are resolved from the list of files present when the sandbox starts. Files created while it is running are not blocked, and the documentation says not to rely on this
Scope
Only commands inside the local sandbox. Connectors, MCP servers, and browser actions are managed through their own settings
Removed setting
approval_policy = "untrusted" is no longer supported. If it remains, Codex may fail to start, so rewrite it following the official migration steps

Step-by-step Codex instructions, and how to confirm the setting works with a dummy file, are in how to stop Codex from reading secret files.

If you only want research or advice and do not want files modified, you can also run the tools read-only (how to use Codex and Claude Code in read-only mode).

3. Share rules across the team

Where you put a rule file decides who it reaches. Place them at three levels: company, repository, and individual.

ReachClaude CodeCodex
Everyone in the companyA CLAUDE.md placed by admins (macOS: /Library/Application Support/ClaudeCode/, Linux and WSL: /etc/claude-code/, Windows: C:\Program Files\ClaudeCode\)No documented location for an AGENTS.md distributed to everyone. What admins can place on the computer is skills (/etc/codex/skills) and requirements.toml
RepositoryThe repository's CLAUDE.md and .claude/rules/*.md (can be scoped by file type)The repository's AGENTS.md (one per folder is possible)
Individual~/.claude/CLAUDE.md and CLAUDE.local.md (if present, AGENTS.md is no longer read)~/.codex/AGENTS.md

For teams using both Claude Code and Codex, writing the rules in AGENTS.md and importing it from CLAUDE.md lets you maintain the same rules in one place.

# CLAUDE.md (for Claude Code; its content is one line that imports AGENTS.md)
@AGENTS.md

If you only have AGENTS.md

Claude Code reads AGENTS.md only when there is no CLAUDE.md (including .claude/CLAUDE.md and CLAUDE.local.md) in the working folder or the folders above it. If even one exists, AGENTS.md is not read, so import it with the line above

Rules that are too long

Codex reads AGENTS.md files only up to 32 KiB combined (the default) and truncates the rest. Claude Code's official documentation also recommends keeping CLAUDE.md short and specific

Settings can be shared too. Commit .claude/settings.json for Claude Code, or .codex/config.toml for Codex (read once each person trusts the project), to the repository, and the team gets the same defaults.

However, in both tools the user can remove these. Anything you do not want removed should be distributed through Layer 3, next.

When per-folder rules are loaded is covered in when subdirectory CLAUDE.md and AGENTS.md files are read, and distributing skills and hooks as a bundle in Claude Code plugins and marketplaces.

4. Settings admins distribute to everyone

Users can edit their personal files and the repository's settings. For settings everyone must follow, use the mechanisms admins distribute. Distributed settings take precedence over personal settings.

How to distribute

MethodClaude Code (managed settings)Codex (requirements.toml)
Admin consoleOrganization settings on claude.ai (Team, Enterprise)Agent security in the ChatGPT admin console (described in the Enterprise documentation)
MDM and OS mechanismsManaged profiles on macOS, the HKLM registry on WindowsManaged profiles on macOS. The Windows registry is not documented
Filemanaged-settings.json (in the same folder as the CLAUDE.md in the previous table)/etc/codex/requirements.toml (on Windows, %ProgramData%\OpenAI\Codex\)

Settings worth distributing

GoalClaude CodeCodex
Enforce blocked files for everyoneRead(...) in permissions.deny and sandbox.filesystem.denyRead (write paths with ~/ or as absolute paths)deny_read in [permissions.filesystem] (paths starting with ./ are not allowed)
Require the sandboxsandbox.enabled, failIfUnavailable: true, allowUnsandboxedCommands: falseSet the allowed permission profiles with allowed_permission_profiles
Ban the do-anything-without-asking modepermissions.disableBypassPermissionsMode: "disable"Leave :danger-full-access out of allowed_permission_profiles. Remove never from allowed_approval_policies
Use only company permission rulesallowManagedPermissionRulesOnly: truePersonal settings cannot loosen what requirements.toml sets
Ban dangerous commandsBash deny rules (for example, Bash(rm -rf *)). Rewording the command gets around them, so combine them with the sandboxdecision = "forbidden" in prefix_rules under [rules]
Decide which MCP servers are allowedallowManagedMcpServersOnlyDefine the allowed ones in [mcp_servers] (leaving it empty blocks them all)
Decide where extensions come fromstrictKnownMarketplaces (an allowlist of plugin sources)restrict_to_allowed_sources in [marketplaces]
Limit sign-in to company accountsforceLoginOrgUUIDallowed_login_methods, allowed_chatgpt_workspaces
Stop reports that send conversations outThe environment variable DISABLE_FEEDBACK_COMMAND=1 (conversations sent with /feedback are kept for 5 years)Not documented

Claude Code's disableBypassPermissionsMode works even when users put it in their own settings. Many other settings (such as allowManagedPermissionRulesOnly) take effect only when distributed by admins. Check the exact syntax of each setting in the official documentation listed in the sources.

Gaps that remain after distributionClaude CodeCodex
Local admin rightsIf the user is an administrator on that computer, they can edit the distributed file itself. The official documentation also suggests redistributing it periodically through MDMLikewise, files on the computer (such as /etc/codex/requirements.toml) can be edited. Files have the lowest precedence; the admin console and macOS MDM rank above them
OS differencesUsers can edit the HKCU registry on Windows, so it is not a means of enforcement. Use HKLM or a file under Program FilesOn Windows, a distributed deny_read applies only to direct file-operation tools and does not stop reads by shell commands
Fetch failuresIf admin console settings fail to download, Claude Code may run without them. With forceRemoteSettingsRefresh: true, it will not start until they are fetchedIf admin console settings fail to download and no valid cached copy exists, Codex does not start without them and shows an error

5. Visibility: usage, records, and data handling

Once settings are distributed, make sure you can check how the tools are used and how data is handled. The available features depend on the plan.

What to checkClaude Code (Claude Team, Enterprise)Codex (ChatGPT Enterprise, Edu)
Usage analyticsThe Claude Code analytics dashboard (Team, Enterprise). Enterprise also has the Analytics APIThe Codex analytics dashboard and the Analytics API
Organization activity recordsAudit logs (Enterprise only; export the past 180 days) and the Compliance API (Enterprise). Records include settings changesThe Compliance API (records such as codex_log). The official documentation states it is not a complete record of every local action
Local activity recordsOpenTelemetry. The official documentation treats it as the source data for auditing Claude Code activity. Prompt text is not sent by defaultOpenTelemetry ([otel]). The documentation recommends turning on prompt logging only when your policy allows it
Use for trainingUnder commercial terms (Team, Enterprise, API), code and prompts you send are not used to train models (unless the company has joined a program to provide them)Data on business plans is not used for training by default
RetentionThe standard is 30 days. Eligible Enterprise customers can request zero data retention (ZDR) from AnthropicOn Enterprise, Edu, and similar plans, admins can set the retention period. Deleted conversations are removed within 30 days unless the law requires otherwise

The official documentation describes Codex's admin, analytics, and records features as being for ChatGPT Enterprise and Edu. It does not say whether they are available on the Business plan.

Watch the local records too

Claude Code keeps conversation transcripts on the computer in ~/.claude/projects/, for 30 days by default and unencrypted. If a secret appears in a conversation, it stays there too. Blocking reads with settings in the first place comes first

Dashboards are not records

Codex's official documentation also says the analytics dashboards are not raw audit logs. For records you can investigate with, send OpenTelemetry data to an in-house collector or similar

How much a company can see of unauthorized AI use is covered in what shadow AI is. How to check ChatGPT and Codex training settings is in are ChatGPT and Codex conversations used for training?

6. Rollout order

You do not have to decide everything at once. Following this order means less rework.

  1. Decide what is and isn't allowed

    Decide what information may be entered and which tasks are not handed to AI (creating guidelines, precautions for input)

  2. Standardize on business plans and company accounts

    Admin settings and records do not reach personal accounts. Use the settings in section 4 so that only company accounts can sign in

  3. Create blocking settings and have admins distribute them

    Write blocked files, banned modes, and dangerous commands as Layer 2 settings, and distribute them through Layer 3. Windows computers that run Claude Code use WSL2 for the sandbox

  4. Put rule files in the repository

    In AGENTS.md (and the CLAUDE.md that imports it), write the working rules and why Layer 2 blocks what it blocks

  5. Keep records and review them regularly

    Check usage through the dashboards and records, and fix anything blocked too much or too little. Also decide on backups so you can recover after an incident

For what happens when AI gets broad permissions, see AI agent security incidents and the real-world case a PC cleanup request that deleted a folder.

7. Common misconceptions

MisconceptionRealityWhat to do
Writing "don't read .env" in CLAUDE.md or AGENTS.md is enoughRule files are not enforcedBlock it with read-blocking settings
I wrote deny rules, so it can't be read anymoreIn Claude Code without the sandbox, grep -r and scripts can still read itEnable the sandbox
It is blocked the same way on WindowsClaude Code run natively on Windows has no sandbox. In Codex, a distributed deny_read does not apply to reads by shell commandsUse Claude Code inside WSL2. With Codex, keep secrets out of the working folder
I wrote a Codex permission profile, so it's in effectIt is not used unless set as the default with default_permissions. It is also not used if sandbox_mode remainsMake it the default and remove the old settings
Repository settings can enforce rules for everyoneUsers can remove themUse admin-distributed settings
Admin settings are distributed, so nobody can remove themWith local admin rights, even the distributed file can be editedDistribute through the admin console or MDM, and restrict local admin rights

Summary

  • AGENTS.md and CLAUDE.md are requests. Things the AI must not read or do are blocked with settings
  • In Claude Code, write deny rules and enable the sandbox. On Windows, WSL2 is required
  • In Codex, write deny in a permission profile and make it the default with default_permissions
  • Distribute settings everyone must follow through admin distribution (managed settings for Claude Code, requirements.toml for Codex). If you distribute only as files on the computer, local administrators can edit them
  • Write the rules in AGENTS.md and import it from CLAUDE.md to keep one source for both tools
  • Make usage and records visible and review them regularly. Dashboards alone are not records you can investigate with

FAQ

Q. Can I use these settings on an individual plan (such as Pro)?
A. Deny rules, the sandbox, rule files, and repository settings work on individual plans too. Settings distributed from an admin console, analytics dashboards, and activity records are business features: for Claude they are on Team and Enterprise (audit logs on Enterprise only), and for Codex the official documentation describes them as being for ChatGPT Enterprise and Edu.
Q. If we use both Claude Code and Codex, do we have to write the rules twice?
A. Write the rules once in AGENTS.md and add the single line @AGENTS.md to CLAUDE.md, and they reach both tools. Read-blocking settings and banned modes, however, are written separately in each tool's settings.
Q. What is the most reliable way to keep .env from being read?
A. Don't keep it in the working folder. If it has to be there, block it with deny rules and the sandbox in Claude Code, or with deny in a permission profile in Codex, and confirm it works with a dummy file.
Q. Is company data used to train AI?
A. Anthropic says that code and prompts sent to Claude Code under commercial terms are not used to train models (unless the company has joined a program to provide them). OpenAI also says data on business plans is not used for training by default. Retention periods are set separately, so check the table in section 5.

Sources