AnyAgent

Claude Code

Use Claude Code through AnyAgent: what you can ask for, how it behaves, and the flags underneath.

The claude-code adapter drives the Claude Code CLI in headless mode, detected as the claude binary on PATH; import claudeCode from anyagent-js/claude-code.

What you can ask for

Nearly every run option works: readOnly, model (Claude Code’s own vocabulary, such as "opus"), effort (closed vocabulary: low, medium, high, xhigh, max), systemPrompt (appended to the CLI’s own, never replacing it), resume, forkSession, mcp, and schema. Only attachments throws, since Claude Code has no headless attachment flag. authStatus() asks claude auth status --json and asserts billing from the subscription tier. models() lists the documented alias vocabulary (fable, opus, sonnet[1m], …) plus the CLI’s cached org-specific entries — probed, since the CLI has no list command. usageStatus() reports the 5-hour and weekly windows plus model-scoped buckets, and { model } narrows the answer to one of them — see Usage and limits. The full grid is on the support matrix.

Good to know

  • The session id lands on result.sessionId; pass it back as resume to continue the conversation.
  • mcp means exactly the servers you passed: the end user’s own configured servers stay out of the run.
  • With a schema, result.text is the serialized JSON reply and no other text is emitted; validation and the one retry still apply.
  • usage reports cache reads and writes as separate line items on cacheReadTokens and cacheWriteTokens, and sets costUsd.
  • usageStatus() reads a snapshot the CLI leaves on disk, which it only refreshes when it runs — so the numbers can be old, or missing entirely on a fresh install. asOf tells you how old. Turn on network and it asks Anthropic directly instead, which is always current and also fills in credits.
  • An expired login is never refreshed. Anthropic issues a new refresh token each time one is used, so refreshing here would sign the user out of their own claude CLI. AnyAgent falls back to the cached snapshot instead.
  • Set CLAUDE_CONFIG_DIR and everything follows it — that is how the CLI keeps separate logins, so usageStatus() and models() answer for whichever one is active.
  • On macOS the login lives in the Keychain rather than a file, so the live reading is unavailable there and the cached snapshot is the answer.

Under the hood

Every run executes claude -p --output-format stream-json --verbose --permission-mode bypassPermissions with the prompt piped over stdin. Run options change the mode and append flags:

OptionFlag
readOnly: true--permission-mode manual plus --disallowedTools Bash,Edit,NotebookEdit,Write
model--model <name>
effort--effort <level>
systemPrompt--append-system-prompt <text>
resume--resume <sessionId>
forkSession: true--fork-session, appended beside --resume to branch into a fresh session id
mcp--mcp-config <json> plus --strict-mcp-config
schema--json-schema <json>

On this page