Skip to content
mentoor

Topic 2 of 5 · 4 min read

Setting up a first terminal agent session

Goal: Set up a terminal agent in a repository and run a first small task that finishes with a passing test or build.

A good first session is a clean repo, a short memory file that names your test command, and one small task that ends in a check the agent can run itself.

Check yourself · 1 of 3

Why should you start a first agent session on a clean branch?

Choose one answer

Why it matters

Most bad first experiences come from the setup, not the tool. The agent starts in the wrong folder, does not know how to run the tests, or gets a task so big that nobody can review the result. A careful first run teaches you how the tool behaves while the cost of a mistake is small.

How to do it

  1. Install and sign in. Follow the official instructions for your tool (Claude Code, Codex CLI, Gemini CLI or Aider). Sign in with an account or an API key. Keep keys in environment variables or the tool's own login, never in the repo.
  2. Start with a clean git state. Run git status. Commit or stash your own work, and create a branch for the agent. Every change is then one git diff away and one git restore from gone.
  3. Start the agent at the repo root. The folder you start in is the agent's working area and often its default scope.
  4. Write a memory file. Most tools read a plain markdown file at session start: CLAUDE.md for Claude Code, AGENTS.md for Codex and others, GEMINI.md for Gemini CLI. Keep it short: how to install, build, test and lint, where code lives, and rules such as "never edit generated files".
  5. Hand over one small task with a check. One bug, one function, one failing test. Name the command that proves it works.

A starter memory file

# Project notes
- Install: `npm ci`
- Test one file: `npx vitest run src/date.test.ts`
- Lint: `npm run lint`
- Source is in `src/`; never edit `dist/`.
- Do not change tests to make them pass; say so if a test looks wrong.

Before and after

Before: "Improve the date handling in this project."

There is no scope, no check and no way to review it. The agent will touch many files.

After: "parseDate('') returns today's date. Make it throw InvalidDateError, add a test in src/date.test.ts, and run npx vitest run src/date.test.ts until it passes. Change nothing else."

What goes wrong

  • Dirty working tree. Your edits and the agent's are mixed, and you cannot tell them apart.
  • No test command. The agent guesses one, or skips verification and says it is done.
  • A memory file that grows into a manual. Long files are read less reliably. Keep only what the agent cannot discover alone.
  • A first task that is a refactor of the whole app. Start small enough to read the full diff in a few minutes.

Examples

A first-run plan

1. git switch -c agent/parsedate-empty
2. Start the agent at the repo root
3. Check that CLAUDE.md lists the test command
4. Task: make parseDate('') throw, add a test
5. Review git diff; run the full test suite yourself

The agent does step 4. You do the rest.

Memory file that backfires

A 400-line memory file copied from the team wiki lists every folder and style rule. The agent starts ignoring parts of it. Trim it to the commands and rules it cannot find by reading the code.

Key points

  • Start from a clean git state on a new branch so every agent change is visible and reversible.
  • Launch the agent at the repository root, which defines its working area.
  • A short memory file with the install, test and lint commands saves the agent from guessing.
  • Give the first task a small scope and a command that proves it worked.
  • Keep secrets out of the repo and the memory file; use environment variables or the tool's login.

Common mistakes

  • Starting with uncommitted work in the tree, so agent changes and your own are tangled.
  • Giving a broad first task such as "clean up the codebase".
  • Not telling the agent how to run the tests and then trusting a claim that they pass.
  • Pasting API keys into the memory file or the prompt.

Check yourself · 2 of 3

What belongs in a short project memory file such as CLAUDE.md or AGENTS.md?

Choose one answer

Check yourself · 3 of 3

Which first task is best for learning how a terminal agent behaves?

Choose one answer

Practice items, not counted towards your mastery.

Start here

More for this topic