Claude Code provides no in-session determinism mechanism, forcing automation users onto the metered Agent SDK path

Status Closed — not planned
Maintainer reply None cached
Activity 11 comments · opened May 14, 2026 · closed Aug 28, 2026

Problem Statement

Anthropic's own legal page describes subscriber-included use as:

Advertised usage limits for Pro and Max plans assume ordinary, individual usage of Claude Code and the Agent SDK. — https://code.claude.com/docs/en/legal-and-compliance

"Ordinary individual usage" includes automation of one's own workflow on one's own machine. Automating a personal quality process is a normal individual activity, not third-party product development.

The problem is that Claude Code as currently designed offers no first-class mechanism for deterministic execution inside the interactive session. Same prompt produces different actions across runs. Slash commands and skills are prose loaded into context — they shape the model's behavior but do not constrain it to a fixed step sequence. There is no protocol/playbook mode that commits to executing N steps in order, no schema-validated tool outputs that fail hard on deviation, no idempotent step machinery, no built-in transactional/checkpoint semantics, no "no-LLM-judgment" mode that dispatches deterministic operations from a registered registry.

The architectural gap is well understood: a multi-step quality process at 99% per-step accuracy is not a quality process — it is a partially-supervised assistant. Determinism requires code, not prose.

The only available path to the determinism that "automation" implies is therefore to leave the interactive session and wrap claude -p in a deterministic Python or TypeScript harness — exactly what the Agent SDK is designed for. This is not an alternative architecture I chose for convenience; it is the only mechanism the product permits to deliver on the "individual automation" promise its own legal page makes.

The June 15, 2026 pricing change then meters that forced path separately:

Starting June 15, 2026, Claude Agent SDK and claude -p usage no longer counts toward your Claude plan's usage limits. [Affected:] Claude Agent SDK usage in your own projects (Python or TypeScript); the claude -p command in Claude Code (non-interactive mode); the Claude Code GitHub Actions integration; third-party apps that authenticate with your Claude subscription. Eligible Pro, Max, Team, and Enterprise plan users can claim a separate monthly credit. Pro: $20/month. Max 5x: $100/month. Max 20x: $200/month. When your monthly credit runs out, additional Agent SDK usage flows to extra usage at standard API rates — but only if you've enabled extra usage. If extra usage isn't enabled, Agent SDK requests stop until your credit refreshes. — https://support.claude.com/en/articles/15036540-use-the-claude-agent-sdk-with-your-claude-plan

The net effect is that Anthropic's pricing model penalizes the only mechanism it provides for the "ordinary individual usage" capability its legal page implicitly promises. The third-party-product use case the change is appropriately targeted at (and which already requires API key auth per the legal page) is not the use case I am describing.

Existing related signals from this repo

  • #37686 — claude -p suggested to a Max subscriber, caused $1,800+ unintended API billing
  • #45572 — Claude Code CLI usage incorrectly classified as API billing on Max subscription
  • #56250 — Subscription quota eligibility for child_process.spawn("claude", ...) from owner-only local backend is undocumented

These are surface symptoms of the same underlying issue: there is no clean place in the product for a solo subscriber who needs deterministic workflow automation against their own projects.

Proposed Solution

Either of the following — ideally both:

(1) Provide first-class determinism mechanisms inside Claude Code interactive, so users do not have to leave the session to get repeatability:

  • A protocol/playbook mode that commits the session to executing a named sequence of steps in order, with no skip, no reorder, and no paraphrase. Each step has structured inputs and outputs.
  • Schema-validated tool outputs: a step declares the JSON shape it must produce, and the session fails hard (rather than continuing or improvising) if the model produces something else.
  • Idempotent step machinery: re-running step N from a checkpoint produces the same effect, allowing the session to be safely resumed after a crash, interrupt, or human review pause.
  • A "deterministic dispatch" mode in which the LLM's role is to choose from a registered, fixed set of operations and the session executes them as code — no free-form generation in the action path.

This would let "individual automation" happen inside the subscription-pool interactive session, where the legal page already says it belongs.

(2) Or, recognize that as long as (1) is missing, subscription-pool claude -p use is the natural consequence, and price it accordingly:

  • Keep solo, single-user, owner-only claude -p invocations on the regular subscription limit when the auth context is the subscriber's own OAuth token, the cwd is the subscriber's own checkout, and the calls are not being routed on behalf of other users.
  • The third-party-credential-routing prohibition already in the legal page is the correct enforcement boundary; the -p flag itself is not a reliable proxy for "this is a third-party product."

Use Case Example

A solo developer maintains a private codebase with a multi-step quality process: pre-commit hooks, internal review, automated review-thread classification and resolution, premerge checks, post-merge retrospective. Each step has well-defined inputs, outputs, and failure modes; missing or misordering a step is a defect the process is specifically designed to catch.

The LLM's role is bounded subtask execution: generate a diff for a specific review thread, classify a thread by intent, draft a retrospective section. The orchestrator decides what to call, validates each result against a schema, and fails hard if the contract isn't met. The same single subscriber, on the same machine, is at the keyboard for both the interactive Claude Code session and the orchestrator that spawns claude -p. Nothing is being routed on behalf of any other user. No third-party product is being built.

This pattern was built specifically because interactive Claude Code is not deterministic enough to drive a quality process directly — there is no in-session machinery to commit to a step sequence, validate outputs against a schema, or fail hard on deviation. The Python+claude -p layer is doing the work the product itself does not yet do.

Alternative Solutions

  • Treat claude -p invocations from a verified OAuth-authenticated context, on the subscriber's own machine, against the subscriber's own checkout, as ordinary subscription use. The auth context already distinguishes this case from third-party services routing through subscriber credentials.
  • Provide first-class cost telemetry surfaced in the subscriber's account dashboard. Today, total_cost_usd is in every claude -p --output-format json envelope but is not aggregated or reported back to the user. Subscribers have to instrument their own pipelines to see what they're spending — which means the first time most users learn they have crossed a billing threshold is when the threshold has already been crossed (#37686 is the canonical case).
  • Document explicitly which claude -p invocation contexts count as subscription use vs. Agent SDK metered use. The current categorization is keyed off the -p flag, which is not informative about whether the invocation is third-party productization or owner-attributed automation. Issue #56250 is asking for exactly this clarity.

Additional Context

The pattern this issue describes — Python orchestration around claude -p with schema validation and fail-hard gates — is not unusual or marginal. It is the standard pattern for obtaining reliable, repeatable execution from an LLM in any context, and Anthropic ships and supports the Agent SDK precisely because of that. The disagreement is not whether the pattern is legitimate, but whether solo subscribers exercising this pattern on their own projects should be priced into the same metered pool as commercial product builders.

The cleanest resolution is to close the gap that forces them out of the interactive session in the first place. Until then, recognizing solo claude -p use as part of the "ordinary individual usage" the legal page already names would honor what the policy already says.

View original on GitHub ↗

9 Comments

kcarriedo · 3 months ago

The framing here is precise and the use case is real. A few things worth surfacing for the thread:

The architectural gap you describe predates the June 15 pricing change and will survive any pricing fix. The issue isn't primarily that claude -p costs money — it's that interactive Claude Code genuinely cannot deliver the step-sequence commitment, schema validation, and fail-hard-on-deviation that a quality process requires. The pricing change just made the cost of the forced workaround visible. If Anthropic reprices claude -p for solo/owner-auth contexts tomorrow, the underlying problem (interactive session is not a reliable orchestrator) remains.

Three patterns that people reach for independently, all with the same problem:

  1. Skills/slash commands as pseudo-orchestration — define steps as prose in .claude/commands/. Works until the model elides a step, reorders, or paraphrases. No fail-hard gate.
  2. Bash wrapper around claude -p — adds idempotency and schema validation at the cost of metered API usage + rewrite-from-scratch for every team.
  3. External process orchestrator — Rust/Python process manages agent lifecycle, passes structured inputs via stdin/file, validates outputs against schema. This is the only pattern that actually delivers the contract you describe. Also requires the most infrastructure.

On the schema-validation proposal: the specific ask for "structured outputs that fail hard on deviation" maps directly to claude -p --output-format json + a JSON schema validation step in the harness. That combination works today — it's just not inside the interactive session, which is your point. The gap is that the interactive session has no equivalent of "declare expected output shape; abort step if shape isn't met."

On the pricing framing: the cleanest boundary for Anthropic to enforce isn't the -p flag or OAuth context — it's whether the claude -p call is in the critical path of a request-response loop that serves a third party. Solo subscriber, own checkout, own machine, no upstream user waiting for a response = clearly subscription use. The API key vs. OAuth distinction is a reasonable proxy but not a definitive one.

Worth noting: the feature request in option (1) of your proposed solution — a protocol/playbook mode inside the interactive session — is the thing that would make the pricing question moot for a large fraction of the affected use cases.

kcarriedo · 3 months ago

This issue articulates something I've been running into from the other side of the fence while building Claudeverse — a scheduling layer that dispatches Claude agents on a cron cadence rather than interactively.

The determinism gap you describe is real. claude -p is the only path to anything resembling "run this sequence, expect this shape of output" — but you're right that the June 15 metering change makes that a cost decision, not just an architecture decision. For solo automation workloads that are genuinely within "ordinary individual usage" intent, that's a frustrating asymmetry.

A few practical notes from building on top of claude -p in an out-of-process scheduler context:

  1. Idempotency via cycle IDs: Generating a UUID before the agent call and passing it as an environment variable (CYCLE_ID) lets the agent stamp all its CodeBake/state writes with that ID. Re-running the same cycle ID is a no-op — you get determinism at the workflow level even without determinism inside the session.
  1. Schema coercion at the boundary: Rather than expecting structured JSON from the agent (unreliable with outputFormat: json_schema when using the Task tool), we extract structured fields from free-form agent output with a regex fallback. Not elegant, but it survives the non-determinism of the session layer.
  1. Cost transparency: For anyone not seeing aggregated cost in the dashboard, the total_cost_usd per-response field can be summed in the caller. We log it as a JSON metric per agent invocation and surface it in our runner's health endpoint.

None of this addresses the architectural gap you're describing — Anthropic needs to ship a first-class determinism mechanism or explicitly document claude -p as a non-metered automation path for subscribers. But if it helps to see how others are working around it in the meantime: happy to share more from our setup.

kcarriedo · 2 months ago

This surfaces something that doesn't get discussed clearly enough: the gap between "Claude Code's interactive model" and "what serious automation users actually need" is forcing a platform fragmentation that shouldn't exist.

The June 15 claude -p reclassification makes this painfully concrete. Users who were running claude -p as their only reliable path to deterministic, scriptable workflows — not because they wanted the API overhead, but because the interactive session's non-determinism made it unsuitable for automation — now face unexpected metered billing for what was, practically speaking, solo developer workflow usage.

The two proposed solutions hit the right axes:

  1. First-class determinism primitives in the interactive session (protocol/playbook mode, schema-validated tool outputs) would let users stay on the plan-included path while getting reliable automation.
  2. Recognizing solo claude -p with subscriber OAuth as subscription-included aligns legal intent with billing reality.

For anyone blocked on this right now: we've been building session coordination and workflow state tracking on top of Claude Code to address the reliability and multi-session tracking gaps — it's what led to Claudeverse (https://claudeverse.ai). The determinism problem is one of the core failure modes we keep seeing. Happy to compare notes if useful.

The $1,800-in-two-days scenario in the issue is the kind of outcome that makes teams shelve automation workflows entirely. This needs to be resolved at the platform level.

m13v · 2 months ago

the owner-vs-third-party split holds at oauth-declaration but collapses at the meter, which keys off the -p flag, not who's at the keyboard.

kcarriedo · 2 months ago

The pricing-as-architecture-forcing-function argument here is really well put. The metering boundary is effectively Anthropic saying "interactive = subscription, headless = API" — but as you point out, that boundary cuts across a use case (solo developer scripting their own machine) that the legal docs explicitly classify as ordinary individual use.

A few related pains from the same category that I've run into:

The --resume context cost problem. When you use claude -p with --resume to maintain session continuity, you're still rebuilding context from the transcript on each invocation. The longer the prior session, the more input tokens you burn just to re-establish state — even if the actual new work is tiny. This makes any agentic cron job progressively more expensive over time with no natural ceiling.

No idempotency primitive. For true workflow automation, you want "run this step, and if it already ran successfully, skip it" to be a first-class concept. The current model makes you implement that yourself (usually via filesystem sentinels), which then becomes part of your agent's instruction surface and contributes to CLAUDE.md bloat.

The --output-format json boundary. When you switch from interactive to -p for automation, you also lose the ability to do things like trigger hooks, which means any safety gates you built into your interactive session don't carry over. You're essentially running a different product.

The determinism feature request (playbook mode with schema validation + checkpoint semantics) would address all three of these. Happy to add specifics if it's useful to whoever picks this up.

kcarriedo · 2 months ago

The pricing change on June 15 made this significantly sharper. Before, claude -p was the only workaround for reliable step sequencing, and it drew from the same subscription pool -- acceptable. Now it has its own separate credit limit, so the "escape hatch" for deterministic automation has become a billing surprise waiting to happen for anyone who built workflows assuming the old model.

The core gap you are describing is that interactive Claude Code is non-deterministic by design (turn-by-turn model decisions), but there is no middle path between "interactive and unpredictable" and "fully programmatic and separately metered."

A few partial mitigations I have used:

  1. Structured JSON output via a post-tool hook that validates the schema and retries the step if validation fails -- not true schema enforcement but catches the worst drift
  2. /plan mode before any multi-step workflow -- forces Claude to commit a step list you can diff against later
  3. Breaking the workflow into single-step claude -p calls each within the Pro credit limit, rather than one long pipeline

None of these fully solve the problem. The Option 1 you proposed (determinism features inside interactive Claude Code) would address this cleanly. For automation users the current situation is: build your own harness, or pay the pricing penalty.

kcarriedo · 2 months ago

The determinism gap you're describing is real, and the billing catch is rough on top of it. Running claude -p for reliable step-sequencing is the only path that works today, but now that path has a separate credit meter - so you're paying twice: once for the interactive session you can't trust for automation, and again for the programmatic layer you built as a workaround.

Worth naming the specific pattern we keep seeing: the problem isn't just non-determinism - it's that there's no observable handoff point between steps. When a run goes off-script you don't know if the agent skipped a step, misread the schema, or just had a bad token sample. Without that observability, the only fix is "run it again and hope."

One approach that's helped for scheduled/autonomous workflows: run the coordinating process out-of-session (as a lightweight scheduler that spawns and monitors claude -p invocations), keep per-agent state in a flat file or SQLite, and treat each invocation as a discrete unit you can retry independently. Lets you get idempotent step sequencing without rebuilding everything in the Agent SDK.

Disclosure: I'm building Claudiverse (claudeverse.ai), a session coordinator for multi-agent Claude Code workflows. This issue describes the exact problem we're trying to address. Happy to share notes on what's worked.

kcarriedo · 2 months ago

The determinism gap you describe is real and the billing surprise pattern you reference (#37686) is one of the clearest examples of what happens when there is no checkpoint or transactional boundary in a long-running session.

The forced-onto-metered-path problem is specifically painful because claude -p is the only way to get structured, scriptable, repeatable execution -- but crossing that boundary now converts subscription credits to per-token API billing, which can produce exactly the surprise invoices that make automation feel too risky to run unattended.

A few patterns that help at the workflow level while waiting for native determinism support:

  1. Phase-scoped sessions with structured exit conditions. Instead of one long session, break the workflow into discrete phases where each session runs exactly one phase, writes its output to disk in a defined schema, and exits. The next session reads that output before starting. Interrupt a phase and you restart just that phase, not the whole pipeline.
  1. Pre-phase validation hooks. Before the session starts doing anything irreversible, run a validation step (can be a separate short claude -p call) that checks preconditions and returns a structured pass/fail. If it fails, you abort before spending tokens on the main task.
  1. Idempotent task design. Structure prompts so that re-running them on the same input produces the same output (or at least a safe output). Works for clearly bounded tasks; breaks down for tasks with side effects or external API calls.

None of these substitute for the native checkpoint/transactional semantics you are asking for. The core request -- a protocol mode that commits to a step sequence, validates schema at each boundary, and supports retry without replay -- is the right framing. The pricing-model-penalizes-the-only-automation-path observation is the part that should get prioritization attention.

kcarriedo · 1 month ago

This hits a real gap that doesn't get enough attention. The subscription-vs-metered split forces a false choice: interactive sessions are unpredictable (you cannot safely wire them into a CI pipeline or a scheduled automation), but adding determinism currently means moving to the metered API path - even when the underlying task is ordinary individual development work.

The practical result is that solo developers running scheduled workflows against their own projects get charged per-agent-hour on top of their subscription, for work that is structurally identical to what a human does interactively but happens to run at 2am.

A few concrete cases where the determinism gap bites:

  1. Nightly dependency triage: run a subagent against your lock file, output a structured diff. Simple, bounded, no humans in the loop. Currently only safe via claude -p + Agent SDK credits.
  2. Pre-commit code review passes: hook-triggered, deterministic input/output contract. Same problem.
  3. Scheduled project health checks: ask an agent to scan for drift from the architecture document, write findings to a file. Reproducible, bounded scope, but not interactive.

All three are textbook "ordinary individual usage" - the user's own projects, no external distribution, same compute volume as a human afternoon session. The pricing page says this is covered. The technical reality is it isn't, because the interactive session offers no determinism guarantees that make it safe to run unattended.

The idempotent step machinery point in the OP is the right frame. Even a simple mechanism - a session flag that commits to a fixed tool sequence and hard-fails on deviation - would separate the "I need a deterministic automation primitive" use case from the "I need cloud-scale parallel agent infrastructure" use case that the Agent SDK is actually designed for.

(Context: building Claudeverse - claudeverse.ai - a polling runner and coordination layer for Claude Code agent workflows, so this intersection of subscription semantics + automation is something we run into constantly.)

Showing cached comments. Read the full discussion on GitHub ↗