Skip to content

interactive harness: PTY-supervised claude as Agent-SDK alternative - #609

Merged
max-sixty merged 2 commits into
mainfrom
claude-p
May 27, 2026
Merged

max-sixty merged 2 commits into
mainfrom
claude-p

Conversation

@max-sixty

Copy link
Copy Markdown
Owner

Why

Anthropic's June 15 2026 billing split puts @anthropic-ai/claude-agent-sdk on a metered Agent-SDK credit pool. anthropics/claude-code-action (which tend wraps today) calls query() from that SDK under the hood — so today's harness: claude path is exactly what's being metered. Interactive Claude Code in a terminal stays on the flat Pro/Max subscription. This PR adds a harness: claude-interactive path that runs the official claude binary in a PTY supervisor instead. Nothing changes for harness: claude users (or for tend's own workflows) until someone flips the config.

What's added

interactive/action.yaml — new composite action, sibling of codex/action.yaml. Mirrors action.yaml's inputs/outputs for drop-in swappability. Runs claude --permission-mode bypassPermissions "$PROMPT" inside script(1) for PTY allocation. A Stop hook in .claude/settings.local.json writes a sentinel file when the model finishes a turn; a StopFailure hook writes a separate sentinel for rate-limit / auth / server errors. The supervisor polls both, plus process exit and a timeout, then terminates cleanly with SIGTERM/SIGKILL. Pre-seeds workspace trust in ~/.claude.json so interactive claude doesn't block on the first-run dialog (the part claude -p skips automatically). Plugins install via claude plugin install against this action's own checkout.

Generator wiring (config.py, templates/macros.yaml.j2, tests/test_generate.py) — claude-interactive joins KNOWN_HARNESSES as a sibling of claude. The agent_step macro grows a three-way branch for the action ref (max-sixty/tend@, max-sixty/tend/interactive@, max-sixty/tend/codex@). Claude-shaped auth secrets and /tend-ci-runner:NAME slash syntax are preserved via a new CLAUDE_FAMILY_HARNESSES = {"claude", "claude-interactive"} constant. Four new tests cover the routing.

.github/workflows/interactive-smoke.yaml — dispatch-only smoke test that exercises the new action via uses: ./interactive against a trivial Bash-tool prompt. Validates the parts the local spike could not cover: claude install on a fresh Ubuntu runner, plugin install non-interactively with OAuth env auth, Stop hook firing on Linux. Fork-guarded; defaults to sonnet for cheap iteration.

How it detects turn end

Verified in a local spike (Stop fires once per turn in interactive mode, even with tool use, and the process stays alive afterward). Five-line state machine: success sentinel → exit 0; failure sentinel → exit 1 with ::error::; premature process exit → exit with the child's code; timeout → exit 1.

What's deferred

  • allowed_bots / allowed_non_write_users enforcement — was claude-code-action's JS layer; primary gating already happens in generated workflow if: conditions. TODO in the action.
  • Per-workflow harness override — top-level harness: only for now. Flipping harness: claude-interactive switches everything; a per-workflow knob would let nightly trial in isolation if that's wanted.
  • Snapshot tests for every claude-interactive workflow YAML — would mint a dozen new .out files; the four routing tests cover the surface that matters.
  • Cutover — harness: claude continues to be tend's own setting and the default. This PR adds the path; flipping it is a follow-up.

Test plan

  • 246 generator tests pass (242 existing snapshot tests untouched + 4 new)
  • pre-commit run passes on all modified files
  • Local spike confirms Stop hook semantics under script(1)
  • Smoke workflow run on claude-p post-merge confirms end-to-end on a real GHA runner

…ative

Anthropic's June 15 2026 billing split moves the Agent SDK
(@anthropic-ai/claude-agent-sdk) — which is what claude-code-action
invokes under the hood — to a metered Agent-SDK credit pool. Interactive
Claude Code in a terminal stays on the flat Pro/Max subscription. This
adds an alternative composite action that runs the official `claude`
binary inside `script(1)` and uses a Stop hook to detect turn end.

- interactive/action.yaml: new composite action mirroring action.yaml's
  inputs/outputs. Stop hook → success sentinel, StopFailure → failure
  sentinel, supervisor polls both plus process exit plus timeout.
  Pre-seeds workspace trust in ~/.claude.json so interactive `claude`
  doesn't block on the first-run dialog. Plugins installed via `claude
  plugin install` against this action's own checkout.
- generator: `claude-interactive` joins KNOWN_HARNESSES as a sibling of
  `claude`; routes the agent_step macro to max-sixty/tend/interactive@<ver>.
  Keeps Claude-shaped auth secrets and /tend-ci-runner:NAME slash syntax.
- smoke test: .github/workflows/interactive-smoke.yaml is a dispatch-only
  workflow that runs the in-tree action against a trivial Bash-tool
  prompt. Validates the parts the local spike couldn't (`claude plugin
  install` non-interactively on Ubuntu with OAuth env auth, install.sh
  recipe end-to-end).

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>

@tend-agent tend-agent left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two places outside this diff still gate on cfg.harness == "claude" rather than membership in CLAUDE_FAMILY_HARNESSES. With harness: claude-interactive, both fall into the else (Codex) branch and emit Codex-shaped behavior — breaking the "input-shape parity with action.yaml" claim once an adopter flips the config (or runs tend init --with-install-test / tend check).

generator/src/tend/workflows.py — generate_install_test

if cfg.harness == "claude":
    harness_envs = (
        f"          CLAUDE_OAUTH: ${{{{ secrets.{cfg.claude_token_secret} }}}}\n"
        ...
    )
    harness_check = '"$CLAUDE_OAUTH$ANTHROPIC_KEY"'
else:
    harness_envs = (
        f"          CODEX_AUTH: ${{{{ secrets.{cfg.codex_auth_json_secret} }}}}\n"
        ...
    )
    harness_check = '"$CODEX_AUTH$OPENAI_KEY"'

With harness: claude-interactive, the generated tend-install-test.yaml checks for CODEX_AUTH_JSON/OPENAI_API_KEY secrets that the adopter doesn't have, so the install-test workflow fails noisily on a correctly-configured repo.

generator/src/tend/checks.py — run_all_checks

engine_auth_secrets = (
    [cfg.claude_token_secret, cfg.anthropic_api_key_secret]
    if cfg.harness == "claude"
    else [cfg.openai_key_secret, cfg.codex_auth_json_secret]
)
...
if cfg.harness == "claude":
    results.append(check_claude_auth(repo, cfg))
else:
    results.append(check_codex_auth(repo, cfg))

uvx tend check against a harness: claude-interactive repo runs check_codex_auth, complaining about absent Codex secrets and reporting Claude OAuth as "extra/unallowed" via check_repo_secret_allowlist.

Fix is mechanical — swap each cfg.harness == "claude" for cfg.harness in CLAUDE_FAMILY_HARNESSES (already imported / defined in config.py). The install-test snapshot test would also catch this if parameterized over ["claude", "claude-interactive", "codex"] instead of ["claude", "codex"] (test_install_test_workflow_regtest in generator/tests/test_generate.py).

Happy to push a fix commit if you'd like.


Other notes (not blocking, flagging for awareness):

  • The action's Pin CLAUDE.md to base branch (fork PRs) step pins only CLAUDE.md. claude-code-action additionally restores .claude/, .mcp.json, .claude.json, .gitmodules, .ripgreprc from base on fork PRs — the comment in this action calls this out as a known gap. Worth flagging in docs/security-model.md before any adopter flips a pull_request_target workflow to claude-interactive, given the RCE surface in .claude/.
  • claude-interactive-session-logs* is a new artifact-name shape. plugins/install-tend/skills/debug-tend-run/SKILL.md currently enumerates only claude-session-logs* and codex-session-logs-* — fine to defer until the cutover, but worth a follow-up.

Reviewer caught two `cfg.harness == "claude"` checks outside the diff
that would mis-classify `claude-interactive` as Codex:

- `generate_install_test` (workflows.py) → produced an install-test
  workflow asserting CODEX_AUTH_JSON / OPENAI_API_KEY presence instead
  of CLAUDE_CODE_OAUTH_TOKEN / ANTHROPIC_API_KEY.
- `run_all_checks` (checks.py) → invoked check_codex_auth and treated
  the Claude OAuth secret as an unallowed extra in the secret allowlist.

Both now use `cfg.harness in CLAUDE_FAMILY_HARNESSES`. The install-test
regtest is parameterized over claude-interactive; the new snapshot is
byte-identical to the claude one. A new test in test_checks.py asserts
run_all_checks emits claude-auth (not codex-auth) and that the secret
allowlist passes under claude-interactive.

Also adds a security-model.md paragraph noting the interactive harness
does not yet restore the RCE-relevant config files (.claude/, .mcp.json,
…) that claude-code-action restores on fork PRs — adopters should not
flip a pull_request_target workflow to claude-interactive until parity
is restored.

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty

Copy link
Copy Markdown
Owner Author

Fixed in 4b92c13. Both gates now use cfg.harness in CLAUDE_FAMILY_HARNESSES:

  • generate_install_test → install-test workflow now references CLAUDE_CODE_OAUTH_TOKEN / ANTHROPIC_API_KEY under claude-interactive (snapshot is byte-identical to the claude one).
  • run_all_checks → emits claude-auth, not codex-auth, and the secret allowlist no longer flags the Claude OAuth token as extra.

Test coverage:

  • test_install_test_workflow_regtest parameterized to include claude-interactive.
  • New test_claude_interactive_runs_claude_auth_check in test_checks.py asserts the check-routing + allowlist behavior.

Also added a docs/security-model.md paragraph noting the interactive harness does not yet restore .claude/ / .mcp.json / etc. on fork PRs — adopters should not flip pull_request_target workflows to claude-interactive until parity is restored. Tracked as follow-up after the trial.

Holding off on the debug-tend-run skill update (claude-interactive-session-logs* artifact name) until we know the trial actually proceeds — happy to bundle later if you'd like.

This was written by Claude Code on behalf of Maximilian.

@tend-agent

Copy link
Copy Markdown
Collaborator

Confirmed the fix lands cleanly:

  • workflows.py:378 and checks.py:452,467 both gate on cfg.harness in CLAUDE_FAMILY_HARNESSES.
  • test_install_test_workflow_regtest is parameterized over claude-interactive and the new snapshot is byte-identical to the claude one.
  • test_claude_interactive_runs_claude_auth_check asserts the claude-auth routing and a clean secret allowlist.
  • docs/security-model.md calls out the .claude/ / .mcp.json restoration gap and the pull_request_target caveat.

Agreed on deferring the debug-tend-run skill update — adding a claude-interactive-session-logs* enumeration before any consumer flips the harness would be speculative content in a skill that's loaded on every relevant session. Better to land it alongside the cutover when a real artifact of that shape exists to debug.

@max-sixty
max-sixty merged commit e79095d into main May 27, 2026
6 checks passed
@max-sixty
max-sixty deleted the claude-p branch May 27, 2026 03:11
max-sixty added a commit that referenced this pull request May 27, 2026
…on PRs (#611)

## Why

Three follow-ups to #609. All scoped to the `interactive` harness
(opt-in via `harness: claude-interactive`); nothing in the existing
`claude` or `codex` paths changes.

## What

**1. Fix the onboarding block (the actual smoke-test blocker).** First
smoke run on `main`
(https://github.com/max-sixty/tend/actions/runs/26488447138) timed out
at 300s with 0 turns. The supervisor's transcript dump showed `claude`
blocked at the theme picker: "Choose the text style that looks best with
your terminal". The workspace-trust pre-seed in #609 didn't cover the
broader onboarding flow. This commit sets `hasCompletedOnboarding`,
`lastOnboardingVersion` (matched to the installed claude version),
`theme`, and the per-project trust + onboarding keys — `claude` reaches
the prompt-processing loop immediately.

**2. Security parity for fork PRs.** Replace the `CLAUDE.md`-only pin
with the full RCE-vector restoration that `claude-code-action` does
today: `.claude/`, `.mcp.json`, `.claude.json`, `.gitmodules`,
`.ripgreprc`, `CLAUDE.md`, `CLAUDE.local.md`, `.husky`. Same path list
and ordering as `restore-config.ts` in `anthropics/claude-code-action`.
Runs on all PR events (including PR-comment `issue_comment`), snapshots
PR-authored versions to `.claude-pr/` for optional review inspection
(added to `.git/info/exclude`), deletes before fetching to keep an
attacker-controlled `.gitmodules` out of git's `recurse-submodules` code
path, then `git checkout origin/<base> -- <path>` and `git reset` to
unstage. `docs/security-model.md` updated.

**3. `debug-tend-run` skill: recognize the new artifact.** Lists
`claude-interactive-session-logs*` alongside the existing patterns and
notes the typescript log (`tend-claude.log`) shipped at the artifact
root for cases where the JSONL is incomplete (session aborted before
Stop).

## Test plan

- [x] 248 generator tests pass (no generator changes here, but rerun
green)
- [x] `pre-commit` passes on all modified files
- [ ] Re-run `interactive-smoke` workflow after merge — confirm Stop
hook fires, turns > 0
- [ ] Eventually: exercise the restore step on a real fork PR (this PR
is same-repo, so the restore is a no-op on its own CI)

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty max-sixty mentioned this pull request May 27, 2026
2 tasks done
max-sixty added a commit that referenced this pull request May 27, 2026
## Why

Lets adopters trial a new harness on a single workflow without flipping
the whole bot. Concrete use case: try `harness: claude-interactive` on
`nightly` while keeping PR review / mention on the production `claude`
harness. Trial-safe rollout for the interactive harness added in #609 /
#611.

## What

- `WorkflowConfig` gains an optional `harness` field. `Config.load`
validates the value is a known harness and (cross-family only)
compatible with the top-level model.
- Same-family overrides (claude ↔ claude-interactive) share the model
set, no compatibility error.
- Cross-family overrides (codex → claude/claude-interactive with a codex
model name like `gpt-5.5`, or vice versa with a per-workflow model
unset) fail at config load with a clear message: "workflows.X.harness
'claude' is incompatible with the top-level model 'gpt-5.5'…
Cross-family per-workflow harness overrides require setting `model:`
per-workflow too, or changing the top-level model."
- `workflows.py`: a new `_effective_cfg(cfg, wf)` helper returns `cfg`
unchanged when there's no override, or `dataclasses.replace(cfg,
harness=wf.harness)` otherwise. Each generator function (review,
mention, triage, ci-fix, scheduled, notifications) calls it once and
passes the effective config to both the template and `default_prompt`.
No template changes — `agent_step` still reads `cfg.harness` from
whatever `cfg` it gets.
- Tests: per-workflow override targets only the named workflow (sibling
workflows keep the top-level harness), unknown harness rejected,
cross-family model mismatch rejected, same-family override loads
cleanly.

## Example

```yaml
bot_name: tend-agent
harness: claude
# Trial the interactive harness on nightly only — review/mention/triage
# stay on the SDK-based claude harness until we're confident.
workflows:
  nightly:
    harness: claude-interactive
```

## Test plan

- [x] 252 tests pass (4 new); existing snapshots untouched
- [x] `pre-commit run --all-files` passes

---------

Co-authored-by: Claude Opus 4.7 (1M context) <[email protected]>
@max-sixty max-sixty mentioned this pull request May 27, 2026
max-sixty added a commit that referenced this pull request May 27, 2026
## Why

Cut the 0.1.2 release so consumer repos (and tend's own nightly regen)
pick up the new
`claude-interactive` harness and per-workflow `harness`/`model`
overrides.

## What's new since 0.1.1

**New `claude-interactive` harness**
(`max-sixty/tend/[email protected]`) — opt-in
alternative to the released `claude` harness. PTY-supervised interactive
`claude` via
`script(1)`, end-of-turn detected through Stop/StopFailure hooks. Built
as the
trial path ahead of Anthropic's June 15 billing split between Agent-SDK
metering and
the flat Claude Code subscription. Smoke tested end-to-end on tend
itself. PRs:
#609, #611, #613, #614, #615, #616.

**Per-workflow `harness` / `model` override** — adopters can flip a
single workflow
to a different harness or model without changing `.config/tend.yaml`
defaults. #612.

**Skill refinements** — nightly upstream-bot rebases (#605),
running-in-ci PR bar
(#604) and recheck (#573), env-filter loophole fix (#599),
authorAssociation warning
(#600), review-gates Gate 1 (#602).

**Bug fix** — mention queue-delay now uses `comment.updated_at` so edit
events report
accurately (#595).

## Compatibility

Released `claude` harness path is byte-identical; `claude-interactive`
is strictly
additive and opt-in. Consumer repos that don't touch `harness:` see no
change beyond
the new skill text and the mention-edit fix.
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.

2 participants