Does Task Framing Change How Claude Code Works? A Preliminary Study
Does Task Framing Change How Claude Code Works? A Preliminary Study
A common Claude Code failure looks deceptively simple: the agent opens three files, changes the wrong abstraction, runs the existing test suite, and reports success—while the requested behavior remains untested.
The code was not necessarily difficult. The task was framed poorly.
In practice, I have seen the same repository produce materially different outcomes depending on whether a request was framed as an outcome, a list of constraints, or a warning about what not to do. The underlying model does not change. What changes is the objective Claude optimizes for on every turn of its agent loop.
This is a preliminary practical study, not a model benchmark. I use the term “preliminary” deliberately: execution environment, repository state, tool permissions, and nondeterministic tool results all affect a coding-agent run. The useful question is not whether one prompt is universally best. It is whether task framing produces repeatable behavioral shifts developers can predict and exploit.
What “Task Framing” Means Here
Task framing is the structure and language used to define work for an AI coding agent.
Consider these three descriptions of the same task:
Outcome-first
Add a per-user rate limiter to the order endpoint. Return HTTP 429 when the limit is exceeded and include
Retry-Afterin the response.
Constraint-first
Modify only the order creation path. Do not change authentication, persistence models, or public response schemas. Add tests for requests under and over the limit.
Prohibition-heavy
Avoid breaking authentication. Never modify the database schema. Be careful not to introduce race conditions or inconsistent behavior.
All three mention the same feature. They create different search spaces for the agent:
- The outcome-first version emphasizes completion criteria.
- The constraint-first version narrows the allowed solution space.
- The prohibition-heavy version makes uncertainty and failure more salient.
Claude Code does not receive a task as passive prose. It interprets the request through its system instructions, repository context, conversation history, available tools, and tool results. Framing influences which files it reads, which abstractions it considers, whether it asks a question, and how it decides that the task is complete.
A Small, Reproducible Evaluation Setup
For a meaningful preliminary comparison, use a tiny isolated problem rather than an entire feature request.
Suppose a Python service needs a rate limiter with this contract:
from collections import defaultdict, deque
from time import monotonic
class RateLimiter:
def __init__(self, limit: int, window_seconds: float):
self.limit = limit
self.window_seconds = window_seconds
self._requests = defaultdict(deque)
def allow(self, user_id: str) -> bool:
now = monotonic()
requests = self._requests[user_id]
while requests and requests[0] <= now - self.window_seconds:
requests.popleft()
if len(requests) >= self.limit:
return False
requests.append(now)
return True
The acceptance test could be:
def test_rate_limiter_rejects_requests_over_limit():
limiter = RateLimiter(limit=2, window_seconds=60)
assert limiter.allow("user-1") is True
assert limiter.allow("user-1") is True
assert limiter.allow("user-1") is False
def test_rate_limiter_is_per_user():
limiter = RateLimiter(limit=1, window_seconds=60)
assert limiter.allow("user-1") is True
assert limiter.allow("user-2") is True
A reasonable evaluation rubric includes:
- Whether the agent creates a test before or alongside implementation.
- Whether it changes files outside the requested path.
- Whether it adds unrelated abstractions.
- Whether it explicitly verifies the boundary condition.
- Number of tool calls and elapsed time.
- Whether it reports unsupported assumptions as facts.
For each prompt variant, begin from a clean checkout and a fresh Claude Code session. Otherwise, conversational history becomes a confounding variable: the second framing may perform better simply because the first run already revealed the relevant file.
What Tended to Change Across Framings
| Framing style | Agent behavior | Main benefit | Main risk |
|---|---|---|---|
| Outcome-first | Moves directly toward observable behavior | Clear completion criteria | May ignore architectural constraints |
| Constraint-first | Investigates repository conventions before editing | Fewer out-of-scope changes | Can become overcautious |
| Steps-first | Executes an explicit sequence | Predictable and auditable | May blindly follow an invalid plan |
| Prohibition-heavy | Spends more effort checking what could go wrong | Useful for risky operations | Can delay progress or refuse useful work |
| Test-driven | Establishes a failing test first | Stronger verification | Test design can become a distraction |
| Repository-first | Locates patterns and adjacent implementations | Better local consistency | More exploration and token usage |
The most effective version in my preliminary work was usually a hybrid: one outcome, a small number of hard boundaries, and executable acceptance criteria.
A better prompt for the rate-limiter task would be:
Implement the existing
RateLimitercontract inratelimit.py. It must allow up to 60 requests per user per rolling 60-second window and reject further requests. Add focused tests covering independent users, the request limit, and expiry of old requests. Do not modify the service API or persistence layer. Run the focused tests and report any assumptions about time handling.
This framing gives Claude four things:
- A concrete behavioral target.
- A file-level scope boundary.
- Verifiable examples.
- A completion instruction.
The “do not modify” sentence is useful because it names adjacent areas likely to be touched accidentally. It is not useful when it expands into a long catalog of everything the agent should fear.
A Common Gotcha: Negative Instructions Can Become Salient Goals
Negative framing is not inherently weaker. For destructive commands or security-sensitive changes, explicit boundaries are essential:
Do not access production credentials. Do not run database migrations. Work only in the staging fixture directory.
That is clearer than:
Be safe with data and careful around production systems.
However, stacking prohibitions can distort the agent’s search behavior. A prompt such as “never introduce a race condition” does not tell Claude how to design the implementation. It may prompt repeated inspection, an unnecessary rewrite, or a refusal to proceed without further information.
A better conversion is:
Protect the shared counter with a lock so concurrent requests cannot exceed the configured limit. Add a concurrency test if the project already has a pattern for them.
This replaces a vague fear with an implementable engineering requirement.
The same principle applies to scope:
- Instead of “don’t change unrelated code,” say “modify only
ratelimit.pyand its test file.” - Instead of “make the API robust,” say “return HTTP 429 with a numeric
Retry-Afterheader.” - Instead of “don’t break compatibility,” specify the preserved function signature or response shape.
Specificity is more useful than severity.
The Difference Between Framing and Tool Design
Prompt framing cannot overcome a poor agent environment.
In practice, a beautifully framed request still performs poorly when:
- The repository contains no tests or no obvious test command.
- Tool permissions block a required read.
- The task depends on information absent from the repository.
- The acceptance criteria are contradictory.
- The model is asked to make a product decision disguised as an implementation taskClaude Code’s behavior is therefore a product of two systems:
task framing
+ repository state
+ tool permissions
+ model capability
+ tool feedback
= observed coding behavior
This distinction matters when moving from Claude Code to direct API useClaude Code provides a scaffold: it reads files, executes commands, observes errors, and continues from that feedback. A raw API request does not automatically reproduce that loop.
When translating a successful Claude Code interaction into an API workflow, preserve the task contract rather than copying conversational wording:
{
"task": "Implement a rolling per-user rate limiter",
"target_files": [
"ratelimit.py",
"tests/test_ratelimit.py"
],
"constraints": [
"Preserve the public function signature",
"Do not modify persistence or authentication code"
],
"acceptance_tests": [
"Different users have independent limits",
"Requests over the limit are rejected",
"Requests outside the window are accepted"
],
"required_verification": [
"Run the focused test file",
"Report unresolved assumptions"
]
}
For Claude’s Messages API, place stable task rules in the system prompt and the mutable repository state in the user message or tool results. GPT and Gemini APIs have different schemas and tool-calling conventions, but the principle is portable: encode the outcome, boundaries, evidence, and completion criteria.
Cost Changes When Framing Changes the Work
Prompt wording affects cost indirectly by changing tool use.
A vague task may trigger broad repository exploration. An outcome-first prompt with exact file targets may reduce search. A prohibition-heavy prompt may create extra loops of inspection and verification.
If one run sends approximately 1,600 input tokens and 3,200 output tokens across multiple turns, a simple cost calculation is:
cost = (input_tokens / 1,000,000) × input_rate
+ (output_tokens / 1,000,000) × output_rate
The important detail is that tool calls add more context on the next turn. A repository scan that adds 20,000 tokens may affect both cost and behavior more than the initial wording.
I therefore evaluate prompts on total successful work, not prompt elegance:
time claude
pytest -q tests/test_ratelimit.py
If you are running the same evaluation across Claude, GPT, and Gemini, multi-model API access can make the comparison practical. AI Prime Tech is one option for cheaper Claude/GPT/Gemini API access, particularly when a test matrix multiplies requests. The current model rate still matters, so calculate from the provider’s present pricing rather than assuming every model has the same economics.
Better Task Contracts for Real Development
For routine work, I use this structure:
1. State the observable outcome
Add idempotency handling to
create_orderso replaying the same request returns the original order instead of creating a duplicate.
2. Name the permitted change surface
Modify the order service and its tests. Do not alter the database schema.
3. Define edge cases as examples
Include concurrent requests with the same idempotency key and requests that reuse a key with a different payload.
4. Require evidence
Run the focused test suite and summarize any assumption that cannot be verified locally.
5. Separate required behavior from optional ideas
Keep the change small. Do not introduce a new framework or redesign the order module.
This format works well in Claude Code, but it also maps cleanly to API tool policiesClaude, GPT, and Gemini differ in how they plan, call tools, and respond to system instructions. They do not need identical prompting styles. They do need equally explicit success criteria.
Practical Takeaways
- Task framing changes agent behavior, not just prompt length. Outcomes influence what gets built; constraints influence where the agent looks and edits.
- Combine one outcome with a few hard boundaries. A positive description of desired behavior is usually more actionable than a long list of fears.
- Make acceptance criteria executable. Tests, command output, and concrete examples give the agent better completion signals than adjectives such as “robust” or “safe.”
- Use fresh sessions for comparisons. Otherwise, repository exploration and chat history contaminate the result.
- Measure successful work, not token count alone. Include tool calls, scope creep, verification quality, and unresolved assumptions.
- Preserve the contract when moving to APIs. Outcome, scope, edge cases, and required evidence travel better than Claude Code-specific conversational phrasing.
- Treat these findings as preliminary. Prompt effects interact with model version, repository layout, tool permissions, and execution feedback. The durable technique is not one magic template; it is providing an agent with a task it can verify.
One API key for Claude Opus 4.8, Sonnet 4.6, Haiku 4.5, Fable 5, plus GPT & Gemini — up to 80% off official pricing, pay-as-you-go.
Get Your API Key →