Skip to main content

Subagents

Subagents allow OpsCode to delegate specialized infrastructure work to isolated domain experts. Each subagent runs with its own system prompt, isolated context window, scoped tool permissions, and domain-specific skills. Intermediate tool output—such as long terraform plan logs or schema lookups—stays inside the subagent, returning only a clean summary and modified files to your main conversation.

How subagent delegation works​

The root OpsCode agent carries 4 lightweight global skills (cloud-core, docker, kubernetes, remember) and delegates domain-specific engineering tasks to 6 built-in subagents:

Progressive skill disclosure

The 6 built-in subagents bundle 34 domain skills in total, but those skills only enter the context window when that specific subagent is invoked. If you are working on a Helm chart, Terraform and Jenkins skills consume zero tokens.

Built-in subagents​

SubagentDomainBundled skills (34 total)Embedded MCP
aws-opentofu-provisionerOpenTofu on AWS (KMS state encryption, S3/DynamoDB locking, cross-account IAM)opentofu-data-security, opentofu-iam-security, opentofu-mcp-schema-lookup, opentofu-module-layout, opentofu-state-management, opentofu-testing-validation, opentofu-vpc-networkingAWS MCP
aws-terraform-module-writerHashiCorp Terraform modules on AWS (multi-account patterns, repair loops)aws-data-security-enforcement, aws-iam-policy-engine, aws-vpc-network-patterns, terraform-iteration-patterns, terraform-mcp-schema-lookup, terraform-module-layout, terraform-repair-loopAWS MCP
infra-ansible-provisionerAnsible playbooks, roles, Vault encryption, Molecule testing, Execution Environmentsansible-code-authoring, ansible-environment-setup, ansible-execution-environments, ansible-linting-remediation, ansible-mcp-schema-lookup, ansible-runner-execution, ansible-security-operationsAnsible MCP
k8s-helm-provisionerProduction Helm charts, JSON schema validation, Pod Security Standardshelm-chart-authoring, helm-deployment-recovery, helm-schema-validation, helm-security-secrets, helm-testing—
github-actions-writerHardened GitHub Actions workflows, OIDC federation, matrix cachinggithub-actions-architecture, github-actions-performance, github-actions-security-hardening, github-actions-vulnerability-mitigation—
ci-jenkins-automaterDeclarative Jenkinsfile pipelines, Shared Libraries, Job DSL, JCasCjenkins-job-dsl-jcasc, jenkins-pipeline-generation, jenkins-pipeline-testing, jenkins-shared-libraries—

Invoke subagents​

By default, the root agent delegates to subagents automatically based on your prompt. You can also target a subagent directly:

# Launch OpsCode directly into a specific subagent
ops -a aws-terraform-module-writer

Or switch the active subagent mid-session in the TUI:

/agents

Define custom subagents​

Create custom subagents by adding an AGENTS.md file in either your project or user directory:

  • Project scope (Git-tracked): .opscode/agents/<subagent-name>/AGENTS.md
  • User scope: ~/.opscode/opscode/agents/<subagent-name>/AGENTS.md
.opscode/agents/terraform-reviewer/AGENTS.md
---
name: terraform-reviewer
description: Review Terraform and OpenTofu modules for security and best practices
model: anthropic:claude-opus-4-7
tools:
- execute
- read_file
- grep
- glob
skills:
- opentofu-iam-security
- aws-iam-policy-engine
permission_tier: read-only
---

You are a specialized Terraform and OpenTofu security auditor.

## Audit Criteria
1. Ensure S3 remote state uses AWS KMS encryption and DynamoDB state locking.
2. Verify all IAM policies follow least-privilege principles with zero wildcard actions.
3. Validate that security groups avoid open `0.0.0.0/0` ingress on non-HTTPS ports.
4. Confirm all resources include standard cost-allocation tags.

Frontmatter reference​

FieldRequiredDescription
nameYesUnique identifier for the subagent
descriptionYesRouting description used by the root agent to decide when to delegate
modelNoModel override in provider:model format (defaults to the main session model)
toolsNoAllowed tool names (e.g., read_file, execute, glob, grep)
skillsNoList of skill names loaded when this subagent runs
permission_tierNoread-only (default) or read-write

Dynamic parallel subagents​

When the QuickJS interpreter is enabled (--interpreter), OpsCode can spawn dynamic subagents in parallel at runtime using the built-in task() function.

Ask OpsCode to run a parallel workflow across multiple directories or modules:

Run a parallel workflow to audit every Terraform module in modules/* for IAM wildcards and unencrypted storage.

OpsCode generates and executes an orchestration script that dispatches concurrent subagents and aggregates their findings in the TUI's dynamic subagents panel:

const modules = await glob("modules/*/main.tf");

const reports = await Promise.all(
modules.map((mod) =>
task(`Audit ${mod} for IAM wildcards, open security groups, and unencrypted storage`)
)
);