惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

Martin Fowler
Martin Fowler
J
Java Code Geeks
博客园 - 【当耐特】
宝玉的分享
宝玉的分享
腾讯CDC
D
DataBreaches.Net
Microsoft Azure Blog
Microsoft Azure Blog
Engineering at Meta
Engineering at Meta
V
V2EX
F
Fortinet All Blogs
MyScale Blog
MyScale Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
T
Tailwind CSS Blog
Jina AI
Jina AI
GbyAI
GbyAI
大猫的无限游戏
大猫的无限游戏
A
About on SuperTechFans
酷 壳 – CoolShell
酷 壳 – CoolShell
爱范儿
爱范儿
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
U
Unit 42
B
Blog
M
MIT News - Artificial intelligence
N
Netflix TechBlog - Medium

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant
Agent as a Tool Call: Claude Code's Fork-Exec Pattern
eyesofish · 2026-05-27 · via DEV Community

eyesofish

Claude-code’s most ruthless move: launching another agent is a tool call. From the parent’s perspective, Agent is just another tool—same level as Bash("ls"). Under the hood, it forks a new sub‑agent loop with its own memory, cache, and permissions. That’s the fork‑exec pattern for LLMs.

The agent as three layers

1. Configuration — AgentDefinition

src/tools/AgentTool/loadAgentsDir.ts:162: AgentDefinition = BuiltInAgentDefinition | CustomAgentDefinition | PluginAgentDefinition. The base definition packs everything you need to spin up a child agent:

  • agentType
  • tools (a subset of the parent’s available tools)
  • disallowedTools
  • model
  • permissionMode
  • maxTurns
  • skills
  • mcpServers
  • hooks
  • background
  • isolation (worktree or remote)

These definitions come from three places: built‑in TypeScript in src/tools/AgentTool/built-in/, user YAML frontmatter in .claude/agents/*.md files, and plugins via the MCP mechanism.

2. Runtime — isolated sub‑conversation loop

When the parent invokes an agent, the tool spawns an isolated query loop. Inside that loop:

  • a fresh message history []
  • its own fileStateCache
  • a separate abortController
  • an independent toolPermissionContext
  • default permission mode acceptEdits (set at AgentTool.tsx:575)

Everything runs in the same Node.js process unless you set isolation=remote.

3. User‑facing — just another tool

From the parent Claude’s standpoint the agent is a plain tool:

  • name: Agent
  • input: { description, prompt, subagent_type, model, run_in_background }
  • output: { result: string }

The closest system analogy: fork() + exec(). You fork a child Claude, give it a specific configuration and a task, let it work in an isolated context, and when it’s done you read back a result string. No shared state, no entanglement.

Where agent calls fit in the Task system

Claude Code models background tasks as a fixed set of TaskTypes. The agent tool maps to these types:

  • local_bash – like subprocess.run() for a shell command
  • local_agent – fork a sub‑process running another Claude agent (our fork‑exec)
  • remote_agent – an HTTP call to a remote inference service
  • > TODO: list the remaining four TaskTypes and when they’re used

The Task interface exposes exactly one control: kill() — essentially SIGTERM for agent processes. Background tasks in LangGraph (e.g., an async embedding) follow the same pattern, hardened here into a small typed enumeration.

What you’d grind on in an interview

If someone tells you they built an agent‑as‑tool‑call system like this, don’t let them wave their hands. Ask:

  1. How are messages isolated? (Is each sub‑agent truly stateless from the parent, or does any context leak through system prompts or shared memory?)
  2. How are tools isolated? (Can a child agent call tools the parent didn’t explicitly allow? What about side effects, like writing to an MCP server?)
  3. How do you prevent concurrent file‑write collisions? (When two agents mutate the same file, who wins? Is there a worktree, file locking, or something else?)

Those three questions cover the real complexity. The fork‑exec metaphor is clean until two processes touch the same disk.