Claude Code

Agent SDK agent features

Agent loop, settingSources, Claude Code features, sessions, skills, subagents, task tracking, checkpoints and hosting limits.

The SDK reuses project rules, skills, hooks, MCP, subagents, task tracking and checkpoints. Understand what loads automatically, what stays on disk and what increases prefixes and costs.

See runtime patterns for APIs and production deployment for topology and isolation.

#Official pages covered

Official pageCoverage
Agent loopMessage, tool, context, result and hook lifecycle
Claude Code features in SDKLoading settings, CLAUDE.md, skills, hooks and MCP
SessionsContinue, resume, fork and cross-host recovery
SkillsDiscovery and loading in SDK
SubagentsProgrammatic definitions, inheritance and tool limits
Todo trackingTask tools and live progress UI
File checkpointingFile rollback capabilities and boundaries
HostingSubprocesses, local state, resources and limitations

#Agent loop

An SDK task roughly follows this loop:

user prompt
  -> system/init
  -> assistant thinks and emits tool calls
  -> SDK/CLI checks hooks and permissions
  -> tools execute
  -> tool results enter conversation
  -> repeat until success, max turns, max budget, or error
Message/stageHost responsibility
system/initRecord session ID, model, commands, tools and permission mode
Assistant textStream to the UI
Tool useShow reads, edits, commands or MCP activity
Tool resultRecord summaries; collapse sensitive content
Successful resultSave output, usage and cost
Error resultShow cause and preserve recovery information

Common result subtypes:

SubtypeMeaning
successCompleted normally
error_max_turnsmaxTurns reached
error_max_budget_usdBudget reached
error_during_executionAPI, tool, cancellation or runtime failure
error_max_structured_output_retriesRepeated schema validation failure

#Context sources

SourceLoaded whenCache impact
System promptEvery requestStable content is reusable
CLAUDE.md / rulesStartup and on demandLarger content increases initial writes
Tool definitionsEvery request or deferred searchUpfront MCP schemas enlarge prefixes
Conversation historyGrows each turnLong sessions need compaction or branches
Skill descriptionsStartupUsually small; full content loads on invocation
HooksAfter configuration loadsHook results may append context

#settingSources

SourceLoaded content
projectProject CLAUDE.md, rules, skills, hooks and settings
userUser CLAUDE.md, rules, skills and settings
localCLAUDE.local.md、.claude/settings.local.json

settingSources does not control:

InputBehaviorDisable/isolate with
Endpoint-managed policyLoaded from device policyRemove device policy
Server-managed settingsOrganization-managed when eligibleAdministrator control only
~/.claude.jsonMay still be readCLAUDE_CONFIG_DIR
Auto memoryInjected into system prompt at startupCLAUDE_CODE_DISABLE_AUTO_MEMORY=1
claude.ai MCP connectorsMay load with subscription loginstrictMcpConfig or disable connector

Do not load user environments by default in multitenant services or CI:

options: {
  settingSources: [],
  env: {
    ...process.env,
    CLAUDE_CONFIG_DIR: "/srv/claude-config/job-123",
    CLAUDE_CODE_DISABLE_AUTO_MEMORY: "1"
  }
}

#Sessions

ScenarioUsage
One-shot taskOmit session and let query() create one
Continue latest in directorycontinue: true / continue_conversation=True
Resume a specific sessionSave ID and pass resume
Explore alternativesFork the session
Avoid persistenceTypeScript persistSession: false

An ID alone cannot restore across hosts. Plan workspace, CLAUDE.md, checkpoints, tool caches and artifacts separately.

#Skills

Load project/user skills or supply them through plugins.

Design areaRecommendation
descriptionExplain when to use the skill for automatic selection
allowed-toolsLimit the skill's tool scope
Project skillsVersion with the repository
User skillsPersonal workflows
Plugin skillsTeam distribution
SDK isolationEmpty settingSources to avoid automatic loading

Descriptions enter initial context even when full skill content does not. Large inventories still affect prefixes.

#Subagents

Programmatic definitions often suit SDK products better than agent files.

FieldPurpose
descriptionHelps select the subagent
promptSubagent role and task boundaries
toolsLimit available tools
disallowedToolsRemove inherited tools
modelSelect a subagent model
skillsPreload named skills
mcpServersSubagent-specific MCP
maxTurnsBound task rounds
backgroundRun without blocking the main thread

Inheritance boundaries:

Subagent receivesDoes not receive
Its own system promptFull parent conversation
Project CLAUDE.mdParent tool results
Specified/inherited toolsParent system prompt
Selected skillsUnloaded skill content

Suggested tool sets:

Use caseTools
Read-only analysisRead, Grep, Glob
TestsBash, Read, Grep
Code changesRead, Edit, Write, Grep, Glob
Full autonomyCarefully inherit tools inside a sandbox

#Todos and Task tools

Current versions favor Task tools over legacy TodoWrite.

Legacy TodoWriteTask tools
Rewrite the entire arrayTaskCreate adds an item
Track status fieldsTaskUpdate changes individual fields
Render the array directlyAccumulate events or read snapshots
Simple listsOwners, dependencies, metadata and parallel work

Listen to TaskCreate, TaskUpdate and TaskList results for progress UIs rather than parsing only assistant prose.

#File checkpointing

Checkpoints provide recovery points around agent file edits.

Tracked actionDescription
WriteNew files or overwrites
EditPartial changes to existing files
NotebookEditJupyter cell edits
Same-session restoreReturn to that session's checkpoint

Limitations:

LimitationDescription
Bash changesShell-created/deleted files are not checkpointed
Directory operationsCreate/move/delete may not fully roll back
Remote filesNetwork resources are not tracked
Cross-sessionCheckpoints belong to their originating session

Create a checkpoint before risky bulk edits or migrations.

#Hosting limitations

LimitationMitigation
No top-level wall-clock timeoutmaxTurns, process watchdog and queue timeout
Growing session memoryCompact, split tasks and recycle processes
Parallel subagents hit limitsBatch work and bound fanout
No total subagent timeoutmaxTurns and a stall watchdog
Extensive local statePlan config directory, workspace and SessionStore

#Cache effects

CapabilityCache effect
CLAUDE.md through settingSourcesStable content can favor one-hour TTL
Many skillsDescriptions increase prefixes
Upfront MCP toolsSchema changes cause misses
SubagentsIndependent contexts and prefixes
Task toolsState enters history; compact long tasks
CheckpointsPrimarily local state; rollback explanations enter conversation

#Official references

Support

Need help?

For setup, billing, or model issues, email us. Check the status page for uptime.

WeChat / QQ support is available at the bottom right.