Skip to main content
Use your Mobile Device Management (MDM) system to connect every employee’s coding agents to the TrueFoundry AI Gateway. You write one configuration file, mdm.toml, that lists the agents, models, sign-in method, MCP servers, and Skills to deploy. A script that your MDM runs on a schedule runs the tfy-local-ai-setup binary, which applies that file on each device and keeps it applied. This guide is for IT administrators. To connect agents on your own computer without MDM, see Set Up Your IDEs.

How it works

On each run, the binary:
  1. Writes managed settings that employees cannot edit: the gateway URL, models, sign-in, MCP servers, and policy for each agent. It locks the Claude Code, Codex, and Claude Desktop files, its own policy file (agents-policy.json), Cursor hooks, and other agents’ managed settings (chflags schg on macOS, chattr +i on Linux, an admin-only ACL on Windows).
  2. Writes user settings for agents that have no managed settings, installs Skills in each agent’s Skills folder, and adds a shell block for agents that read the gateway from environment variables. Employees can edit these files; the next run reapplies them. The first time the binary edits an existing user file, it keeps the original as a .bak copy. For every path, see Files written.
  3. Signs the employee in and refreshes their credential, so no shared API key is ever distributed.
Each request is attributed to the individual employee in the gateway. The binary does not install the agents themselves and does not create a schedule; your MDM handles both.

Supported agents

Managed settings are machine-wide and locked; employees cannot edit them. User settings are in the employee’s home directory; employees can edit them, and the next run reapplies them. Skills are always per-user. All agents are supported on macOS, Linux, and Windows except Claude Desktop. Native Windows deployment does not configure WSL unless you pass --wsl. For each agent’s extra options, see the configuration reference.

Before you start

  • An MDM that runs scripts as root on macOS/Linux or as Administrator/SYSTEM on Windows, on a schedule. Jamf, Kandji, Mosyle, Intune, SCCM, Group Policy, and configuration tools such as Ansible, Chef, or Puppet all work.
  • Your connection details: the TrueFoundry control-plane URL (the address of your TrueFoundry console), your tenant name, and the gateway base URL. Copy the gateway URL, including any /api/llm path, from a Playground code snippet.
  • Gateway models that employees can access. Claude Code needs Opus, Sonnet, and Haiku tier models. Codex needs a Virtual Model with a bare OpenAI model slug, such as gpt-5.4.
  • Identity controls in your vendors’ consoles. Enforce SSO in Claude and in OpenAI so employees cannot fall back to personal accounts.
  • The agents, installed separately. You can deploy the configuration before or after installing them.

Choose how employees sign in

Every employee signs in with their own TrueFoundry identity. Choose one method for your rollout: Start with device login unless your security team requires OIDC.

Set up OIDC sign-in

Skip this section if you use device login. With OIDC, no credential is written into the agents’ configuration. Claude Code and Codex ask the installed tfy-local-ai-setup binary for a token when they need one, and Claude Desktop signs in itself. One public OIDC client, with no client secret, serves all three agents. Other agents, such as OpenCode or Gemini CLI, and Cursor monitoring do not ask for tokens on demand; the first MDM run signs the employee in for them, as described in What employees see.
Claude Desktop 2.7032.0 or later is required on every device before you roll out OIDC. These settings replace the older interactive and inferenceGatewayOidc pair, which the binary removes on its next run. The issuer, client ID, scopes, and token type stay the same.

Create the OIDC client

1

Create a Personal Access Token

Create a Personal Access Token as a user with the Manage settings permission on the tenant. You need it only to create the client.
2

Create the client

Replace the control-plane URL and token, then run:
On a self-hosted control plane, use its URL; the path stays /api/svc/v1/oidc/clients.
  • Redirect URIs: Claude Desktop uses http://127.0.0.1/callback. The binary, which signs in for Claude Code and Codex, listens on port 8585, or on 8586 or 8587 if that port is busy.
  • refresh_token_ttl sets how long an employee stays signed in without using an agent. With refresh_token_max_uses: 1, each refresh issues a new refresh token.
3

Copy the client ID

The response looks like { "data": { "id": "cli_...", "manifest": { ... } } }. data.id is the client ID.Sending the request again with the same manifest.name updates the client and keeps its ID. client_type cannot be changed after creation.
4

Find the issuer

The issuer is your control-plane URL followed by /<tenant>, for example https://<tenant_name>.truefoundry.cloud/<tenant_name>. Open <issuer>/.well-known/openid-configuration and copy its issuer value exactly.
5

Add OIDC to mdm.toml

When you write mdm.toml, replace its [auth] table:
The client ID is public, so it is safe in the script. To use OIDC for only some agents, keep mode = "api-key" and set auth = "oidc" in the [agents.claude-code], [agents.codex], or [agents.claude-desktop] table. All additional agents must use the same mode.

What employees see

  • MDM runs write the configuration for Claude Code, Codex, and Claude Desktop without opening a browser. If you also deploy additional agents, such as OpenCode or Gemini CLI, or Cursor monitoring, the first MDM run signs the employee in once through the browser.
  • Claude Code and Codex open a browser sign-in the first time they need a token. Later requests reuse the cached access token, or refresh it silently, without a browser.
  • Claude Desktop asks the employee to sign in on first launch and keeps its own session.
  • When the refresh token expires, after refresh_token_ttl without use, the next request opens the browser again.

What OIDC writes

  • Claude Code: apiKeyHelper in managed-settings.json runs tfy-local-ai-setup --_print-oidc-token.
  • Codex: [model_providers.truefoundry.auth] has a command that runs the binary with --_print-oidc-token.
  • Claude Desktop: inferenceCredentialKind = external-idp and inferenceIdpOidc = {"bearerTokenType":"access_token","clientId":"<client-id>","issuer":"<issuer>","scopes":"openid profile email offline_access"}.
No token is stored in any of these files. The binary caches tokens in the employee’s ~/.tf/oidc-* files, separate from device login’s ~/.tf/refresh-token. For each agent’s file paths, see What gets written for Claude Code and Claude Desktop and for Codex. Keep the Claude Desktop defaults:
  • bearerTokenType must be access_token. The gateway validates access tokens and rejects ID tokens, which are Desktop’s default.
  • Keep openid in the scopes, or Desktop’s sign-in fails. Desktop still sends the access token to the gateway.
The binary flags --oidc-bearer-token-type and --oidc-scopes change these values; leave them at their defaults for TrueFoundry.

Limitations

Deploy to a pilot device

Test on one device per operating system, with an employee who is logged in and available to complete a browser sign-in.
On a device that already has a TrueFoundry rollout, mdm.toml replaces what the binary manages there. For example, a file without mcp_servers removes the gateway MCP servers an earlier rollout deployed, and one without [monitoring.cursor] removes its Cursor hooks. Before you run on such a device, copy the existing settings into mdm.toml: MCP servers, Cursor monitoring, prompt blocks, and the Claude Code policy. Then preview the changes with a dry run, sudo DRY_RUN=true ./deploy-mdm.sh, as described in Preview before applying below.
1

Write mdm.toml

Copy this file and edit it. It contains every setting you are likely to need: the active lines are a working rollout of Claude Code and Codex, and every other setting is commented out with what it does and its default. To turn a setting on, remove the #. To use a setting under a commented [table] line, uncomment that table line too. An agent is deployed only when its [agents.<id>] table is present.
mdm.toml
Before you deploy:
  • Replace control_plane_url, tenant_name, and gateway_url with your connection details.
  • Replace the model IDs with gateway models your employees can access.
  • Keep a table only for each agent you deploy. Claude Code, Codex, Claude Desktop, and agents with managed settings are configured even before they are installed.
  • Optional: uncomment the Claude Code policy to set your own. Without it, the binary keeps the policy in an existing managed-settings.json, or applies a built-in baseline. See Set the Claude Code policy.
Unknown keys and duplicate tables fail validation. A few rarely needed options, such as per-agent token limits and wire protocols, are listed only in the configuration reference, with each field’s type, default, and accepted values. Files in the older layout, with url, tenant, and tools, still work; see Older file layout.
2

Create the deployment script

The script installs a pinned tfy-local-ai-setup release, checks it against the release’s checksums, and stops if they are missing or do not match. It then writes your mdm.toml and runs the binary. Copy the script for your platform and paste your mdm.toml into the Configuration section at the top.
deploy-mdm.sh
Keep RELEASE_TAG the same across your rollout. To upgrade, change it and redeploy the script.
3

Run it through your MDM

Add the script to your MDM and run it once on the pilot device while the employee is logged in.With device login, the run opens a browser sign-in in the employee’s session if they have not signed in before. Ask them to complete it while the run is in progress. The binary then writes each agent’s configuration in the same run.With OIDC, a run that configures only Claude Code, Codex, and Claude Desktop writes the configuration without opening a browser, and the employee signs in later from the agent. With additional agents or Cursor monitoring, the run also signs the employee in once. See What employees see.Checkpoint: the MDM reports exit code 0, and neither the script’s output nor the log file (/var/log/tfy-mdm-setup.log, or C:\Program Files\TrueFoundry\mdm-setup.log) shows errors. Some errors appear only in the script’s output, so always check the exit code. If sign-in failed or timed out, run the script again when the employee is available. See Exit codes.
Run the script with a dry run from an administrator terminal: sudo DRY_RUN=true ./deploy-mdm.sh. On Windows, set $DryRun = $true in the script. The preview prints each agent’s changes without writing them.A dry run still signs the employee in when needed, and its output can include their live credential. Do not share it.
4

Check that the settings are locked

Confirm the managed files exist and employees cannot change them:
Checkpoint: each file shows its lock. To check what each file contains, see Verify the deployment for Claude Code and Claude Desktop and for Codex.
5

Send a test request

Restart each agent, open a new terminal for terminal-based agents, and send:
Checkpoint: the reply arrives without an authentication or model error, and the request appears in TrueFoundry → AI Gateway → Request Logs under the employee and the expected model. A reply alone does not prove the request went through the gateway.If you deployed MCP servers or Skills, test them separately: employees authorize each MCP server inside their agent. See the FAQ.

Roll out to your fleet

  1. Widen gradually. After the pilot passes on each operating system, deploy to a small group, then to everyone.
  2. Schedule the script to run regularly, plus on demand. Each run refreshes device-login credentials and reapplies settings that employees changed, so run it often enough to refresh credentials before they expire; hourly is a common choice. On Intune, platform scripts run only once, so use Remediations or a scheduled task.
  3. Tell employees what to expect: a one-time browser sign-in, restarting their agents after the first run, and authorizing MCP servers inside each agent.
  4. Install agents in any order. Claude Code, Codex, Claude Desktop, and agents with managed settings are configured before installation. Agents configured through user settings are configured on the first run after they are installed.

Windows Subsystem for Linux

Claude Code and Codex running inside WSL read the distribution’s own /etc/claude-code and /etc/codex, not the Windows configuration. Add --wsl to the binary’s command in your script to also configure Claude Code and Codex in the employee’s WSL distributions.
  • It is off by default because reaching a stopped distribution starts it.
  • Running distributions are updated on every run; stopped ones at most once a day, so they can be up to 24 hours behind.
  • Container distributions, such as docker-desktop, rancher-desktop, and podman-machine-*, are skipped.
  • Inside WSL this routes traffic but does not enforce it: anyone who can run wsl.exe is root in the distribution.
  • WSL does not inherit Windows VPN or proxy routes, so check that the gateway is reachable from inside.
  • Prompt blocks from native Windows hooks do not cover WSL.
Verify with wsl.exe -d Ubuntu cat /etc/claude-code/managed-settings.json for Claude Code, or wsl.exe -d Ubuntu cat /etc/codex/managed_config.toml for Codex.

Exit codes

The script exits with the binary’s exit code, so your MDM can report failures:
  • 0: configuration applied.
  • 1: the run failed. Check the script’s output and the log file; the next run retries. Configuration already written stays in place if the run failed after some agents were configured.
  • 2: invalid command-line flags or arguments. Check the binary’s command in your script.
  • 3: configuration applied, but a Skill in mdm.toml does not exist. Fix the Skill reference.

Customize your rollout

The settings you are likely to need are already in your mdm.toml, commented out, and the rest are in the configuration reference. Uncomment what you need in the script’s TOML block and redeploy it. The settings below need more than one line of explanation. For agent-specific options, see:

Claude Code and Claude Desktop

Policy, MCP allowlist, models, Claude Enterprise or Team subscriptions, Desktop connectors, tool search, 1M context, claude.ai history import.

Codex

Models, ChatGPT Business or Enterprise subscriptions, MCP allowlists, Windows enforcement.

Add MCP servers and Skills

Register the resources in TrueFoundry and grant employees access first. Then set the top-level mcp_servers and skills lists in mdm.toml. Each takes one of three values:
  • Every agent gets the shared lists. Set an agent’s own mcp_servers or skills to a list to replace them for that agent, or [] to deploy nothing to it. ["@all"] is accepted only in the shared lists.
  • Pin a Skill version, as in :1, for a fixed rollout, or omit it to follow the latest version. Some agents also read other agents’ Skill folders, so an empty list does not guarantee a Skill is hidden in that agent.
  • Deployed MCP servers are added alongside servers the employee added. To block other servers, see restrict Claude Code to gateway MCP servers and Codex MCP allowlists.
mcp_servers = ["@all"] never opens a browser. It uses the employee’s existing sign-in, and if there is none, the whole run exits with code 1 and writes nothing, so a new employee is never signed in. Roll out with a fixed list first, and switch to ["@all"] after employees have signed in. skills = ["@all"] does not block the rest of the configuration; it is retried on later runs.
With ["@all"], a failed lookup keeps the existing configuration and retries on the next run. A successful lookup that finds nothing removes the resources it deployed earlier.

Monitor Cursor activity

Cursor monitoring requires TrueFoundry AI Gateway v0.185.0 or later. Older gateways don’t accept these events.
With [monitoring.cursor] enabled, the binary installs managed Cursor hooks that send prompts, agent responses, tool and MCP events, and session events to <gateway>/hooks/cursor with the employee’s credential. These events can contain prompt and tool content. Monitoring does not change Cursor’s model routing.
  • require_login = true blocks agent prompts and tool and MCP calls when no credential is available. Delivery failures and gateway verdicts never block.
  • To remove the hooks, set enabled = false or delete the table, and run the script again.
  • For monitoring only, mdm.toml still needs at least one agent table. Add [agents.cursor] with mcp_servers = [] and skills = [], so nothing else is deployed to Cursor. Without those two lines, Cursor also gets the shared MCP servers and Skills.

Block an agent

Supported for Claude Code, Codex, and Cursor. List the agents in [restrictions] blocked_agents to stop employees from submitting prompts in them.
  • message is what employees see when a prompt is blocked. If unset, they see “Your organization has disabled this application. Please use an approved alternative or contact your administrator.”
  • To remove every block, set blocked_agents = []. If you delete the [restrictions] table instead, the blocks from the last run stay in place.
  • It blocks new prompts, not launching the app, manual editing, or Cursor Tab completions. Claude Code needs version 2.1.295 or later, and Codex may ask employees to trust the hook in /hooks.

Monitor usage

Once agents route through the gateway, every model request and MCP tool call is logged with the employee, model, server, and tool, with no extra instrumentation.

Data retention

The gateway controls what is logged and where it goes, including request logging and audit, independent of any setting on the device. Local transcripts and retention on the providers’ side are set separately:
  • Claude: transcriptRetentionDays in the Claude Code policy deletes local transcripts; 7 to 14 days is a common choice. Anthropic-side retention, Zero Data Retention, and compliance are configured with Anthropic; see Claude’s data retention documentation.
  • OpenAI: retention of prompts and outputs is governed by your agreement with OpenAI, and differs between API usage and ChatGPT subscription plans. See OpenAI’s managed configuration documentation for the admin controls on your plan.

Update a rollout

Edit the TOML block or RELEASE_TAG in your script and redeploy it. The next run applies the change; restart agents that read settings at launch. Each run makes the device match mdm.toml, so preview larger changes with a dry run on a pilot device first. MCP servers and Skills that are no longer selected are removed, while entries employees added themselves are kept.

Troubleshooting

For agent-specific issues, see Troubleshooting for Claude Code and Claude Desktop and for Codex. When you contact support, share your TOML and the relevant log lines. Do not share files from ~/.tf, dry-run output, or generated agent settings, which can contain credentials.

FAQ

No. With device login, the browser opens on the first run and again only after 30 days without a successful run. With OIDC, MDM runs open a browser at most once, on the first run, and only if you deploy agents other than Claude Code, Codex, and Claude Desktop, or Cursor monitoring. See What employees see.
With device login, run the MDM script again while the employee is available. With OIDC, the employee uses Claude Code or Codex again to get a new sign-in; they do not need to wait for the next MDM run.
No. Employees authorize each server inside their agent, for example with /mcp in Claude Code or codex mcp login <server-name>.
They cannot edit locked managed settings; user settings they edit are reapplied on the next run. The gateway setting alone does not block direct access to other providers, so use network controls if you need that.
The run exits with code 1, and the next scheduled run retries once an employee is logged in.
Yes, for agents that IT does not manage. Personal setup leaves IT-managed agents alone.

Reference

Configuration reference

Every mdm.toml field, CLI flag, version requirement, and file path.

Claude Code and Claude Desktop

What MDM writes for Claude Code and Claude Desktop, and how to verify it.

Codex

What MDM writes for Codex, and how to verify it.