How to Configure Agent-Specific Profiles with Different Trust Levels in dcg
Configure agent-specific profiles in dcg by creating [agents.<name>] tables in your TOML configuration files, setting trust_level to high, medium, or low, and optionally specifying additional_allowlist, extra_packs, or disabled_packs to customize command filtering per AI agent.
Dicklesworthstone/destructive_command_guard (dcg) enables granular security policies by recognizing which AI coding agent is invoking commands and applying tailored trust levels. By configuring agent-specific profiles, you can grant trusted internal agents permissive access while enforcing strict restrictions on unknown or external agents. This profile-based system operates through standard TOML configuration files that override global defaults at runtime according to the logic in src/config.rs.
How dcg Detects AI Agents
According to the source code in src/config.rs and as documented in docs/agents.md, dcg automatically identifies the calling agent by inspecting environment variables such as CLAUDE_AGENT at startup. If detection fails, the system defaults to an unknown agent profile. This detection mechanism ensures that the appropriate trust level and rule set are applied before any command evaluation begins.
Creating Agent Profiles in TOML Configuration
Agent profiles reside under [agents.<agent_name>] tables within dcg's hierarchical configuration system, as defined in docs/configuration.md. You can define these profiles at the project level in .dcg.toml (repository root) or globally in ~/.config/dcg/config.toml.
Project-Level Agent Configuration
Create a .dcg.toml file at your repository root to enforce repository-wide policies that travel with your codebase. This approach ensures consistent behavior across all team members using different AI agents.
# Global pack configuration (applies to all agents unless overridden)
[packs]
enabled = ["core.git", "core.filesystem"]
# Agent-specific configuration for Claude Code
[agents.claude-code] # Detected name for Claude Code
trust_level = "high" # Give Claude Code a permissive stance
additional_allowlist = [
"npm run build", # Allow repeated build commands
"git status" # Permit harmless Git introspection
]
[agents.unknown] # Fallback for any unrecognised agents
trust_level = "low" # Be strict by default
extra_packs = ["paranoid"] # Activate the very strict “paranoid” pack
disabled_packs = ["core.git"] # Optionally disable a pack for unknown agents
User-Level Agent Overrides
For personal preferences that apply across multiple projects, add profiles to ~/.config/dcg/config.toml. These settings merge with project-level configurations following dcg's precedence rules.
[agents.my-custom-agent]
trust_level = "medium"
extra_packs = ["containers.docker"]
Assigning Different Trust Levels and Overrides to Agent Profiles
Each agent profile supports four key fields that modify dcg's default behavior. According to src/allowlist.rs and src/packs/mod.rs, these fields are resolved at runtime and override global settings.
- trust_level: Controls default severity thresholds. Set to
highto reduce false positives for trusted agents,mediumfor balanced enforcement, orlowfor aggressive blocking of potentially destructive commands. - additional_allowlist: A list of exact command strings permitted for this agent even if they match destructive patterns in the global rule set.
- extra_packs: Activates additional rule packs specifically for this agent, useful for adding domain-specific restrictions.
- disabled_packs: Removes global rule packs for this agent only, effectively relaxing security for trusted workflows.
Configuration Precedence and Runtime Behavior
As implemented in src/config.rs, dcg reads global configuration first, then applies agent-specific overrides if a matching [agents.<name>] table exists. This merge happens at invocation time without requiring daemon restarts.
The precedence hierarchy follows:
- CLI flags and environment variables (highest priority)
- Agent-specific profile settings (
[agents.<name>]) - Global configuration sections (
[packs], etc.)
When you invoke dcg with an explicit agent identifier, the system loads the corresponding profile immediately:
DCG_CONFIG=/path/to/.dcg.toml DCG_AGENT=claude-code dcg test --format json "git push --force"
In this example, dcg applies the claude-code profile from the specified configuration, permitting the high-risk command if the profile's trust_level and additional_allowlist allow it.
Summary
- Agent detection relies on environment variables like
CLAUDE_AGENT, falling back tounknownwhen unspecified. - Profile definition occurs in
[agents.<name>]tables within.dcg.tomlor~/.config/dcg/config.toml. - Trust levels (
high,medium,low) control the strictness of command evaluation per agent. - Additional allowlists and pack overrides (
extra_packs,disabled_packs) fine-tune rule enforcement without modifying global policies. - Runtime precedence ensures agent profiles override globals but yield to CLI flags, with changes taking effect immediately on the next invocation.
Frequently Asked Questions
How does dcg determine which agent profile to use?
dcg inspects environment variables such as CLAUDE_AGENT during initialization to identify the calling AI agent. If no matching environment variable is present, it defaults to the unknown agent profile. You can also force a specific profile by setting the DCG_AGENT environment variable before invocation.
Can I disable specific destructive pattern packs for only one agent?
Yes. Use the disabled_packs field in an agent profile to remove global rule packs for that specific agent. For example, setting disabled_packs = ["core.git"] under [agents.claude-code] allows that agent to run Git commands that would normally be blocked, while other agents remain restricted according to the global configuration.
What happens if I specify both extra_packs and disabled_packs in the same profile?
dcg resolves both fields during configuration merging in src/packs/mod.rs. The system first applies global pack settings, then adds extra_packs and removes disabled_packs. If a pack appears in both lists, the disable operation typically takes precedence, though you should avoid such conflicts in your configuration.
Do agent profile changes require restarting dcg?
No. dcg reads configuration files at each invocation, so changes to .dcg.toml or ~/.config/dcg/config.toml take effect immediately on the next command execution. This applies to trust levels, allowlists, and pack configurations without requiring daemon restarts or service reloads.
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:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →