Skip to content

Prompting Long-Horizon Coding Agents

Long-horizon coding agents are useful when the task is larger than one obvious edit.

They can inspect, plan, delegate, implement, verify, and recover from failures across many steps. That changes how you should prompt them. Overly detailed step-by-step prompts can become a constraint. Vague outcome prompts can become a license to wander.

The right balance is: clear outcome, explicit boundaries, enough context, and strong verification.

Use a long-horizon prompt for:

  • root-cause investigations
  • migrations
  • unfamiliar codebase changes
  • multi-file feature work
  • architecture decisions
  • bug fixes that require reproducing behavior first
  • cleanup where correctness matters more than speed

Do not use it for tiny edits, formatting, typo fixes, or work where you already know the exact diff.

Tell the agent what result must be true, not every step it should take.

Goal: users should stay logged in after token refresh without weakening session security.
Investigate the current auth flow, identify the root cause, implement the smallest safe fix, and verify it with the most relevant tests.

This gives the agent room to inspect the real system while keeping the destination clear.

Outcome prompts need boundaries. Without them, a capable agent may refactor, tidy, or “improve” unrelated code.

Boundaries:
- keep the fix scoped to auth/session behavior
- do not redesign the auth module
- do not change public API contracts unless the current contract is the bug
- do not add fallback logic for impossible states
- stop if the fix requires a data migration

Boundaries are not micromanagement. They protect the task from accidental scope growth.

Agents perform better when they understand why the task matters.

Context:
This affects enterprise users who leave the app open all day.
The visible symptom is a surprise logout after refresh.
The fix should prioritize security and predictable behavior over preserving a flawed shortcut.

This helps the agent make tradeoffs when it hits details you did not specify.

For long-running work, define when the agent should pause and when it should proceed.

Proceed without asking for reversible implementation choices that fit the goal.
Pause only for:
- destructive or irreversible actions
- real scope changes
- secrets, credentials, or production data
- decisions that change user-visible behavior beyond the stated goal

This avoids two common failures: stopping too often, or silently crossing a boundary.

Long-running agents can produce confident progress summaries. Require evidence.

When reporting progress, tie each claim to evidence from this session:
- file inspected
- command output
- test result
- screenshot
- log excerpt
- diff
If something is not verified, say so directly.

This is especially important when the agent has been running for a while and the human is catching up late.

Use subagents when parts of the task can be investigated independently.

Good subagent tasks:

  • search the repo for existing patterns
  • inspect official docs
  • review tests and fixtures
  • check UI screenshots
  • compare two implementation options
  • run a focused security review

Poor subagent tasks:

  • vague “think harder” delegation
  • multiple agents editing the same files
  • parallel work with no output contract
  • delegation that hides risk from the main agent
flowchart TD
    A["Main agent<br/>owns goal and final decision"] --> B["Repo pattern check"]
    A --> C["Docs/API check"]
    A --> D["Test/verification check"]
    B --> E["Synthesis"]
    C --> E
    D --> E
    E --> F["Scoped implementation"]

The main agent should keep ownership of the final plan and final diff.

Older prompts often compensate for weaker models with long lists of rules, examples, and step-by-step scripts. For stronger agents, that can backfire.

Keep durable rules:

  • scope boundaries
  • safety constraints
  • output contract
  • verification requirement
  • project conventions

Remove brittle scaffolding:

  • fake examples that narrow the solution too much
  • long instruction lists that repeat the same idea
  • “show your full reasoning” requirements
  • outdated commands
  • rules copied from an older model or tool version without retesting

If default behavior is now better than your old prompt, simplify the prompt.

Goal:
[state the outcome that must be true]
Context:
[why this matters, relevant users, constraints, known symptoms]
Scope:
[what the agent may change]
Boundaries:
[what it must not change, when it must pause]
Process:
1. Inspect before editing.
2. Identify unknowns that could change the approach.
3. Propose the smallest safe plan.
4. Implement only after the plan is grounded in evidence.
5. Verify with focused checks.
6. Return a backbrief with changed files, evidence, assumptions, and remaining risk.
  • Larger agent tasks need outcome clarity more than step-by-step control.
  • Boundaries are how you keep autonomy from becoming scope creep.
  • Progress claims should be tied to files, commands, tests, screenshots, or logs.
  • Use subagents for independent investigation, not uncontrolled parallel editing.
  • Simplify prompts when old scaffolding starts constraining better agents.