11 May 2026

دليل · Guide10 min read

١٠ نصائح للبرومبت تبقي وكلاء Claude مركزين ومنجزين للمهام10 Prompting Tips to Keep Claude Agents Focused and On Task

Ten tested techniques for writing Claude agent prompts that stay on task: a bounded scope, exit conditions, named tools and an escalation rule. You finish with a production ready agent template.

Who this guide is for

Builders running agents on Claude Code or Claude who want them to finish the job and stop

Key terms

Agent
Claude working on its own: reading, acting and calling tools to finish a task over several steps.
Agent drift
When an agent calls tools you never asked for, expands the task on its own, or returns results that miss the point.
Exit condition
A clear criterion that tells the agent the task is done and it must stop.
Escalation
The agent stops and reports an unexpected situation instead of improvising a fix.

The steps

  1. Step 1

    Understand why agents drift

    An agent does not understand intent. It follows instructions. The vaguer the instructions, the more it fills the gaps in ways you did not expect.

    Three causes sit behind most drift: no precise definition of the task, no clear exit condition, and leaving the decision to expand scope to the agent itself.

    The fix is not a longer prompt. It is a more precise one, built on three elements: scope, exit conditions and escalation rules. The next steps cover all ten techniques in order.

    PromptBefore and after: a scope bounded agent
    BEFORE (drifts easily)
    You are a helpful agent. Review the codebase and fix any issues you find.
    
    AFTER (focused and bounded)
    You are a code review agent. Your single mission: fix broken import statements in the /src directory only.
    
    SCOPE
    Read files inside /src only. No other directories.
    Fix only import statements that cause a ModuleNotFoundError.
    Do not refactor, rename, reformat or reorganize any code.
    Do not create new files.
    Do not touch files outside /src under any circumstances.
    
    ALLOWED TOOLS: Read, Edit. No other tools.
    MAXIMUM TOOL CALLS: 30 total.
    
    EXIT CONDITIONS: stop when ANY of these is true
    1. All broken imports in /src are fixed
    2. You have made 30 tool calls
    3. You encounter a situation not covered by these instructions
    
    SELF CHECK (before writing your final response)
    1. Did I modify anything outside /src? If yes, revert it before finishing.
    2. Did I change anything other than import statements? If yes, revert it.
    3. Did I exceed 30 tool calls? If yes, report that the limit was reached.
    
    FINAL OUTPUT FORMAT
    Files changed: [list each file]
    Imports fixed: [describe each fix]
    Status: COMPLETE | STOPPED AT LIMIT | ESCALATED
  2. Step 2

    Bound the mission and scope (tips 1 to 3)

    Tip 1: open every agent prompt with a single mission sentence that leaves no room for interpretation.

    Tip 2: state explicitly what the agent must not do. "Do not edit files outside src" is stronger than any positive instruction because it draws a line the agent will not cross.

    Tip 3: bind the scope to measurable parameters, such as a file count, a step count or a time limit.

    PromptMission and scope block
    You are a [TASK_TYPE] agent. Your single mission: [ONE SENTENCE].
    Operate only within [DIRECTORY OR SOURCE].
    You must not: [PROHIBITED ACTION 1], [PROHIBITED ACTION 2].
    Stop after [NUMBER OF FILES OR STEPS].
  3. Step 3

    Test on a small task and watch

    Before you give the agent a big job, test the prompt on a small one and watch exactly what it does.

    The commands below run in the terminal with Claude Code. The first runs a bounded task with verbose output so you can inspect tool calls, then uses git to confirm the agent touched nothing it should not have.

    The second pipes in a task with an explicit stop condition, then verifies the agent's claim with an independent command.

    PromptTest commands
    claude --print --verbose 'Summarize the 3 most recent git commits. Do not read any files. Do not run any commands other than git log. Stop after exactly 3 commits.'
    
    git diff --name-only HEAD
    
    echo 'List the 5 largest files in the current directory by size. Do not open or read any file. Stop after listing exactly 5. Final line must be: DONE, listed 5 files only.' | claude --print
    
    ls -lhS | head -6

    Tip: Never trust an agent's report about itself. Verify it with an independent command.

  4. Step 4

    Design exit conditions and self checks (tips 4 to 6)

    Tip 4: tell the agent when to stop, not only what to do. "Stop after creating the first successful file" keeps it from running on with no end.

    Tip 5: ask for one self check step before finishing. A line like "Before answering, check: did I do only the original task?" reduces drift.

    Tip 6: require a full list of everything it did as the mandatory last step. It forces the agent to consider its impact before it finishes.

    PromptExit and self check block
    Stop and write your final report when ANY of these is true:
    1. You have completed [MEASURABLE COMPLETION CRITERIA]
    2. You have reached [NUMBER] tool calls
    3. You encounter a situation these instructions do not cover
    
    Before your final response, check: did I do only the original task? Did I stay inside the scope?
    
    Mandatory last step: list every action you took and every file you touched.
  5. Step 5

    Name the tools and cap the calls (tips 7 and 8)

    Tip 7: name the allowed tools explicitly instead of leaving the judgment to the agent. "Use only the Read and Bash tools" is far clearer than "use the appropriate tools". An agent that does not know its limits expands step by step.

    Tip 8: set a hard maximum on total tool calls. It stops the agent from looping on the same tool with no real progress.

    In Claude Code you can enforce the allowlist from the terminal with allowedTools, as in the command below. After the run, session logs live under ~/.claude/projects if you want to review the tool calls.

    PromptRun with a restricted tool allowlist
    claude --allowedTools 'Read,Bash' --print 'Count the total number of TODO comments across all .py files in /src. Use Read to open files. Use Bash only for counting. Stop after scanning 15 files. Report the total count and the list of files scanned.'
  6. Step 6

    Add escalation and a decision log (tips 9 and 10)

    Tip 9: add the golden escalation sentence to every serious agent prompt: "If you encounter a situation these instructions do not cover, stop and report it instead of trying to resolve it." This one line prevents the big mistakes that happen when an agent improvises a fix you never asked for.

    Tip 10: require a decision log. Every significant action is written down with its reason. It improves accuracy and makes review easier, because an agent that explains its decisions keeps steering back to the original goal.

    PromptEscalation and log block
    If you encounter a situation these instructions do not cover, output this line exactly and then stop:
    ESCALATION: [the situation in one sentence]
    Do not attempt to resolve it.
    
    Before every action, write one line:
    ACTION: [what you are about to do] | REASON: [why this serves the mission]
  7. Step 7

    Combine all ten into one prompt and check it

    Now combine everything into one production ready template. Replace the bracketed parts with your values.

    Before launch, run the prompt through this checklist: does it have exactly one clear mission sentence? Did you list what the agent must not do? Is there a measurable exit condition? Did you name the allowed tools and cap the call count? Did you include the escalation trigger? Did you test it on a small task before scaling up?

    A well prompted agent does not need constant supervision. It needs a tight prompt from the start.

    PromptFull agent template
    You are a [TASK_TYPE] agent.
    MISSION (one sentence): [YOUR SINGLE SENTENCE TASK]
    
    SCOPE
    Operate only within: [DIRECTORY, DOMAIN OR DATA SOURCE]
    You MUST NOT:
    [PROHIBITED ACTION 1]
    [PROHIBITED ACTION 2]
    Act outside the defined scope under any circumstances.
    Allowed tools: [TOOL_1], [TOOL_2]. No other tools.
    Maximum tool calls: [NUMBER] total across the entire session.
    
    EXIT CONDITIONS
    Stop and write your final report immediately when ANY of these is true:
    1. You have completed [SPECIFIC MEASURABLE COMPLETION CRITERIA]
    2. You have reached [NUMBER] total tool calls
    3. You encounter a situation not covered by these instructions
    
    ESCALATION TRIGGER
    If condition 3 is reached, output this line exactly:
    ESCALATION: [the unexpected situation in one sentence]
    Then stop. Do not attempt to resolve the unexpected situation.
    
    SELF CHECK (before every response you write)
    1. Am I still working on the original mission? If no, stop now.
    2. Have I exceeded my tool call limit? If yes, stop and write the final report.
    3. Am I about to act outside my defined scope? If yes, stop.
    
    DECISION LOG
    For every action you take, write one line before taking it:
    ACTION: [what you are about to do] | REASON: [why this serves the mission]
    
    FINAL OUTPUT FORMAT
    Decision log:
    [all ACTION lines]
    Result:
    [your deliverable]
    Status: COMPLETE | STOPPED AT LIMIT | ESCALATED

    Tip: The minutes you put into the prompt save hours of debugging later.

The takeaway

One mission, explicit limits, an exit condition and escalation. Use them in your next agent and it will do exactly what you asked, then stop.

Most value

Start building with me now

We sit together, break down your problem, and I build the AI solution with you step by step

60minutes
  • A private session with you
  • Real building during the session
  • Results you take with you when we finish
Book a build session

100% free

A free consultation about your problem

Start

The full path · Monthly subscription

Full access to every guide (29) for 249 AED/month