How to Configure Agent-Specific Profiles for Different AI Coding Agents in dcg

You configure agent-specific profiles in dcg by creating a TOML file with [agents.<name>] tables containing strictness, enabled_packs, and trust settings, then enabling agent_specific = true under [policy] to automatically apply the correct profile based on detected environment variables.

The dcg (Destructive Command Guard) open-source tool from Dicklesworthstone/destructive_command_guard lets you tailor security policies for each AI coding assistant in your workflow. When you configure agent-specific profiles for different AI coding agents in dcg, you can enforce strict deny modes for experimental agents while allowing warn modes for trusted tools like Claude Code or Aider. This configuration is driven by a TOML file that maps environment variables to behavioral profiles.

Where Agent Profiles Are Defined

Agent profiles live in a TOML configuration file that you specify via the --config flag or the DCG_CONFIG environment variable. By default, dcg looks for ~/.config/dcg/config.toml.

A reference implementation exists in the test suite at tests/e2e/fixtures/configs/agent_profiles.toml. This file defines a [agents.default] table and specific sections for Claude, Codex, Cursor, Copilot, Continue.dev, and Aider.

According to the source code, the profile for Claude Code appears as:

[agents.claude_code]
strictness = "high"
enabled_packs = ["git", "filesystem", "network"]
default_mode = "deny"
log_all_decisions = true
require_confirmation = true
max_warnings_per_session = 5
trust_level = 9

To enable per-agent handling, you must set agent_specific = true under the [policy] table. As shown in lines 7-10 of the test fixture:

[policy]
agent_specific = true
default_mode = "warn"
strictness = "medium"

The AGENT_PROFILES_CONFIG constant in tests/e2e/framework.rs (lines 652-660) embeds this configuration into the test harness for validation.

How dcg Detects the Current AI Agent

dcg determines which agent-specific profile to load by checking a prioritized list of environment variables. The detection logic is exercised in tests/agent_profile_comprehensive.rs (lines 41-48).

The environment variable mapping is:

  • CLAUDE_CODE → Claude Code
  • AIDER_SESSION → Aider
  • CONTINUE_SESSION_ID → Continue.dev
  • CODEX_CLI → Codex
  • GEMINI_CLI → Gemini
  • COPILOT_CLI or COPILOT_AGENT_START_TIME_SEC → Copilot
  • DCG_AGENT_TYPE → Custom agent name (fallback)

When multiple variables are present, the first match in this hard-coded order wins. You can verify this behavior in the edge cases test at lines 23-30 of tests/agent_profile_comprehensive.rs.

To bypass environment detection entirely, use the --agent <name> CLI flag. As implemented in src/cli.rs and tested at lines 66-73 of tests/agent_profile_comprehensive.rs, this flag overrides all environment variables:

dcg --agent claude_code --config ./config.toml test "git status"

Profile Configuration Structure

Each [agents.<name>] table in the TOML file supports the following settings:

Setting Type Purpose
strictness string Aggressiveness level: low, medium, or high
enabled_packs array Pattern packs to activate (e.g., ["git", "filesystem"])
default_mode string Baseline action: allow, warn, log, or deny
log_all_decisions boolean Write every evaluation to the history database
require_confirmation boolean Force user confirmation before executing flagged commands
require_bypass_confirmation boolean Require explicit confirmation for bypass operations
max_warnings_per_session integer Rate-limit for warnings shown to the agent
trust_level integer Numeric trust score (1-10); higher values relax restrictions

If a detected agent lacks a specific table, dcg falls back to [agents.default]. The merging logic resides in src/config.rs, which handles the Config::load implementation.

Loading and Merging Profiles

When agent_specific is enabled in the policy section, the configuration loading process follows these steps:

  1. Parse: dcg reads the TOML file from the path specified by --config or DCG_CONFIG.
  2. Detect: It identifies the active agent via environment variables or the --agent flag.
  3. Extract: It retrieves the matching [agents.<name>] table (case-insensitive).
  4. Merge: Missing fields in the agent-specific table inherit values from [agents.default].
  5. Apply: The final configuration drives the evaluation pipeline, determining which pattern packs are active and the default handling mode.

The trust_level setting interacts with the default_mode; high-trust agents may bypass deny restrictions for certain command categories depending on your pack configuration.

Practical Configuration Examples

Run dcg with a High-Strictness Claude Profile

DCG_CONFIG=./tests/e2e/fixtures/configs/agent_profiles.toml dcg --agent claude_code test "rm -rf /"

Effect: Applies the Claude profile with strictness = "high" and default_mode = "deny", blocking the destructive command and logging the attempt.

Override Detection for an Unrecognized Agent

dcg --agent my_custom_agent --config ./config.toml test "npm install"

Effect: Since no [agents.my_custom_agent] section exists in the TOML, dcg merges settings from [agents.default] as implemented in src/config.rs.

Adjust Trust Level via Environment Variable

DCG_TRUST_LEVEL=9 dcg test "git push --force"

Effect: Overrides the profile's trust setting to 9, potentially relaxing confirmation requirements if your configuration respects trust thresholds.

Disable Agent-Specific Handling

[policy]
agent_specific = false
default_mode = "warn"

Effect: dcg ignores all [agents.*] tables and applies the global policy uniformly, regardless of which AI agent is running.

Summary

  • Agent-specific profiles in dcg let you define custom security postures for each AI coding assistant via TOML tables.
  • Enable the feature by setting agent_specific = true under [policy] in your configuration file.
  • Detection relies on environment variables like CLAUDE_CODE and AIDER_SESSION, but you can override this with the --agent CLI flag.
  • Configuration settings include strictness, enabled_packs, default_mode, and trust_level, with undefined fields falling back to [agents.default].
  • Core implementation resides in src/config.rs and src/cli.rs, with comprehensive tests in tests/agent_profile_comprehensive.rs.

Frequently Asked Questions

What environment variables does dcg check to detect AI agents?

dcg checks CLAUDE_CODE, AIDER_SESSION, CONTINUE_SESSION_ID, CODEX_CLI, GEMINI_CLI, COPILOT_CLI, COPILOT_AGENT_START_TIME_SEC, and DCG_AGENT_TYPE. The detection order is hard-coded, and the first match wins when multiple variables are present. This logic is validated in tests/agent_profile_comprehensive.rs at lines 41-48.

How do I override the automatically detected agent?

Use the --agent <name> CLI flag to explicitly specify which profile to load. This bypasses all environment variable checks. According to lines 66-73 of tests/agent_profile_comprehensive.rs, the flag takes precedence over CLAUDE_CODE or any other detection variable.

What happens if no profile exists for the detected agent?

If dcg detects an agent (e.g., via DCG_AGENT_TYPE) but finds no matching [agents.<name>] table in the TOML file, it falls back to the [agents.default] table. The merging logic in src/config.rs ensures that missing fields inherit default values, preventing configuration errors.

Can I disable agent-specific profiles entirely?

Yes. Set agent_specific = false in the [policy] section of your configuration file. When disabled, dcg ignores all per-agent tables and applies the global policy settings uniformly to all commands, regardless of which AI assistant generated them.

Have a question about this repo?

These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:

Share the following with your agent to get started:
curl -s "https://instagit.com/install.md"

Works with
Claude Codex Cursor VS Code OpenClaw Any MCP Client

Maintain an open-source project? Get it listed too →