Skip to content

Add Claude Code provider plugin#197

Merged
chubes4 merged 6 commits into
mainfrom
claude-code-provider
Jun 8, 2026
Merged

Add Claude Code provider plugin#197
chubes4 merged 6 commits into
mainfrom
claude-code-provider

Conversation

@chubes4
Copy link
Copy Markdown
Member

@chubes4 chubes4 commented Jun 7, 2026

Summary

  • Add a wp-coding-agents-carried ai-provider-for-claude-code WP AI Client provider backed by Claude Code OAuth credentials and Anthropic Messages API requests.
  • Sync and activate the carried provider during setup/upgrade when Claude Code is the selected or detected runtime.
  • Document the Homeboy Codebox path and add regression coverage for OAuth/API provider routing and read-only Codebox canary construction.

Testing

  • bash -n setup.sh upgrade.sh lib/carried-plugins.sh lib/homeboy.sh lib/agents-md-guidance.sh
  • php -l on all carried-plugins/ai-provider-for-claude-code PHP files
  • bash tests/carried-claude-code-plugin.sh && bash tests/homeboy-codebox-canary.sh && bash tests/agents-md-guidance.sh
  • git diff --check
  • EXISTING_WP="/Users/chubes/Studio/intelligence-chubes4" ./setup.sh --local --runtime claude-code --dry-run --no-chat
  • ./upgrade.sh --local --wp-path "/Users/chubes/Studio/intelligence-chubes4" --runtime claude-code --dry-run --plugins-only
  • php -r 'define("ABSPATH", __DIR__ . "/"); function add_action($hook, $callback, $priority = 10) { call_user_func($callback); } require "carried-plugins/ai-provider-for-claude-code/ai-provider-for-claude-code.php"; echo "loaded\n";'

Live canary

  • claude-code-provider-oauth-canary-20260608-007
  • Provider: claude-code
  • Model: claude-sonnet-4-6
  • Result: succeeded
  • Changed files: 0
  • Patch bytes: 0
  • Evidence paths captured by Homeboy:
    • Status: /var/folders/lr/c_cmmt7s0592m4njz99v5yb40000gn/T/tmp.vUFYw5hhK3/status.json
    • Logs: /var/folders/lr/c_cmmt7s0592m4njz99v5yb40000gn/T/tmp.vUFYw5hhK3/logs.json
    • Artifacts: /var/folders/lr/c_cmmt7s0592m4njz99v5yb40000gn/T/tmp.vUFYw5hhK3/artifacts.json

AI assistance

  • AI assistance: Yes
  • Tool(s): OpenCode (openai/gpt-5.5)
  • Used for: Implemented the carried Claude Code provider plugin, OAuth/API rewrite, setup/upgrade wiring, docs, regression tests, and Homeboy Codebox canary fixes; Chris directed the architecture and remains responsible for review/testing.

@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Status: blocked on WP Codebox Claude Code runtime support

This PR is not done by the Homeboy Codebox cooking gate yet.

What is proven:

  • ai-provider-for-claude-code is mounted and activated by WP Codebox.
  • Homeboy deterministic agent-task orchestration runs and emits Codebox artifacts.
  • The provider reaches execution inside the sandbox.

Failing canary evidence:

  • Run: claude-code-provider-canary-20260608-0002
  • Result: failed
  • Provider plugin loaded: ai-provider-for-claude-code/ai-provider-for-claude-code.php
  • Runtime policy: network: deny, commands: wordpress.wp-cli, wordpress.run-php, hostTools: []
  • Failure: Claude Code exited with status 127
  • Changed files: 0
  • Patch bytes: 0

Additional probe:

  • Run: claude-code-provider-canary-20260608-0004
  • Mounted local /Users/chubes/.local/bin/claude into the runtime as /usr/local/bin/claude
  • Set AI_PROVIDER_CLAUDE_CODE_BIN=/usr/local/bin/claude
  • Result remained Claude Code exited with status 127

Diagnosis:

The PHP provider approach cannot power Codebox cooking until WP Codebox/Homeboy exposes a first-class Claude Code execution surface to the sandbox or runs Claude Code as the outer Codebox agent. The current Playground runtime cannot execute the host-authenticated claude CLI from PHP.

Upstream tracker: Automattic/wp-codebox#807

@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Status update: CLI blocker removed

The provider implementation has been rewritten in commit 91d526e to remove the PHP proc_open / local claude CLI runtime entirely.

Current shape:

  • ai-provider-for-claude-code now extends WP AI Client's API provider path.
  • Auth is Claude Code OAuth via AI_PROVIDER_CLAUDE_CODE_REFRESH_TOKEN plus optional cached access token env/constant/filter values.
  • Requests go to Anthropic Messages API with Claude Code OAuth headers, including Claude Code beta headers and identity prompt.
  • The old ClaudeCodeProcess runtime file has been deleted.
  • tests/carried-claude-code-plugin.sh now asserts the OAuth support files exist and the CLI process runtime is absent.

Verification after rewrite:

  • php -l on all Claude provider PHP files
  • bash tests/carried-claude-code-plugin.sh && bash tests/homeboy-codebox-canary.sh && bash tests/agents-md-guidance.sh
  • git diff --check

Live model-backed Homeboy Codebox canary is still pending because AI_PROVIDER_CLAUDE_CODE_REFRESH_TOKEN is not set in the local shell. The earlier Claude Code exited with status 127 canary evidence applied to the deleted CLI-backed implementation and is superseded by this rewrite.

@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Status update: Homeboy Codebox canary passing

The Claude Code OAuth provider now passes the read-only Homeboy Codebox canary.

Canary evidence:

  • Run: claude-code-provider-oauth-canary-20260608-007
  • Provider: claude-code
  • Model: claude-sonnet-4-6
  • Result: succeeded
  • Changed files: 0
  • Patch bytes: 0

What changed after the earlier OAuth rewrite:

  • Removed the newer ProviderWithRequestAuthenticationInterface dependency so the plugin loads against the PHP AI Client version bundled in Codebox.
  • Explicitly registers ClaudeCodeRequestAuthentication with the WP AI Client provider registry.
  • Makes ClaudeCodeRequestAuthentication compatible with the current registry's API-key auth validation while still applying Claude Code OAuth headers.
  • Serializes non-text message parts into text payload blocks so Agents API tool/function context does not crash text generation.
  • Keeps Discord routing in provider config only; the canary helper no longer passes unsupported --channel / --thread flags to homeboy agent-task dispatch.

Verification:

  • php -l on changed provider PHP files
  • bash tests/homeboy-codebox-canary.sh && bash tests/carried-claude-code-plugin.sh && bash tests/agents-md-guidance.sh && git diff --check
  • Live Homeboy Codebox canary above

@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Status update: Opus 4.8 canary passing

Added claude-opus-4-8 to the provider model map (verified as a live Anthropic model id via /v1/models) and confirmed the read-only Homeboy Codebox canary passes on it.

Canary evidence:

  • Run: claude-code-provider-oauth-canary-20260608-009
  • Provider: claude-code
  • Model: claude-opus-4-8
  • Result: succeeded
  • Changed files: 0
  • Patch bytes: 0

Provider now declares models: claude-opus-4-8, claude-opus-4-7, claude-sonnet-4-6, claude-haiku-4-5.

The provider previously did text-only generation, so the agent's tools
were never declared to Anthropic and the model improvised tool calls as
freeform text that the runtime could not reliably parse.

Declare the agent's function declarations as Anthropic `tools` with an
`input_schema`, serialize FunctionCall/FunctionResponse message parts as
`tool_use`/`tool_result` content blocks, and parse Anthropic `tool_use`
response blocks back into FunctionCall message parts so the runtime's
preferred structured tool-call path executes deterministically. Maps
`stop_reason: tool_use` to FinishReasonEnum::toolCalls() and declares
the functionDeclarations supported option.

Adds a headless smoke test that mocks the HTTP transporter to assert the
request carries structured tools and the response tool_use parses into a
FunctionCall part.
@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Update: structured tool calling added

The provider now implements Anthropic structured tool calling, replacing the prior text-only generation that forced the model to improvise tool calls as freeform text.

Commit fdf79db:

  • Declares the agent's FunctionDeclarations as Anthropic tools with input_schema.
  • Serializes FunctionCall parts as tool_use and FunctionResponse parts as tool_result content blocks.
  • Parses Anthropic tool_use response blocks back into FunctionCall message parts (the runtime's preferred structured path).
  • Maps stop_reason: tool_use to FinishReasonEnum::toolCalls() and declares the functionDeclarations supported option.

Verification

New headless smoke test (tests/structured-tools-smoke.php) mocks the HTTP transporter and asserts, with 14 passing assertions:

  • the outgoing request declares the tool with name/description/input_schema
  • prior FunctionCall/FunctionResponse parts serialize to tool_use/tool_result
  • the response tool_use parses into a FunctionCall part with decoded args and preserved id
OK: 14 structured-tools assertions passed.

Also passing: php -l on all provider files, tests/carried-claude-code-plugin.sh, tests/homeboy-codebox-canary.sh, tests/agents-md-guidance.sh, git diff --check.

Related upstream fixes from this work

Anthropic rejects a Messages request with `tool_use.input: Input should be
an object` when a serialized assistant tool call carried empty or
list-shaped arguments, because an empty PHP array encodes as `[]` rather
than `{}`. Coerce function-call arguments to an object so no-argument tool
calls round-trip correctly, and cover the case in the structured-tools
smoke test.
@chubes4
Copy link
Copy Markdown
Member Author

chubes4 commented Jun 8, 2026

Update: empty tool_use input fix + full chain verified

Commit 8d1a9a6 fixes an Anthropic 400 (tool_use.input: Input should be an object): a serialized assistant tool call with empty/list-shaped arguments was encoding as [] instead of {}. Now coerced to a JSON object, with a smoke assertion (15/15 structured-tools assertions pass).

End-to-end status across the full chain

With the synced runtime (data-machine main + agents-api dev-main + the writable-tools and projection fixes), the structured tool-calling path now reaches Anthropic and the model emits real tool_use blocks. The final runtime gap was that the write workspace tools were never projected as model-facing tools — fixed in Extra-Chill/data-machine-code#606.

Related fixes that make Codebox coding agents work end-to-end:

Remaining note

Opus 4.8 is non-deterministic about emitting a structured tool_use vs. narrating the action in prose; when it narrates, the write does not execute. The provider/runtime plumbing is correct (verified by a real tool_use round-trip and 15/15 headless assertions); the remaining item is model/prompt behavior, tracked separately from this provider PR.

@chubes4 chubes4 merged commit af32950 into main Jun 8, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant