<!-- mobian-agent-page publisher="dailydev" canonical="https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo" -->

---
title: Claude Code as a function | daily.dev
description: AgentField&#x27;s harness() function wraps multi-turn coding agent CLIs (Claude Code, Codex, Gemini, OpenCode) so they can be called safely from backend code with a...
canonical: https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo
twitter:card: summary_large_image
twitter:site: @dailydotdev
og:type: website
og:site_name: daily.dev
og:title: Claude Code as a function | daily.dev
og:description: AgentField&#x27;s harness() function wraps multi-turn coding agent CLIs (Claude Code, Codex, Gemini, OpenCode) so they can be called safely from backend code with a...
og:url: https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo
og:image: https://api.daily.dev/og/posts/wWshTB7QO.png
og:image:alt: Claude Code as a function
og:image:width: 1200
og:image:height: 630
og:locale: en
---

> ## Documentation Index
> Fetch the complete documentation index at: https://daily.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Claude Code as a function

**[AgentField.ai](https://daily.dev/sources/agentfield)** · 6 min read · 0 upvotes · 0 comments

## Summary

AgentField's harness() function wraps multi-turn coding agent CLIs (Claude Code, Codex, Gemini, OpenCode) so they can be called safely from backend code with a dollar budget cap, turn limit, tool allowlist, and typed Pydantic/schema output. The post walks through a Python example that dispatches a bug-fix task to Claude Code with a three-dollar ceiling, explains how each guardrail works, contrasts harness() with a lighter-weight ai(tools=...) call for single-step reasoning, and notes a cross-SDK gap where the Go version lacks a cost field that Python and TypeScript both expose.

## Full article

daily.dev links to this article rather than hosting it. Read it at the original source: <https://agentfield.ai/blog/claude-code-as-a-function>

## Questions this post answers

### How do I limit how much money an autonomous Claude Code run can spend when I call it from a backend service?

Set a max_budget_usd parameter when invoking the agent through a harness function; the agent stops as soon as it crosses that dollar cap, so a runaway loop costs exactly that ceiling rather than an unbounded amount. Combine it with a max_turns limit as a second, independent brake, and restrict the tools list (for example Read, Write, Bash) to cap what the agent can actually do.

_For teams wiring coding agents into unattended pipelines, daily.dev surfaces practical guardrail patterns like this one._

### What is the difference between calling a coding agent for a multi-turn task versus a single reasoning step with tool access?

A multi-turn coding agent call is appropriate when the task involves navigating a repo it hasn't seen upfront: reading files, deciding what to read next, editing several files, running tests, and iterating on failures. A single reasoning-step call with a short tool loop fits classification, routing, or a bounded structured extraction - essentially one prompt and one answer rather than an open-ended session.

_Developers deciding between agent architectures can find this kind of practical framing on daily.dev._

### Does the Go SDK for AgentField's coding agent harness return the dollar cost of a run like the Python and TypeScript versions do?

No, the Go harness result only carries the turn count and duration, not a cost field, so a Go call reads hr.NumTurns but has no hr.CostUsd. Python exposes result.cost_usd and TypeScript exposes result.costUsd, both returning the actual spend, making cost tracking inconsistent across the three SDKs.

_Engineers building cross-language agent tooling can track SDK parity gaps like this via daily.dev._

## Similar posts on daily.dev

- [Program Claude Code, Codex, Pi and other agent harnesses with AI SDK](https://daily.dev/posts/program-claude-code-codex-pi-and-other-agent-harnesses-with-ai-sdk-o7afpazbb) · Vercel · 2 upvotes · 0 comments
- [What Is an Agent Harness? The Architecture Behind Claude Code, DeepSeek Harness, and Hermes Agent](https://daily.dev/posts/what-is-an-agent-harness-the-architecture-behind-claude-code-deepseek-harness-and-hermes-agent-yewiwnntj) · freeCodeCamp · 11 upvotes · 2 comments
- [The Harness Tax: The Dead Weight Inside Your Coding Agent](https://daily.dev/posts/the-harness-tax-the-dead-weight-inside-your-coding-agent-iiu0gkchd) · portkey · 0 upvotes · 0 comments

---

Tags: [#python](https://daily.dev/tags/python), [#ai-agents](https://daily.dev/tags/ai-agents), [#claude-code](https://daily.dev/tags/claude-code)

[View this post on daily.dev](https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo)

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://daily.dev/#organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180},"sameAs":["https://twitter.com/dailydotdev","https://github.com/dailydotdev","https://www.linkedin.com/company/daily-dev-ltd"]},{"@type":"WebSite","@id":"https://daily.dev/#website","url":"https://daily.dev","name":"daily.dev","publisher":{"@id":"https://daily.dev/#organization"},"potentialAction":{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https://daily.dev/search?q={search_term_string}"},"query-input":"required name=search_term_string"}}]}
{"@context":"https://schema.org","@type":"TechArticle","headline":"Claude Code as a function","url":"https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo","mainEntityOfPage":{"@type":"WebPage","@id":"https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo"},"datePublished":"2026-10-02T17:45:21.990Z","dateModified":"2026-10-03T17:36:56.498Z","description":"AgentField's harness() function wraps multi-turn coding agent CLIs (Claude Code, Codex, Gemini, OpenCode) so they can be called safely from backend code with a...","image":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4daff12c105c7f8f1177be6aa01df4a1?_a=AQAEuop","thumbnailUrl":"https://media.daily.dev/image/upload/f_auto,q_auto/v1/posts/4daff12c105c7f8f1177be6aa01df4a1?_a=AQAEuop","isAccessibleForFree":true,"articleSection":"AgentField.ai","inLanguage":"en","publisher":{"@type":"Organization","name":"daily.dev","url":"https://daily.dev","logo":{"@type":"ImageObject","url":"https://daily.dev/apple-touch-icon.png","width":180,"height":180}},"author":{"@type":"Organization","name":"AgentField.ai","logo":"https://media.daily.dev/image/upload/s--VLFHaedl--/f_auto/v1791063152/squads/33beeb91-1f14-4d9b-9cf8-db7d9f69160a?_a=BAMAMicg0","url":"https://daily.dev/squads/agentfield"},"commentCount":0,"discussionUrl":"https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo","interactionStatistic":[{"@type":"InteractionCounter","interactionType":{"@type":"LikeAction"},"userInteractionCount":0},{"@type":"InteractionCounter","interactionType":{"@type":"CommentAction"},"userInteractionCount":0}],"keywords":"python,ai-agents,claude-code","timeRequired":"PT6M"}
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https://daily.dev"},{"@type":"ListItem","position":2,"name":"AgentField.ai","item":"https://daily.dev/squads/agentfield"},{"@type":"ListItem","position":3,"name":"Claude Code as a function"}]}
{"@context":"https://schema.org","@type":"FAQPage","@id":"https://daily.dev/posts/claude-code-as-a-function-wwshtb7qo#faq","mainEntity":[{"@type":"Question","name":"How do I limit how much money an autonomous Claude Code run can spend when I call it from a backend service?","acceptedAnswer":{"@type":"Answer","text":"Set a max_budget_usd parameter when invoking the agent through a harness function; the agent stops as soon as it crosses that dollar cap, so a runaway loop costs exactly that ceiling rather than an unbounded amount. Combine it with a max_turns limit as a second, independent brake, and restrict the tools list (for example Read, Write, Bash) to cap what the agent can actually do. For teams wiring coding agents into unattended pipelines, daily.dev surfaces practical guardrail patterns like this one."}},{"@type":"Question","name":"What is the difference between calling a coding agent for a multi-turn task versus a single reasoning step with tool access?","acceptedAnswer":{"@type":"Answer","text":"A multi-turn coding agent call is appropriate when the task involves navigating a repo it hasn't seen upfront: reading files, deciding what to read next, editing several files, running tests, and iterating on failures. A single reasoning-step call with a short tool loop fits classification, routing, or a bounded structured extraction - essentially one prompt and one answer rather than an open-ended session. Developers deciding between agent architectures can find this kind of practical framing on daily.dev."}},{"@type":"Question","name":"Does the Go SDK for AgentField's coding agent harness return the dollar cost of a run like the Python and TypeScript versions do?","acceptedAnswer":{"@type":"Answer","text":"No, the Go harness result only carries the turn count and duration, not a cost field, so a Go call reads hr.NumTurns but has no hr.CostUsd. Python exposes result.cost_usd and TypeScript exposes result.costUsd, both returning the actual spend, making cost tracking inconsistent across the three SDKs. Engineers building cross-language agent tooling can track SDK parity gaps like this via daily.dev."}}]}
```

