Skip to content

Generate clean 2D game sprites & animation atlases — component-row pipeline: state rows, alpha cleanup, frame extraction, runtime atlases. Codex/Claude skill.

fix(pixel-draw): read a subscription answer from every assistant message, not the result

Soohong Kim44a29ac42a28
diff --git a/CHANGELOG.md b/CHANGELOG.md
index f4639ab..f31217d 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@ All notable public changes to `sprite-gen` are recorded here. Versions track the
## Unreleased
-- **Behavior change: `pixel-draw` runs on your Claude subscription first, and on `ANTHROPIC_API_KEY` only without one** — the order `codex` and `grok` keep. When `claude auth status` says Claude Code is signed in with a subscription (`claude.ai` or `oauth_token`), every call — the drawings, the row repairs, the pick — goes through the unmodified `claude` binary in print mode, from an empty directory, with no tool, no session written and no CLAUDE.md, hook, skill, plugin or MCP server loaded, and costs nothing per call: `report.json` says `auth_source: claude-login`, each call's `mode` is `subscription` and its `cost_usd` `0`, its usage kept. The child never sees `ANTHROPIC_API_KEY`, which print mode would use instead of the login. Without a subscription login the run uses the key as before, billed per call and said on stderr; with neither it is refused naming both, before the run folder is made. A login that refuses a call, has expired or has reached its usage limit fails the call; the run never switches to the key on its own. `--batch` is the API's Message Batches and runs on the key even when signed in. An answer the binary cuts at the output cap is read as `stop_reason: max_tokens`, so the one redraw one effort lower happens on either route. One call may take up to `SPRITE_GEN_CLAUDE_CALL_TIMEOUT_SECONDS` (1800). A `--resume` that reads every call back no longer prints the billing line ([pixel-draw](docs/pixel-draw.md#which-credential-a-call-runs-on)).
+- **Behavior change: `pixel-draw` runs on your Claude subscription first, and on `ANTHROPIC_API_KEY` only without one** — the order `codex` and `grok` keep. When `claude auth status` says Claude Code is signed in with a subscription (`claude.ai` or `oauth_token`), every call — the drawings, the row repairs, the pick — goes through the unmodified `claude` binary in print mode, from an empty directory, with no tool, no session written and no CLAUDE.md, hook, skill, plugin or MCP server loaded, and costs nothing per call: `report.json` says `auth_source: claude-login`, each call's `mode` is `subscription` and its `cost_usd` `0`, its usage kept. The child never sees `ANTHROPIC_API_KEY`, which print mode would use instead of the login. Without a subscription login the run uses the key as before, billed per call and said on stderr; with neither it is refused naming both, before the run folder is made. A login that refuses a call, has expired or has reached its usage limit fails the call; the run never switches to the key on its own. `--batch` is the API's Message Batches and runs on the key even when signed in. An answer the binary continues past the output cap is read whole from every message, not from its `result`, which holds only the last part; one it cannot finish is read as `stop_reason: max_tokens`, so the one redraw one effort lower happens on either route. One call may take up to `SPRITE_GEN_CLAUDE_CALL_TIMEOUT_SECONDS` (1800). A `--resume` that reads every call back no longer prints the billing line ([pixel-draw](docs/pixel-draw.md#which-credential-a-call-runs-on)).
- **Behavior change: every metered call says so on the terminal, and every report names what a call ran on.** How codex is signed in is one reading, `codex_provider.codex_login` (`codex login status`), for the default provider resolution, `gen --provider codex`, the codex facing check and `workflow`: a codex signed in with an API key used to run with no word about it and the workflow called it a subscription; it now prints the per-call charge line before `codex exec` runs, its report records `extra.auth_source: codex-api-key` (`codex-login` on ChatGPT), and `workflow` asks to confirm the API credit. A codex that is not signed in is refused with the reason before it runs. `gen-set` and `video-set` keep each item's output in its log, but a child's billing line and a default provider switch now also print on the terminal as they happen (`base.run_logged`), each `gen-set` row records `auth_source`, and each `video-set` clip result too. `sound` prints the same billing line as every other metered route (it printed its own) and its receipt records `auth_source`. One function reads a provider key from the environment (`base.env_api_key`: a key, none, or a refusal of an empty one) for Anthropic, OpenAI, xAI and ElevenLabs; one function says what to do when xAI rejects a credential (`xai.rejected_fix`), so `gen --provider grok` now gives the same `grok models` refresh as `video`. `workflow` probes a provider once for its images and videos (they share one credential) and asks the API-credit question by that provider's name rather than always about Grok video. Docs: the credential table in the README, grok's `XAI_API_KEY` route in the help and SKILL.md, the sound billing line, `SPRITE_GEN_GEN_TIMEOUT_SECONDS` and `SPRITE_GEN_CLAUDE_READ_TIMEOUT_SECONDS`, and `gen-set --provider` (`codex` or `grok`).
- **Tests** — `tests/gen/test_claude_login.py` (the login before the key, the key only without a login, neither refused naming both, a batch on the key without asking the login, an unreadable status refused rather than read as no login, the child's environment without a key or the calling session, a message mapped onto the binary's flags and stdin with its image and schema, the stream-json answer, a cut answer read as max_tokens, a refused or limited login an error and not a switch to the key, no result, a timeout and a missing binary), the subscription, batch and read-back cases in `tests/gen/test_pixel_draw.py`, and `gen.base.env_api_key` in `tests/gen/test_gen.py`; `tests/gen/test_codex_login.py` (ChatGPT, an API key and not signed in; the default resolution, `generate` and `workflow` read the same login; an API-key login announces the charge and records it), `base.run_logged` in `tests/gen/test_gen.py`, the ElevenLabs billing line and key refusals in `tests/audio/test_sound.py`.
- **New: `background-tile --axis xy` makes one tile seamless in both directions and measures both joins.** It quilts along x, then along y with a cyclic seam: the second seam's two ends, which meet across the x wrap, may differ by one step at most, so the second quilt cannot break the first one's join. The report measures the finished tile on both axes (`axes.x`, `axes.y`, each with its join, quilt seam, `status` and reasons); the top-level `status` is `needs-review` when either axis is, and each reason names its axis. Two separate one-axis runs had no such rule, and the second run's report measured only its own axis. `inspect_tile_xy(image)` measures both joins of any tile ([asset-tools](docs/asset-tools.md#both-axes-a-ground-tile)).
diff --git a/docs/pixel-draw.md b/docs/pixel-draw.md
index 32c2b1b..8c06ab2 100644
--- a/docs/pixel-draw.md
+++ b/docs/pixel-draw.md
@@ -434,9 +434,11 @@ and the login is not asked. One call through the binary may take up to
socket read of the stream may wait `SPRITE_GEN_CLAUDE_READ_TIMEOUT_SECONDS` (300) — the API sends
`ping`s while the model thinks, so a stream silent that long is stalled.
-The binary answers an answer cut at the output cap by asking for a continuation a few times and then
-failing with "exceeded the N output token maximum"; that is read as the API's `stop_reason:
-max_tokens`, so the one redraw one effort lower happens on either route.
+An answer that reaches the output cap is not cut by the binary: it asks for a continuation, which goes
+on in another message, and the answer is read whole from every message in order (the binary's own
+`result` holds only the last part). When the continuations do not finish it fails with "exceeded the N
+output token maximum"; that is read as the API's `stop_reason: max_tokens`, so the one redraw one
+effort lower happens on either route.
The subscription route is for the person running sprite-gen on their own machine, signed in to their
own plan. Anthropic permits an end user signing in to the unmodified Claude Code binary with their
diff --git a/sprite_gen/gen/claude_login.py b/sprite_gen/gen/claude_login.py
index 99bf9fc..6e66e7a 100644
--- a/sprite_gen/gen/claude_login.py
+++ b/sprite_gen/gen/claude_login.py
@@ -19,9 +19,11 @@ claude 2.1.300 the same day:
- `-p --input-format stream-json --output-format stream-json --verbose` takes one user message of
content blocks (text, a base64 image) on stdin and ends with a `result` event: `result` (the text),
`structured_output` (with `--json-schema`), `usage` (the Messages API's), `stop_reason`, `is_error`,
- `subtype`, `api_error_status`. An answer cut at the output cap is not returned as a cut answer: the
- binary asks for a continuation a few times and then ends `is_error` with "exceeded the N output token
- maximum" (`OUTPUT_CAP_ERROR`); that is the API's `stop_reason: max_tokens`.
+ `subtype`, `api_error_status`. An answer that reaches the output cap is not returned as a cut answer:
+ the binary asks for a continuation, which goes on in another assistant message (so the answer is every
+ assistant text in order — `result` holds only the last part), and when continuations do not finish it
+ ends `is_error` with "exceeded the N output token maximum" (`OUTPUT_CAP_ERROR`); that is the API's
+ `stop_reason: max_tokens`.
- `--system-prompt` replaces Claude Code's own prompt (an empty one is accepted), `--tools ""` and
`--strict-mcp-config` leave no tool, `--safe-mode` loads no CLAUDE.md, hook, skill, plugin or MCP
server while the login still works, `--no-session-persistence` writes no session, `--effort` sets the
@@ -204,7 +206,9 @@ def send_message(body: dict[str, Any], *, label: str, env: Mapping[str, str] | N
f"{f', HTTP {status}' if status else ''}): {said[:300]}",
status=status if isinstance(status, int) else None,
billed=bool(usage.get("output_tokens")))
+ # The answer is every text the assistant wrote, in order: past the output cap the binary asks for a
+ # continuation and `result` holds only the last part (2026-10-15: fence and palette lost).
structured = result.get("structured_output")
- text = json.dumps(structured, ensure_ascii=False) if structured is not None else said
+ text = json.dumps(structured, ensure_ascii=False) if structured is not None else ("".join(texts) or said)
return api.Reply(text=text, thinking="\n".join(thinking), stop_reason=result.get("stop_reason"), usage=usage,
model=body["model"], message_id=message_id, mode="subscription", seconds=seconds)