AI & Agents

Using Hermes Agent as a Coding Agent: Code Execution and Delegation

Hermes Agent offers three distinct coding modes: direct code execution via execute_code, delegation to external coding CLIs like Claude Code and OpenCode, and structured implementation planning through bundled skills. This guide walks through each mode with practical examples, explains when to choose one over another, and shows how to persist coding artifacts in shared workspaces.

Fastio Editorial Team 9 min read
AI agent workflow showing code execution and task delegation

Three Coding Modes in Hermes Agent

Nous Research Hermes Agent ships with coding capabilities that go beyond simple code generation. Where most AI coding tools offer a single interaction model, Hermes provides three complementary approaches that cover different parts of the development lifecycle.

Direct code execution via execute_code collapses multi-step pipelines into single inference calls. Your agent writes a Python script that invokes Hermes tools programmatically, and the entire workflow runs in a child process without flooding the context window with intermediate results.

Delegation to coding CLIs like Claude Code and OpenCode hands complex implementation tasks to specialized agents. Each delegate gets its own conversation, terminal session, and working directory. The parent agent receives only a final summary.

Implementation plan generation through the bundled software-development skill produces structured task breakdowns that other agents or human developers can execute step by step.

These three modes compose naturally. You might generate an implementation plan, delegate individual tasks from that plan to Claude Code subagents running in parallel, then use execute_code to collect and verify their outputs.

How to Execute Code Directly with execute_code

The execute_code tool runs Python scripts in a child process that communicates with Hermes over a Unix domain socket. Scripts import from hermes_tools to call tools like web_search, web_extract, read_file, write_file, search_files, patch, and terminal.

Here is a practical example that searches a codebase for database configuration files and extracts their contents:

from hermes_tools import search_files, read_file
import json

matches = search_files("database", path=".", file_glob="*.yaml", limit=20)
configs = []
for match in matches.get("matches", []):
    content = read_file(match["path"])
    configs.append({
        "file": match["path"],
        "preview": content["content"][:200]
    })
print(json.dumps(configs, indent=2))

Only print() output returns to the LLM. Intermediate results from tool calls stay isolated in the child process, which keeps the context window clean and reduces token consumption .

Resource Limits

Scripts run with sensible defaults: a 5-minute timeout, 50 KB stdout cap, 10 KB stderr cap, and a maximum of 50 tool calls per execution. All limits are configurable in ~/.hermes/config.yaml.

Security Model

The child process strips environment variables containing KEY, TOKEN, SECRET, PASSWORD, CREDENTIAL, PASSWD, or AUTH by default. Skills that declare required_environment_variables pass their variables through automatically. Scripts cannot call execute_code recursively, invoke delegate_task, or access MCP tools.

When to Use execute_code

Reach for execute_code when you need three or more tool calls with processing logic between them, bulk data filtering, conditional branching, or loops over results. A web research pipeline that fetches five pages and extracts specific data points is a textbook use case. If the work is purely mechanical (no judgment calls, no exploration), execute_code is cheaper and faster than delegation because it skips the LLM reasoning loop entirely.

How to Delegate Coding Tasks to Claude Code and OpenCode

For tasks that require reasoning, multi-step debugging, or code review, Hermes delegates to specialized coding CLIs through delegate_task and bundled skills.

Claude Code Integration Hermes invokes Claude Code in two modes. Print mode uses the -p flag for single-shot execution:

claude -p "Refactor the auth module to use JWT refresh tokens" \
  --allowedTools "Read,Edit,Write,Bash" \
  --max-turns 15

Interactive mode spawns Claude Code in a tmux session for multi-turn conversations:

tmux new-session -d -s claude-refactor
tmux send-keys -t claude-refactor 'cd /project && claude' Enter

Results come back as text, structured JSON (with session_id, num_turns, total_cost_usd, and stop_reason), or streamed newline-delimited JSON events for real-time monitoring.

OpenCode Integration OpenCode handles bounded implementation tasks with opencode run:

opencode run 'Add input validation to the user registration endpoint'

For iterative work, Hermes launches OpenCode in background mode with PTY enabled. OpenCode also supports PR review via opencode pr <number>, making it useful for code quality workflows.

Choosing Between Delegates

Claude Code excels at complex refactoring, architecture-level changes, and multi-file modifications where judgment matters. OpenCode is well-suited for bounded feature implementation and automated PR review. Both run with isolated conversations and terminals, so the parent agent's context stays clean regardless of how much work the delegate performs.

Agent delegation workflow showing task handoff and results
Fastio features

Persist your Hermes coding artifacts across sessions

Free 50 GB workspace with auto-indexing. Store implementation plans, code review summaries, and build outputs where your whole team can find them. No credit card required.

Subagent Delegation for Parallel Development

The delegate_task tool spawns child agent instances with fully isolated execution contexts. Each subagent starts with zero knowledge of the parent's conversation history and receives only what the parent explicitly passes via goal and context parameters.

Single Task Delegation

delegate_task(
    goal="Debug why integration tests fail in the payment module",
    context="Error: assertion in test_checkout.py line 42. Project uses pytest.",
    toolsets=["terminal", "file"]
)

Parallel Batch Mode

delegate_task(tasks=[
    {"goal": "Review auth module for SQL injection", "toolsets": ["terminal", "file"]},
    {"goal": "Add rate limiting to the API gateway", "toolsets": ["terminal", "file"]},
    {"goal": "Write integration tests for the new webhook handler", "toolsets": ["terminal", "file"]}
])

Batch mode runs up to 3 concurrent subagents by default (configurable via delegation.max_concurrent_children). Results return in input order regardless of completion order.

Isolation and Coordination Subagents operate with complete separation. Leaf agents (the default role) cannot delegate further, access memory, or call execute_code. Orchestrator children retain delegation rights but still lack memory and messaging access.

Hermes v0.11.0 introduced a file coordination layer that prevents concurrent sibling subagents from clobbering each other's edits. For files that multiple agents might touch simultaneously, the coordination mechanism synchronizes filesystem state across active children.

Configuration

### ~/.hermes/config.yaml
delegation:
  max_iterations: 50
  max_concurrent_children: 3
  max_spawn_depth: 1
  child_timeout_seconds: 600
  model: "google/gemini-flash-2.0"
  provider: "openrouter"

You can assign different models to subagents than the parent uses. A common pattern: run the orchestrator on a capable model (Claude Opus, GPT-4) while delegating mechanical subtasks to faster, cheaper models.

Implementation Plans with the Software Development Skill

Before jumping into code, the bundled software-development skill generates structured implementation plans that break complex features into executable tasks. Each task targets 2-5 minutes of focused work with exact file paths, step-by-step instructions, and verification procedures.

The skill follows a strict principle: "A good plan makes implementation obvious. If someone has to guess, the plan is incomplete."

Plan Structure

Plans include a header (feature name, goal, architecture overview, technology stack) followed by numbered tasks. Each task specifies its objective, affected files, and detailed steps including the full TDD cycle: write test, verify failure, implement, confirm pass, commit.

Core Principles

The planning skill enforces three development practices:

  • DRY: Extract shared logic rather than duplicating across files
  • YAGNI: Implement only what the current requirement demands
  • TDD: Every coding task includes write-test-run-implement-verify cycles

Combining Plans with Delegation

The most effective workflow generates a plan first, then delegates individual tasks to subagents:

  1. Ask Hermes to write an implementation plan for your feature
  2. Review the plan and adjust scope or ordering
  3. Use delegate_task in batch mode to assign each plan task to a separate subagent
  4. Subagents execute with ["terminal", "file"] toolsets, following the plan's exact instructions
  5. Parent collects results and verifies integration

This pattern works particularly well for features that span multiple modules. Each subagent works on a self-contained piece, and the file coordination layer handles any overlap.

Persisting Coding Artifacts Beyond the Session

Hermes Agent runs on your own infrastructure (local machine, Docker, SSH, Modal, Singularity, or Vercel Sandbox). Code files live wherever the terminal backend points. But development artifacts, documentation, and outputs that need to survive across sessions or reach other team members benefit from persistent cloud storage.

Local filesystems work for active development, but they create gaps: files disappear when containers stop, other team members cannot access outputs without manual file transfers, and there is no semantic search across generated code documentation.

Cloud Workspace Storage

Fastio provides workspaces where agents store, index, and share files through an MCP server or REST API. For coding workflows, this means implementation plans, code review summaries, generated documentation, and build artifacts persist beyond any single Hermes session.

The Fastio MCP server exposes workspace operations (upload, download, search, AI query) that Hermes can call through its MCP integration. Files uploaded to a workspace are automatically indexed for semantic search through Intelligence Mode, so you can later ask questions about your stored plans and outputs with cited answers.

For multi-agent coding teams where subagents produce independent outputs, file locks prevent conflicts when multiple agents write to the same workspace. This complements Hermes's built-in file coordination layer by extending conflict prevention to cloud storage.

Alternatives for File Persistence

S3 or Google Cloud Storage work well if you only need durable blob storage without indexing or collaboration features. GitHub repositories handle version-controlled source code. For teams that need both persistence and searchability across agent-generated artifacts, a workspace with built-in intelligence (auto-indexing, RAG, semantic search) reduces the tooling you need to maintain separately.

The Business Trial includes 50 GB storage, included credits, and 5 workspaces with no credit card required.

Frequently Asked Questions

Can Hermes Agent write code?

Yes. Hermes Agent writes code through three mechanisms: execute_code runs Python scripts that call tools programmatically, delegate_task hands implementation work to Claude Code or OpenCode with isolated terminals, and the software-development skill generates structured implementation plans. The agent can also write files directly via write_file and patch tools.

How does Hermes Agent delegate to Claude Code?

Hermes invokes Claude Code in print mode (single-shot via the -p flag) or interactive mode (multi-turn via tmux sessions). Print mode returns structured JSON with session metadata. Interactive mode uses tmux send-keys for dialog handling and tmux capture-pane for output monitoring. Each invocation gets constrained tool access and token budgets.

What is execute_code in Hermes Agent?

execute_code is a tool that runs Python scripts in an isolated child process communicating with Hermes over a Unix domain socket. Scripts can call Hermes tools (web_search, read_file, write_file, terminal, etc.) programmatically. Only print() output returns to the LLM, keeping intermediate results out of the context window and reducing token consumption.

Is Hermes Agent good for coding?

Hermes Agent is well-suited for orchestrating coding workflows rather than acting as a standalone code editor. Its strengths are coordinating multiple coding agents in parallel, running multi-step pipelines without context window bloat, and generating structured plans. For direct code editing, it delegates to specialized tools like Claude Code or OpenCode that excel at that specific task.

What is the difference between execute_code and delegate_task?

execute_code handles mechanical, sequential operations: loops, data collection, conditional branching with no judgment needed. It skips the LLM reasoning loop entirely. delegate_task spawns a full agent instance for reasoning-heavy subtasks: debugging, code review, research synthesis, or multi-step implementation. Use execute_code when the logic is predictable, delegate_task when the subtask needs fresh perspective or exploration.

Can Hermes Agent run multiple coding tasks in parallel?

Yes. The delegate_task tool accepts a tasks array for batch execution, running up to 3 concurrent subagents by default. Each gets an isolated conversation and terminal session. A file coordination layer introduced in v0.11.0 prevents concurrent agents from overwriting each other's edits. The max_concurrent_children setting is configurable in ~/.hermes/config.yaml.

Related Resources

Fastio features

Persist your Hermes coding artifacts across sessions

Free 50 GB workspace with auto-indexing. Store implementation plans, code review summaries, and build outputs where your whole team can find them. No credit card required.