Sub topic 5
Working in an interactive session
This chapter assumes you can run the install commands from the earlier chapters, that you have signed in to at least one tool, and that you know basic git (commit, branch, diff). It covers the day-to-day mechanics of an interactive session: starting one, giving the agent input, steering it while it works, and ending or resuming it.
What an interactive session is
An interactive session is a long-running terminal program that holds a conversation with the model. You type a prompt, the agent runs its loop (model call, tool call, observation), and it returns control to you when it has an answer or needs approval. Everything in the session shares one history, so a later prompt can refer to "that function" or "the failing test" without repeating details.
The session is tied to the directory you started it in. The agent treats that directory as the project root. It reads files there, runs commands there, and loads the project's instruction file from there.
Starting a session
Start from the root of the repository, not from a parent folder or your home directory. Starting too high gives the agent access to unrelated files. It also makes searches slower and noisier.
cd my-project
claude # empty session
claude "Where is date parsing implemented?" # session with a first prompt
codex # empty session
codex "Where is date parsing implemented?" # session with a first prompt
copilot # empty sessionPassing a quoted prompt as an argument starts the interactive session and submits that prompt immediately. This differs from the non-interactive flags (-p, exec), which print one answer and exit. Those are covered in a later chapter.
The shape of a turn
Each prompt you submit starts a turn. During a turn the agent may call several tools before it stops.
Two points follow from this shape:
- Approval is part of the turn. The agent pauses at the approval step until you answer. How often it pauses depends on the permission or approval mode, which a later chapter covers.
- The turn is not over until the final answer. An agent that appears to be idle may be waiting on a long command or on you.
Giving the agent input
You are not limited to plain sentences. Common input features are similar across the three tools, though the exact keys can differ by version. Check each tool's help or its /help command to confirm.
| Input | Typical use | Notes |
|---|---|---|
| Plain text | Describe the task | Multi-line input is supported, usually with a modified Enter key or a paste |
| `@path/to/file` | Point at a specific file | Narrows the agent's search and loads that file into context |
| `!command` | Run a shell command yourself | Supported in Claude Code. Check whether your tool and version support it |
| `/command` | Control the session | Covered in the slash commands chapter |
| Pasted text or an error log | Provide evidence | Paste the actual error, not a paraphrase |
Referencing files with @ is the most useful habit. Compare these two prompts:
- Vague: "Fix the date bug."
- Specific: "In
@src/dates/parse.ts,parseWeekDate('2026-W01-1')returns the wrong day. Fix it and add a test in@test/dates.test.ts."
The second prompt names the files, gives a failing input, and states the expected change. The agent needs fewer search steps, and you can judge the result more easily.
Steering while the agent works
You can interrupt a running turn. Pressing Esc stops the current action in all three tools. Ctrl+C also interrupts, but pressing it at an empty prompt, or twice, can exit the program. After an interruption the session history is kept, so you can redirect the agent with a new message such as "Stop. Don't change the public API. Use a helper function instead."
Interrupt early in these cases:
- The agent edits files you did not mention.
- It starts a large refactor when you asked for a small fix.
- It repeats the same failing command more than twice.
- It reads very large directories such as
node_modules/or build output.
Waiting for a bad turn to finish costs time and fills the context window with noise. A quick interruption and a correction is cheaper.
Reading what the agent shows you
At each approval prompt, read what is about to happen. For file edits you see a diff. For shell commands you see the exact command line. Check three things:
- Does the command touch only the project? Watch for absolute paths,
rm,curl ... | sh, and anything that writes outside the repository. - Does the edit match the request? Extra changes in unrelated files are a warning sign.
- Is the agent running something you did not expect, such as a package install or a network call?
Ending, resuming, and starting fresh
Exit with /exit or Ctrl+D at an empty prompt, or use the quit command your tool documents. Each tool stores session history, and each can reopen it:
claude --continue # most recent conversation in this directory
claude --resume # pick from a list
codex resume # pick a previous session
copilot --continue # most recent sessionResume when you are continuing the same task. Start a fresh session when the task changes, because old history takes up context and can mislead the agent. The context chapter covers this trade-off in more detail.
Common mistakes
- Starting in the wrong directory. The agent edits the wrong project or cannot find your instruction file. Check
pwdfirst. - Stacking unrelated tasks in one session. The history grows, and earlier instructions get mixed with later ones.
- Accepting a large turn at once. Break a big request into steps. Review the diff after each.
- Assuming the agent remembers across sessions. It does not, apart from resumed history and the instruction file. Put lasting rules in
CLAUDE.mdorAGENTS.md. - Pasting secrets into the prompt. Prompt text is sent to the model provider.
Exercise
You start claude from your home directory and ask it to fix a failing test in ~/work/shop. Give two problems this can cause and the fix.
Show answer
The agent has access to far more files than the task needs, and it will not load the CLAUDE.md from ~/work/shop, so it misses the project's test command and conventions. Searches are also slower and noisier. The fix is to cd ~/work/shop and start the session from the repository root.
Exercise
The agent begins editing files in src/billing/ while you asked only for a change in src/dates/. What do you do, and what do you type next?
Show answer
Press Esc to interrupt the turn right away, then review the diff (or run git diff) and revert any unwanted edits. Send a correcting message, for example: "Only change files under src/dates/. Revert your edits in src/billing/." Starting from a clean git branch makes the revert simple.