Claude Opus 5.5 (effort default (no --effort flag) · thinking on) on Refactor nested legacy pricing code + add a bulk-discount rule with exact behaviour preservation
AClaude Opus 5.5default · thinking on · Claude Code 2.1.299 (headless -p) · cloud · 2026-10-16 · by @bobsiopener
- Estimated cost
- $0.28
- Wall time
- 1m
- Human step-ins
- 0
- Outcome
- Pass
Compare with other models on this task →
Summary
Exact prompt
# Task: refactor the legacy pricing engine and add one rule `pricing.py` has a deeply nested `price(order)` function. 1. Refactor it so it is readable: no function may have nesting depth greater than 3 (if/for/while/with/try blocks), and the category/tier discounts must live in a data table, not if-chains. Behaviour must stay IDENTICAL for every order (outputs are compared to the old version on hundreds of random orders, rounded to cents). 2. Add a new rule: **bulk discount** — any line item with qty >= 10 gets an extra 5% off that line, applied after the tier discount and before coupons. The bulk discount does NOT combine with coupon "SAVE20" (if SAVE20 is present, no bulk discount anywhere). Keep the signature `price(order) -> float`. Add tests in `test_pricing.py`. No network, no new dependencies. Order shape: {"customer":{"tier":"gold|silver|none"},"region":"EU|US|ROW","coupon":null|"SAVE10"|"SAVE20"|"FREESHIP","items":[{"category":"books|electronics|toys|garden","unit":float,"qty":int}]}
Refactor a deeply nested legacy pricing function into readable code with a discount table, then add a bulk-discount rule. Behaviour must stay identical to the cent on 800 random orders, including several odd regional tax and shipping quirks that a careless refactor would 'fix'. Nesting depth and the data-table requirement are checked from the code's syntax tree. Original benchmark task written for usecaserank.com (not based on a specific public post). Headless, offline run on a reproducible fixture. Each run's notes say how its cost was measured (estimates are marked).
Success criteria: 1. price(order) is called on 800 seeded random orders (tiers, regions, coupons, quantities incl. >=10) and must match the reference implementation within half a cent on every order (0 mismatches); exceptions count as mismatches. 2. Maximum nesting depth of if/for/while/with/try inside any function must be <= 3 (elif chains count as one level), measured with the AST. 3. pricing.py must contain a dict literal mentioning 'gold' (tier discounts kept in a data table).
Setup notes: Use Case Scout batch 3 case c02-refactor-pricing (offline fixture). Prepared with batch3/prepare.sh; hidden key/tests kept outside the agent's work dir. Prompt = TASK.md verbatim. Scored with the scout's scorer: `python score.py WORKDIR`. Tools: Read/Write/Edit/Glob/Grep/Bash, web disabled. Single run, no retries. Claude Code's own reported cost for claude-opus-5.5: $0.27509. Score: 1/1 checks. Cost is an ESTIMATE: measured tokens x pricing.json list price (Claude Pro subscription, nothing billed); input_tokens include cache reads and writes. Single run.
Estimated cost List-price estimate; not actually billed.
Metrics
- Estimated cost
- $0.28
- Wall time
- 1m
- Human step-ins
- 0
- Turns
- 7
| Model | Input tok | Output tok | Cost |
|---|---|---|---|
| AClaude Opus 5.5anthropic/claude-opus-5.5effort default (no --effort flag) · thinking on | 130,457 | 6,857 | $0.28 |
Reproduce this run
- Use the use case prompt on the use case page.
- Same setup: Claude Opus 5.5 (anthropic/claude-opus-5.5, effort default (no --effort flag) · thinking on) via
Claude Code 2.1.299 (headless -p), cloud. - It counts as a success only if it meets every success criterion: 1. price(order) is called on 800 seeded random orders (tiers, regions, coupons, quantities incl. >=10) and must match the reference implementation within half a cent on every order (0 mismatches); exceptions count as mismatches. 2. Maximum nesting depth of if/for/while/with/try inside any function must be <= 3 (elif chains count as one level), measured with the AST. 3. pricing.py must contain a dict literal mentioning 'gold' (tier discounts kept in a data table).
- Log model, tokens, wall time, human step-ins and the evidence log, then submit it as a reproduction. A different model? Submit a head-to-head rerun.
How runs are scored: Methodology.
Was this useful?
Automated checks
Trust 80% comes from these checks (how Trust % works).
- Run date is not in the future : passed
- Model is in the dated pricing table : passed
- Cost recomputed from tokens matches : passed
- Cached tokens are consistent : passed
- Output throughput is plausible : passed
- Autonomy matches step-ins : passed
- Step-ins do not exceed turns : passed
- Retries agree with first-try result : passed
- Evidence log SHA-256 matches : passed
- Evidence log is substantial : passed
Evidence log
[
{
"duration_api_ms": 68242,
"stop_reason": "end_turn",
"session_id": "[REDACTED]",
"total_cost_usd": 0.27509,
"usage": {
"input_tokens": 12,
"cache_creation_input_tokens": 14335,
"cache_read_input_tokens": 116110,
"output_tokens": 6857,
"output_tokens_details": {
"thinking_tokens": 1006
},
"server_tool_use": {
"web_search_requests": 0,
"web_fetch_requests": 0
},
"service_tier": "standard",
"cache_creation": {
"ephemeral_1h_input_tokens": 14335,
"ephemeral_5m_input_tokens": 0
},
"inference_geo": "global",
"iterations": [
{
"input_tokens": 2,
"output_tokens": 823,
"cache_read_input_tokens": 25460,
"cache_creation_input_tokens": 1021,
"cache_creation": {
"ephemeral_5m_input_tokens": 0,
"ephemeral_1h_input_tokens": 1021
},
"type": "message"
}
],
"speed": "standard",
"fallback_credit": null
},
"modelUsage": {
"claude-opus-5-5": {
"inputTokens": 12,
"outputTokens": 6857,
"cacheReadInputTokens": 116110,
"cacheCreationInputTokens": 14335,
"webSearchRequests": 0,
"costUSD": 0.27509,
"contextWindow": 1000000,
"maxOutputTokens": 128000,
"thinkingTokens": 1006,
"canonicalModel": "claude-opus-5-5",
"provider": "firstParty",
"costBasis": "list"
}
},
"permission_denials": [],
"terminal_reason": "completed",
"fast_mode_state": "off",
"fast_mode_disabled_reason": "sdk_opt_in_required",
"subagent_stats": {
"spawned": 0,
"requested": {
"background": 0,
"foreground": 0,
"unset": 0
},
"started_in_background": 0,
"max_depth": 0,
"spawned_by_subagents": 0,
"completed": 0,
"failed": 0,
"killed": {
"parent": 0,
"user": 0,
"system": 0
},
"refused": {
"depth_limit": 0,
"concurrency_limit": 0,
"budget": 0
},
"by_type": {}
},
"safety_stops": 0,
"is_error": false,
"num_turns": 7,
"subtype": "success",
"api_error_status": null,
"result": "I've refactored `pricing.py`, added the bulk discount and written `test_pricing.py`; all 15 tests pass (`python3 -m unittest -v test_pricing`). pytest isn't installed here, so the tests use the standard-library `unittest`, and pytest will run them too.\n\n**Refactor**\n- The category and tier discounts now live in a data table, `TIER_DISCOUNTS`. Unknown categories fall back to the \"other\" row and unknown tiers get no discount, the same as the old if-chains.\n- `price` is split into small steps: line totals, subtotal, coupon, shipping, then tax. No function nests deeper than 2.\n- The arithmetic happens in the same order as before, so results match exactly, not just to the cent. That includes the quirk where US tax is charged on goods only (`(total - ship) * tax`).\n\n**Bulk rule**\n- Any line with qty \u2265 10 gets `\u00d7 0.95` after the tier discount and before coupons.\n- If the coupon is SAVE20, no line gets the bulk discount.\n- Because it applies before coupons, it can change whether a coupon or shipping threshold is reached. For example, a 52.00 line with qty 10 drops to 49.40, so SAVE10 (which needs 50) no longer applies.\n\n**Tests**\n- **Matches the old version:** I kept an exact copy of the old function in the test file and compared against it on 3,000 random orders, plus every coupon and shipping threshold value combined with each tier, region and coupon. The random orders either have qty \u2264 9 or use SAVE20, where the bulk rule can't fire.\n- **Bulk rule:** the qty-10 boundary, that it applies per line, the order relative to tier and coupon discounts, its effect on shipping thresholds, and that it's skipped with SAVE20 but works with the other coupons.\n- **Structure:** a check that reads the code and fails if any function nests deeper than 3, and a check that the result is a float.\n\nYour note says outputs are compared to the old version on random orders. Any order with a qty \u2265 10 line and no SAVE20 will now price lower by design, so that comparison needs to skip those orders or allow for the new rule.",
"ttft_ms": 3267,
"type": "result",
"duration_ms": 68733,
"uuid": "[REDACTED]",
"ttft_stream_ms": 2204,
"time_to_request_ms": 236,
"first_content_frame_ms": 2204,
"queued_turn_count": 0,
"result_index": 0
}
]