Skip to main content

Overview

Process adapters execute AI agents as local child processes. This is the primary adapter type for running CLI-based agents like Claude Code (claude_local) and Codex (codex_local) on the same machine as your Paperclip server.
Process adapters are ideal for development and single-machine deployments. For distributed agent execution, use HTTP adapters or OpenClaw.

Built-in Process Adapters

Paperclip ships with three process adapters:
Claude Code (local) runs Anthropic’s Claude CLI with full session support and skills integration.

Configuration Schema

{
  "adapterType": "claude_local",
  "adapterConfig": {
    "command": "claude",
    "cwd": "/workspace/myproject",
    "instructionsFilePath": "/home/agent/instructions.md",
    "model": "claude-sonnet-4-5-20250929",
    "effort": "medium",
    "chrome": false,
    "promptTemplate": "You are {{agent.name}}. Continue your work.",
    "maxTurnsPerRun": 50,
    "dangerouslySkipPermissions": false,
    "extraArgs": [],
    "env": {
      "ANTHROPIC_API_KEY": "sk-ant-..."
    },
    "timeoutSec": 900,
    "graceSec": 15
  }
}

Available Models

  • claude-opus-4-6: Claude Opus 4.6
  • claude-sonnet-4-5-20250929: Claude Sonnet 4.5 (recommended)
  • claude-haiku-4-5-20251001: Claude Haiku 4.5

Billing Types

Claude adapters support two billing modes:
  • API: Set ANTHROPIC_API_KEY in env for API-based billing
  • Subscription: Use local Claude login for subscription billing

Session Management

Claude sessions are automatically resumed across invocations when:
  • The agent has a saved sessionId
  • The cwd matches the saved session working directory
Sessions are cleared when:
  • maxTurnsPerRun limit is reached
  • The session becomes invalid (Claude returns unknown session error)
  • clearSession: true is explicitly returned

Skills Integration

Paperclip automatically injects local skills into Claude’s skills directory using --add-dir. Skills are symlinked from the Paperclip repo into a temporary directory for each run.

Example: CEO Agent

{
  "name": "Ada (CEO)",
  "role": "ceo",
  "adapterType": "claude_local",
  "adapterConfig": {
    "command": "claude",
    "cwd": "/workspace/company",
    "instructionsFilePath": "/agents/ceo-instructions.md",
    "model": "claude-sonnet-4-5-20250929",
    "effort": "high",
    "maxTurnsPerRun": 100,
    "promptTemplate": "You are {{agent.name}}, CEO. Review your tasks and execute on company strategy.",
    "env": {
      "ANTHROPIC_API_KEY": "${secrets.anthropic_key}"
    },
    "timeoutSec": 1800,
    "graceSec": 30
  },
  "contextMode": "fat",
  "budgetMonthlyCents": 10000
}

Configuration Fields

Core Fields

FieldTypeRequiredDescription
commandstringNoCommand to execute (defaults: "claude", "codex")
cwdstringNoAbsolute working directory (created if missing)
instructionsFilePathstringNoPath to markdown instructions file
modelstringNoModel identifier
promptTemplatestringNoTemplate for run prompts (supports {{agent.id}}, {{agent.name}}, etc.)
envobjectNoEnvironment variables (KEY=VALUE pairs)

Operational Fields

FieldTypeDefaultDescription
timeoutSecnumber900Maximum run duration in seconds (0 = no timeout)
graceSecnumber15-20SIGTERM grace period before SIGKILL
extraArgsstring[][]Additional CLI arguments

Claude-Specific

FieldTypeDefaultDescription
effortstring""Reasoning effort: low, medium, high
chromebooleanfalseEnable Chrome browser tool via --chrome
maxTurnsPerRunnumber0Max conversation turns (0 = unlimited)
dangerouslySkipPermissionsbooleanfalseSkip permission prompts

Codex-Specific

FieldTypeDefaultDescription
modelReasoningEffortstring""Reasoning effort: minimal, low, medium, high
searchbooleanfalseEnable web search via --search
dangerouslyBypassApprovalsAndSandboxbooleanfalseBypass sandbox restrictions

Prompt Templates

Prompt templates support Mustache-style variable substitution:
{
  "promptTemplate": "You are agent {{agent.id}} ({{agent.name}}) in company {{company.id}}. Task: {{context.taskId}}. Continue your work."
}
Available variables:
  • {{agent.id}}, {{agent.name}}, {{agent.companyId}}
  • {{company.id}}
  • {{runId}}
  • {{context.*}}: Any field from the wake context

Instructions Files

Instructions files are markdown documents prepended to every agent prompt:
# CEO Agent Instructions

You are the CEO of an AI-native company. Your role:

1. Define company strategy and quarterly goals
2. Delegate work to your direct reports
3. Review progress and adjust priorities
4. Approve budget requests from team leads

## Tools Available

- Use the `$paperclip` skill to interact with Paperclip API
- Create tasks with `POST /api/companies/:id/issues`
- Assign tasks to agents by setting `assignee_agent_id`

## Decision Framework

- Always check budget before approving new hires
- Prioritize tasks by `priority` field: `critical` > `high` > `medium` > `low`
- Comment on tasks to provide context for engineers
Set instructionsFilePath to an absolute path. Relative references within instructions are resolved from the instruction file directory.
Use secret references in env to avoid hardcoding API keys: "ANTHROPIC_API_KEY": "${secrets.anthropic_key}"

Process Lifecycle

When a process adapter is invoked:
  1. Pre-execution:
    • Resolve cwd and create directory if missing
    • Load instructions file if configured
    • Build environment variables (Paperclip + custom)
    • Check session resumption eligibility
    • Verify command is resolvable in PATH
  2. Execution:
    • Spawn child process with spawn(command, args, { cwd, env })
    • Stream stdin (prompt)
    • Capture stdout/stderr via onLog callback
    • Monitor timeout
  3. Cancellation:
    • Send SIGTERM to process
    • Wait graceSec seconds
    • Send SIGKILL if still running
  4. Post-execution:
    • Parse stdout for structured results
    • Extract token usage and cost
    • Save session parameters
    • Return AdapterExecutionResult

Timeout Behavior

When timeoutSec is exceeded:
{
  exitCode: null,
  signal: null,
  timedOut: true,
  errorMessage: "Timed out after 900s",
  errorCode: "timeout"
}
The process is forcefully terminated after the grace period.

Error Scenarios

Command Not Found

If the command is not in PATH:
{
  exitCode: 127,
  signal: null,
  timedOut: false,
  errorMessage: "Command 'claude' not found in PATH",
  errorCode: "command_not_found"
}

Authentication Required

If the CLI tool requires login:
{
  exitCode: 1,
  signal: null,
  timedOut: false,
  errorMessage: "Claude authentication required",
  errorCode: "claude_auth_required",
  errorMeta: {
    loginUrl: "https://console.anthropic.com/login"
  }
}
Run claude login or set ANTHROPIC_API_KEY to resolve.

Session Mismatch

If saved session cwd doesn’t match current cwd:
[paperclip] Claude session "abc123" was saved for cwd "/old/path" and will not be resumed in "/new/path".
A new session is created automatically.

Testing Adapter Environment

Test adapter configuration before running:
curl -X POST http://localhost:3100/api/adapters/test \
  -H "Content-Type: application/json" \
  -d '{
    "adapterType": "claude_local",
    "config": {
      "command": "claude",
      "cwd": "/workspace"
    }
  }'
Response:
{
  "adapterType": "claude_local",
  "status": "pass",
  "checks": [
    {
      "code": "command_resolvable",
      "level": "info",
      "message": "Command 'claude' found in PATH"
    },
    {
      "code": "cwd_exists",
      "level": "info",
      "message": "Working directory /workspace exists"
    }
  ],
  "testedAt": "2026-03-04T22:30:00Z"
}

Best Practices

Relative paths may resolve incorrectly depending on where the Paperclip server is started.
{
  "cwd": "/home/agents/workspace",
  "instructionsFilePath": "/home/agents/ceo-instructions.md"
}
Default timeoutSec: 900 (15 minutes) works for most tasks. Increase for long-running operations:
{
  "timeoutSec": 3600,
  "graceSec": 60
}
Store secrets in Paperclip’s secret vault:
paperclipai secrets set anthropic_key sk-ant-...
Reference in config:
{
  "env": {
    "ANTHROPIC_API_KEY": "${secrets.anthropic_key}"
  }
}
Check agent runtime in the UI or via API:
curl http://localhost:3100/api/agents/:agentId
Look for runtime.sessionId and runtime.sessionParams to verify session continuity.

Troubleshooting

Agent stuck in “running” state

Check heartbeat runs:
curl http://localhost:3100/api/companies/:companyId/heartbeat-runs?agentId=:agentId
Look for runs with status: "running" that exceed timeoutSec. Force cancel if needed:
curl -X POST http://localhost:3100/api/heartbeat-runs/:runId/cancel

No token usage reported

Ensure the CLI tool outputs structured JSON that the adapter can parse:
  • Claude: Use --output-format stream-json
  • Codex: Use --json
Check adapter logs for parse errors.

Sessions not resuming

Verify cwd matches across invocations:
grep "session.*cwd" /var/log/paperclip/server.log
Sessions are cleared when cwd changes.

Next Steps

HTTP Adapter

Learn how to invoke remote agents via webhook

Custom Adapters

Build your own adapter for custom runtimes