Skip to content

Subagents

Subagents let you create specialized AI agents tailored to specific tasks in your project. Instead of working with a general-purpose AI, you can define agents with specific expertise, restrict what tools they can access, and use them to handle specialized work—like security audits, documentation, or code review.

Focused expertise:

  • Create a security-focused agent that only reviews for vulnerabilities
  • Make a documentation agent that specializes in clear, comprehensive docs
  • Build a test specialist that runs tests and analyzes failures

Better control:

  • Give some agents access to bash and file editing, but not others
  • Create read-only agents for code review that can’t modify files
  • Prevent agents from accidentally breaking things by restricting permissions

Organized workflow:

  • Coordinate multiple agents working on different aspects of a task

Consistency:

  • Reuse the same agent definition across multiple threads
  • Keep specialized agents’ instructions consistent
  • Share agents globally or keep them project-specific

Open Settings → Skills → Subagents to browse the marketplace and install community subagents, or create your own with Add Subagent.

In your project, create a new agent file at .agents/agents/code-reviewer/AGENT.md:

---
name: code-reviewer
description: Review code for quality and best practices
---
You are an expert code reviewer. When reviewing code:
- Look for readability and maintainability issues
- Check for potential bugs and edge cases
- Suggest improvements to performance or clarity
- Point out violations of best practices
- Be constructive and specific with feedback

That’s it! You now have a code-reviewer agent.

In a conversation, ask the AI to use your agent:

Please use the code-reviewer agent to review the authentication module.

Or invoke it directly:

agent({
prompt: "Review the authentication module for security and quality issues",
agentName: "code-reviewer"
})

The agent will analyze your code using its specialized instructions and provide focused feedback.

Agents live in your project at .agents/agents/{name}/AGENT.md. Each agent file has two parts:

Configuration (frontmatter):

---
name: my-agent
description: What this agent does
---

Instructions (everything after ---):

You are a specialized expert. Your job is to...
Option What It Does Example
name Agent identifier code-reviewer, security-auditor, doc-writer
description Brief description, listed with the agent in the model’s system prompt Review code for quality and best practices
tools Which tools the agent can use (space-separated) read grep bash
agents Parsed but currently unused by the runtime [code-reviewer, test-runner]
model Specific model to use for this agent claude-haiku-4-5
provider Specific provider to use for this agent anthropic, openai
user-invocable Parsed but not consulted; only disable-model-invocation has an effect. Agents are surfaced to the model via the system prompt true
disable-model-invocation Exclude from the model’s agent list and reject named invocation through the agent tool true or false

Most of the time you only need name and description.

By default, subagents use the same model and provider as the main conversation. You can override this per-agent with the model and provider frontmatter fields. In Orchestrate mode, Tarsk uses the Cheap model alias for subagents regardless of these fields:

---
name: fast-reviewer
description: Quick code review using a fast model
model: gemini-2.5-flash
provider: google
---

This is useful when you want certain agents to use cheaper or faster models for routine tasks while reserving expensive models for complex work.

Code Reviewer

  • Tools: read grep (can read files but not modify)
  • Good for: Providing feedback without making changes
  • Instructions: Focus on code quality, maintainability, bugs

Security Auditor

  • Tools: read grep bash (can run commands to test)
  • Good for: Checking for vulnerabilities
  • Instructions: Look for auth issues, injection vulnerabilities, credential handling

Documentation Writer

  • Tools: read grep (read code to document it)
  • Good for: Generating docs from code
  • Instructions: Create clear, comprehensive documentation with examples

Test Runner

  • Tools: bash read (run tests but don’t modify code)
  • Good for: Running tests and analyzing results
  • Instructions: Run the test suite, analyze failures, suggest fixes

Simply mention using the agent:

Can you use the security-auditor agent to review the login flow for vulnerabilities?

Call the agent directly:

agent({
prompt: "Audit the database connection pool for security issues",
agentName: "security-auditor"
})

Agent files can include an agents frontmatter field, and Tarsk parses it, but nothing consumes it today. Spawning a subagent passes only its system prompt, tool whitelist, and optional model and provider overrides. Describe any coordination workflow in the agent’s instructions instead.

Set runInBackground: true when you want a subagent to keep working while the main agent handles other work:

agent({
prompt: "Review the authentication module for security issues",
agentName: "security-auditor",
runInBackground: true
})

Tarsk returns a backgroundRunId and sends the subagent’s result as a later message when it finishes. Continue other work while it runs. Do not poll or wait for it.

Use the agent tool to check, steer, or stop a run you started in this thread:

agent({ control: "status" })
agent({ control: "send", backgroundRunId: "bgsub_...", message: "Check the login flow too" })
agent({ control: "interrupt", backgroundRunId: "bgsub_..." })

status without a backgroundRunId lists active runs. send delivers its message at the subagent’s next turn boundary. interrupt stops the run and discards its partial result.

By default, subagents inherit the parent’s base tools. Restrict what they can do by listing allowed tools. Orchestrate mode ignores these restrictions and gives subagents the full Build tool set:

Read-only agent (can’t modify):

---
name: code-reviewer
description: Review code for quality
tools: read grep
---

Command-only agent (can run bash but not edit):

---
name: test-runner
description: Run tests and report results
tools: bash read
---

Edit-only agent (very restricted):

---
name: formatter
description: Format code according to style guide
tools: read edit bash
---

All agents in .agents/agents/ are available. The model sees them in its # Subagents system-prompt list, which names each agent it can pass as agentName. Their definition files also live in your project’s thread directory.

Open .agents/agents/{agent-name}/AGENT.md and update:

  • The instructions (everything after frontmatter)
  • The configuration fields

Changes take effect immediately.

Delete the .agents/agents/{agent-name}/ directory, and the agent disappears from the model’s subagent list.

Put agents in ~/.agents/agents/{name}/AGENT.md to make them available globally. Project-specific agents in .agents/agents/ override global ones with the same name.

---
name: security-auditor
description: Security-focused code review
tools: read grep bash
---
You are a security expert. When analyzing code, focus on:
- **Authentication & Authorization:** Session handling, token validation, permission checks
- **Data Validation:** Input sanitization, type checking, bounds validation
- **Injection Attacks:** SQL injection, command injection, XSS, template injection
- **Secrets Management:** Hardcoded credentials, key storage, environment variables
- **Cryptography:** Weak algorithms, insecure random number generation
- **Error Handling:** Information leakage through error messages
Be thorough, specific, and explain the security impact of each issue.
---
name: api-documenter
description: Generate API documentation
tools: read grep
---
You are a technical writer specializing in API documentation.
Generate comprehensive documentation including:
1. **Overview** - High-level purpose and use cases
2. **Endpoints** - List all endpoints with HTTP method and path
3. **Request/Response** - Show examples for each endpoint
4. **Error Codes** - Document status codes and error messages
5. **Authentication** - Explain how to authenticate
6. **Rate Limiting** - Note any limits
7. **Examples** - Provide curl and code examples
Use clear language and structure with proper formatting.
---
name: quality-lead
description: Run a code quality pass over the workspace
---
You run one code quality pass across the workspace.
1. Assess code quality and maintainability
2. Check for security vulnerabilities
3. Verify that tests pass
Group findings by severity in a short report.

Create agents for recurring needs:

  • If you frequently need security reviews, create a security-auditor
  • If you often write documentation, create a doc-writer
  • If tests are important, create a test-runner

Use focused instructions:

  • Give agents clear, specific guidance on what to focus on
  • Avoid vague instructions like “review the code”
  • Be specific: “Check for SQL injection vulnerabilities and authentication issues”

Restrict tools appropriately:

  • Review agents don’t need edit or bash (use read grep)
  • Test runners don’t need edit (use bash read)
  • Give agents only the tools they actually need

Start simple:

  • Create agents for one specific purpose
  • Expand to more complex agents once you understand the pattern
  • You can always modify an agent’s instructions later

Document your agents:

  • Use clear names: security-auditor not agent2
  • Provide helpful descriptions in the description field
  • The model sees these descriptions in its subagent list, which helps it pick the right agent
  • Nested subagents: A subagent keeps the agent tool until the chain reaches depth 3. The depth-3 run loses agent and keeps every other tool, so nesting stops there.
  • Agent availability: Agents only exist in the project where they’re defined, unless you move them to your global agents folder