Skip to content

The AI primer, technical edition

← Back to the start

This is the friendly primer rewritten for people who live in a terminal: system administrators, software developers and machine learning engineers. The habits are the same. Here they're about repos, rules files, permission configs, dry runs, CI and evals instead of notes and folders.

It's written for coding agents, the kind that read your files, run commands and make changes, because that's where the habits matter most. We use Claude Code, so most examples use it, and the rules files section shows the equivalent files for Codex CLI, GitHub Copilot and Cursor. The ideas carry over to any tool.

Tool facts were checked against each tool's own documentation on 28 November 2026, with Claude Code 2.1.332. These tools change every few weeks, so check your version's docs before you rely on a detail. Anything we couldn't confirm says so.

At work: use only the AI tools, models and plans your employer has approved, for the kinds of data they're approved for. Every work example here assumes that. Keep secrets, customer data, personal data and production logs out of any tool that isn't approved for them, and use stand-ins like service-a or customer-x when you need an example.

Alongside this page:

Page What's in it
GUARDRAILS.md Permission rules, modes, the sandbox, hooks, secrets, MCP servers and prompt injection
WORKFLOWS.md Explore, plan, build, verify; context, worktrees, subagents, headless runs, dry-run scripts
VERIFYING.md Tests first, reviewing agent diffs, checking claims, and a small eval harness
EXAMPLES.md Fifteen worked examples: five each for sysadmins, developers and ML engineers
RULES-FILES.md Sample rules files for an infra repo, a service, an ML repo, a data pipeline and you
CHEATSHEET.md The whole thing on one page
templates/ A rules file, plan, runbook, eval, handoff note and decision record to copy

Contents: the mental model · ten practices · your first week · prompts to copy · where to go next

The mental model

Six facts explain nearly every good habit and every bad surprise.

  1. The model remembers nothing between sessions. Each session starts with what's in its context window: the tool's own instructions, your rules files, the conversation and whatever it has read so far. If something isn't in the repo or the prompt, it doesn't exist for the agent.
  2. The context window is finite, and noise costs you. A 4,000-line log or three whole files you didn't need push out what matters and make answers worse. Give it paths and the relevant lines, not everything.
  3. An agent is a loop. The model proposes a tool call, the harness checks it against your permissions, the tool runs, the result goes back into the context, and round it goes. The model never runs anything itself. The harness does.
  4. So safety lives in the harness, not the prompt. A rules file that says "never push to main" shapes what it tries. A deny rule in the settings file stops the usual ways of doing it, and a sandbox or a container stops the rest. Write the wish in the rules file and the wall in the config.
  5. Everything it reads is input, not instruction. A web page, an issue comment, a log line, a dependency's README or an MCP server's reply can contain text written to steer it. That's prompt injection, and it's why the agent's reach matters as much as its prompt.
  6. It's fluent and confident whether it's right or not. "All tests pass" is a claim. The test output is evidence. Verifying is your job and your pipeline's job.

Ten practices

1. The repo is the memory

Everything the agent should know lives in files it can read: a README that says what the thing is and how to run it, decision records for why it's built this way, a runbook for how to operate it, and a plan file for the work in progress. Each session starts by reading them instead of you explaining again.

  • One repo, or one clearly bounded folder, per system or project.
  • Write things down in the repo the first time you explain them. If you said it twice in chat, it belongs in a file.
  • Keep the in-progress plan in PLAN.md and the "where we left off" note in HANDOFF.md. Templates for both.

2. A rules file per repo, and one for you

A rules file is a Markdown file the tool loads at the start of every session. It's where the build and test commands, the conventions and the "don't touch" list live.

Tool Repo rules file Your personal file Notes
Claude Code CLAUDE.md or .claude/CLAUDE.md; CLAUDE.local.md for your own untracked notes ~/.claude/CLAUDE.md Reads AGENTS.md when there's no CLAUDE.md (2.1.277 and later). @path imports other files. .claude/rules/*.md can apply to some paths only
Codex CLI AGENTS.md, plus AGENTS.override.md ~/.codex/AGENTS.md Files nearer the working folder win. Combined size is capped at 32 KiB by default
GitHub Copilot .github/copilot-instructions.md, and .github/instructions/*.instructions.md with applyTo globs See its docs Its agents also read AGENTS.md; support varies by surface
Cursor .cursor/rules/*.mdc See its docs Also reads AGENTS.md. .cursorrules is the old format

If your team uses more than one tool, put the shared rules in AGENTS.md and make CLAUDE.md one line, @AGENTS.md, plus anything only Claude needs. Claude Code reads only CLAUDE.md when both exist, so the import is what keeps them in step.

What makes a good one:

  • Commands, exactly. make test, uv run pytest -x tests/unit, terraform -chdir=envs/dev plan. The agent will use whatever you write here.
  • Facts it can't guess: the odd directory layout, the generated files not to edit, the flaky test everyone knows about, the reason for the strange pin in requirements.txt.
  • Short. Under 200 lines. It's read every session and competes for space with the actual work. Link to longer docs instead of pasting them.
  • Not a security control. Anything that must never happen goes in the permission config too.

/init in Claude Code writes a starter from the repo. Trim it hard: it tends to describe what the agent could have found by reading. RULES-FILES.md has five complete examples.

3. Permissions in config, not prose

Sort every action into three tiers and write them down where the harness enforces them:

Tier Examples In Claude Code
Go ahead Read files, run tests and linters, git diff, git commit on a branch allow rules
Ask me first git push, installing packages, network fetches, anything that touches shared state ask rules
Never Force pushes, terraform apply, kubectl delete against prod, reading .env deny rules, plus a hook or the sandbox where it has to hold

Claude Code checks deny rules first, then ask, then allow, and a deny at any level beats an allow at any other. Your organization's managed settings sit above everything, including command-line flags. GUARDRAILS.md has a complete settings file, the matching rules that catch people out, and when you need a hook or a container instead.

4. Small diffs on branches

Version control is the undo button, so the agent works on a branch, in small commits you can read in a few minutes each, and you review the diff before anything merges.

  • Ask for a plan in phases first, each with a check (a command that proves it worked). Then one phase at a time.
  • One concern per commit. A refactor and a behavior change in the same diff is how bugs hide.
  • Parallel work goes in separate worktrees, not separate sessions fighting over one checkout.
  • Never force-push and never rewrite shared history. Put that in deny rules too.

5. Dry run first, and a person runs the first real one

Anything that changes the world gets a mode that shows what it would do, and the first real run is yours, not the agent's.

Tool The preview
Your own scripts --dry-run (skeletons in WORKFLOWS.md)
Terraform / OpenTofu plan, saved with -out so apply runs exactly that plan
Kubernetes kubectl diff -f, or kubectl apply --dry-run=server
Helm helm upgrade --install --dry-run, or helm template and a diff
Ansible --check --diff
PowerShell -WhatIf on cmdlets and on your own functions
Databases Run the migration against a copy, or inside a transaction you roll back

The agent can write the change and run the preview. You read the preview, and you run the apply.

6. Leave a handoff note

Long tasks outlive a session, and a fresh session with a good note beats a stale one with a full context. Before you stop, ask for HANDOFF.md: what's done, what's half-done, what was tried and ruled out, the exact next command. The next session starts with "read HANDOFF.md and PLAN.md, then continue." Claude Code can also pick up a session with claude --continue or claude --resume, but the file survives machines, tools and teammates.

7. Keep secrets out of reach

The agent can't leak what it can't read.

  • Deny reads of .env, key files and secrets folders in the permission config.
  • Keep real values in environment variables or a secret manager, and commit config.example.* files with placeholders.
  • Give the agent its own credentials with the least access the task needs: a read-only cloud role for exploring, a token scoped to one repo, never your admin login or a production kubeconfig.
  • Scan before every commit. The first primer has a pre-commit hook that catches the common shapes.
  • Never paste a token into a chat to "just test something". If one leaks into a session or a commit, rotate it. Deleting the message doesn't undo it.

8. Treat tools and inputs as untrusted

Every MCP server, plugin and fetched page is code or text from someone else running inside your agent's loop.

  • Add MCP servers you'd be happy to run as a dependency, give them their own least-privilege tokens, and prefer read-only.
  • Be most careful when one session has all three of: private data, untrusted input (web, issues, email), and a way to send data out (network, pushes, messages). Remove one of the three.
  • Pin versions of servers and plugins like any other dependency.
  • Prune them every month or two, starting with the ones that can send, spend or deploy.

More in GUARDRAILS.md.

9. Verify like you mean it

  • Have the agent run the tests, linters and type checks itself, and show you the output, not a summary of it.
  • Ask for evidence: file paths and line numbers for claims about the code, the exact command that reproduces a bug, the log lines a conclusion rests on.
  • Read test changes separately. "Fixed the failing test" sometimes means "loosened the assertion".
  • Run the same checks in CI on every pull request, so they don't depend on anyone remembering, and make green part of done.
  • For prompts and agent workflows you rely on, keep a small eval set and run it before and after changes. VERIFYING.md has a harness in under 200 lines of Python.

10. Delegate on purpose

Once the basics hold, hand off more, each piece with its own limits:

  • Subagents for searching, reviewing or summarizing in their own context, so the main session stays clean.
  • Worktrees for two or three tasks at once.
  • Headless runs (claude -p) for scripts, CI steps and scheduled jobs, with a tool allowlist and a spending cap.

The rule that makes this safe: the less you'll watch it, the less it may do. A nightly job gets read-only tools and writes a report. It doesn't open pull requests until it's earned it. Details in WORKFLOWS.md.

Your first week

One repo you know well, one small step a day:

  1. Day 1: run /init (or write AGENTS.md by hand), then cut it to the commands, the layout and the gotchas. Check: a new teammate could build and test from it.
  2. Day 2: add .claude/settings.json with allow, ask and deny rules from the starter in GUARDRAILS.md. Check: ask for a force push and watch it get refused.
  3. Day 3: a small real task on a branch, start to finish: plan, one phase, tests, your review of the diff. Check: you'd have merged it from a colleague.
  4. Day 4: add the secret scan and one hook for something that matters in your world. Check: the test cases in that section pass.
  5. Day 5: write five eval cases for a prompt you use every week and run them with the harness. Check: you know your pass rate.
  6. Later: a subagent for reviews, a worktree for a second task, then one headless job with read-only tools.

Prompts to copy

Replace the parts in angle brackets.

Explore before you touch anything

Read <paths>. Don't change anything. Explain how <a request / a job / a deploy> flows through this code, citing file:line for each step. Then list what you're unsure about and what you'd read next to find out.

Plan in phases

I want to <goal>. Write PLAN.md: phases small enough to review in ten minutes each, each with the exact command that proves it worked and how to roll it back. List the risks and the questions you need me to answer. Don't write code yet.

One phase at a time

Do phase <n> of PLAN.md only. Run <test command> and show me the last 30 lines of output. Commit with a message that says what and why. Then stop and wait.

Debug from evidence

Here's the failure: <command and output>. Give me your top three hypotheses, most likely first, and for each the quickest check that would confirm or rule it out. Run the checks that are read-only. Don't change code until we've agreed on the cause.

Review like a skeptic

Review the diff on this branch against main as a careful senior <engineer / SRE>: correctness, edge cases, error handling, security, performance and how we'd roll it back. Cite lines. Separate "must fix" from "worth considering". Don't fix anything.

Write the dry run first

Write <script> with a --dry-run flag that prints every change it would make and makes none. Make dry run the default if that's easy. Show me the dry-run output against <test data>. I'll do the first real run myself.

Hand off

Update HANDOFF.md: what's done, what's half-done and where, what we tried and ruled out and why, open questions, and the exact command to run next. Keep it under 40 lines.

Turn a session into rules

Look back over this session. What did you get wrong, or have to ask, that a line in AGENTS.md would have prevented? Suggest those lines. Only facts and commands, no general advice.

Where to go next


← Back: Scripts and automation · Next: Guardrails → · Back to the start