dcg can detect which AI coding agent is invoking it and apply agent-specific trust levels and configuration overrides. This allows you to grant higher trust to well-behaved agents while maintaining strict controls for unknown ones.
| Agent | Detection Method | Environment Variable |
|---|---|---|
| Claude Code | Environment | CLAUDE_CODE=1 or CLAUDE_SESSION_ID |
| Aider | Environment | AIDER_SESSION=1 |
| Continue | Environment | CONTINUE_SESSION_ID |
| Codex CLI | Environment | CODEX_CLI=1 |
| Gemini CLI | Environment | GEMINI_CLI=1 |
Agent detection follows this priority order:
- Explicit
--agentflag: Manual override via CLI - Environment variables: Most agents set identifying env vars
- Parent process inspection: Fallback check of process tree
- Unknown: Default when no agent is detected
Three trust levels control how strictly dcg evaluates commands:
| Level | Description |
|---|---|
high |
Relaxed evaluation; agent has proven reliable |
medium |
Default; standard evaluation rules apply |
low |
Strict evaluation; extra caution for unknown agents |
Configure agent profiles in your config.toml:
# Trust Claude Code more (it sets CLAUDE_CODE=1)
[agents.claude-code]
trust_level = "high"
additional_allowlist = ["npm run build", "cargo test"]
# Restrict unknown agents
[agents.unknown]
trust_level = "low"
extra_packs = ["paranoid"]
# Default profile for unspecified agents
[agents.default]
trust_level = "medium"| Option | Type | Description |
|---|---|---|
trust_level |
string | "high", "medium", or "low" |
disabled_packs |
array | Packs to disable for this agent |
extra_packs |
array | Additional packs to enable |
additional_allowlist |
array | Commands to allowlist for this agent |
disabled_allowlist |
bool | If true, ignore base allowlist for this agent |
# In .dcg.toml (project-level)
[agents.unknown]
trust_level = "low"
disabled_allowlist = true
extra_packs = ["core", "database", "filesystem"]
[agents.claude-code]
trust_level = "medium"
additional_allowlist = ["npm test", "npm run lint"]Define profiles for custom agents by setting an environment variable:
# Set a custom agent identifier
export MY_BUILD_BOT=1Then configure in config.toml:
[agents.my-build-bot]
trust_level = "high"
additional_allowlist = ["make deploy"]When resolving which profile to use:
- Look for exact match:
agents.<agent-config-key> - Fall back to
agents.unknownif agent is unrecognized - Fall back to
agents.defaultif no specific profile exists
Use --verbose or -v to see agent detection info:
$ dcg test "git push --force" --verbose
Command: git push --force
...
Elapsed: 21.14ms
Agent: Claude Code
Trust level: medium
Severity: criticalUse -vv for detailed debug output:
$ dcg test "git push --force" -vv
...
Agent detection:
Detected: Claude Code (claude-code)
Method: environment_variable
Matched: CLAUDE_CODE
Profile: agents.claude-code
Trust level: mediumThe --format json output includes agent information:
{
"command": "git push --force",
"decision": "deny",
"agent": {
"detected": "claude-code",
"trust_level": "medium",
"detection_method": "environment_variable"
}
}Robot mode provides a unified, machine-friendly interface for AI agents. When enabled, dcg optimizes its output for programmatic consumption.
# Via flag
dcg --robot test "rm -rf /"
# Via environment variable
DCG_ROBOT=1 dcg test "rm -rf /"| Aspect | Normal Mode | Robot Mode |
|---|---|---|
| stdout | JSON or pretty | Always JSON |
| stderr | Rich colored output | Silent |
| Exit codes | Varies | Standardized |
| ANSI codes | If TTY | Never |
| Progress | Shown | Hidden |
| Suggestions | Shown | In JSON only |
In robot mode, dcg uses consistent exit codes across all commands:
| Code | Constant | Meaning |
|---|---|---|
| 0 | EXIT_SUCCESS |
Success / Allow |
| 1 | EXIT_DENIED |
Command denied/blocked |
| 2 | EXIT_WARNING |
Warning (with --fail-on warn) |
| 3 | EXIT_CONFIG_ERROR |
Configuration error |
| 4 | EXIT_PARSE_ERROR |
Parse/input error |
| 5 | EXIT_IO_ERROR |
IO error |
All robot-mode responses are pure JSON on stdout:
{
"command": "rm -rf /",
"decision": "deny",
"rule_id": "core.filesystem:rm-rf-root",
"pack_id": "core.filesystem",
"severity": "critical",
"reason": "rm -rf / would delete the entire filesystem",
"agent": {
"detected": "claude-code",
"trust_level": "medium",
"detection_method": "environment_variable"
}
}Hook mode (default when no subcommand) follows the Claude Code protocol:
- Always exits 0 (hook protocol requirement)
- JSON on stdout for denials, empty for allows
- Rich output on stderr for human visibility
Robot mode with subcommands uses standardized exit codes:
- Exit 1 for denials (allows scripting with
$?) - Pure JSON on stdout
- Silent stderr
#!/bin/bash
# Script for AI agent to check commands before execution
check_command() {
local cmd="$1"
local result
# Use robot mode for predictable output
result=$(dcg --robot test "$cmd" 2>/dev/null)
local exit_code=$?
if [ $exit_code -eq 0 ]; then
echo "Command allowed: $cmd"
return 0
elif [ $exit_code -eq 1 ]; then
echo "Command BLOCKED: $cmd"
echo "Reason: $(echo "$result" | jq -r '.reason')"
return 1
else
echo "Error checking command (exit code: $exit_code)"
return $exit_code
fi
}
# Usage
check_command "git status" # Allowed
check_command "rm -rf /" # BlockedRobot mode uses the unified OutputFormat enum:
# These are equivalent in robot mode
dcg --robot test "cmd"
dcg --robot --format json test "cmd"Available formats:
pretty/text/human- Human-readable (default without --robot)json/sarif/structured- JSON output (default with --robot)jsonl- JSON Lines (one object per line, for streaming)compact- Compact single-line output
-
Start with defaults: The default
mediumtrust level is safe for most use cases. -
Grant trust incrementally: Only increase trust for agents after observing their behavior.
-
Use project-level configs: Put agent profiles in
.dcg.tomlso they're version-controlled with your project. -
Restrict unknown agents: Always configure
agents.unknownwith lower trust in production environments. -
Review the JSON output: Use
--format jsonin CI to audit which agents are accessing your codebase. -
Use robot mode for scripting: When integrating dcg into automated workflows, use
--robotfor consistent, parseable output. -
Check exit codes: In robot mode, use exit codes to make decisions without parsing JSON for simple allow/deny checks.