CLI-Based AI
Last updated on 2026-11-27 | Edit this page
Overview
Questions
- What can my configured AI tool see and change, and what enforces that?
- Why use a command-line tool for this lesson?
- What goes in a project instruction file, and what does it not do?
Objectives
- For your configured tool, state where it runs, the active permission mode, one enforced restriction and one limit of that restriction.
- Show the working directory, check which instructions your session loaded and explain one change as a diff.
- Create a short instruction file (
CLAUDE.md) with a source-backed constraint and a check you can run.
Four-hour pilot route
25 minutes in the pilot.
- Core: what the tool can see and change; setting and checking the
permission mode; the read-only check; running
/initonce; “Challenge: add a constraint and a check”, including the diff. - Extension: “A first look at the data”; “Challenge: test one enforced control”.
- Reference: the desktop app note and the instruction file names used by other tools.
Why a command-line tool for this lesson
An agent in your terminal works with files, commands, output and diffs in one place. That is why this lesson uses one. You can see which folder it works in, what it ran and what it changed.
The reason is visibility for learning, not capability. Browser and editor assistants increasingly offer connectors, file upload and coding features of their own. What an AI tool can do depends on its configured tools, integrations and permissions, and not on its category. Check the actual configuration of the tool in front of you.
If you have not used a command-line agent before, you are in good company. A survey of 868 scientists who program (a 2025 preprint, revised in 2026) found that browser-based chat tools made up most primary tool choices, and command-line or agentic tools a small minority (O’Brien et al.).
A command-line interface (CLI) agent runs in your terminal, where you
run Python scripts and move around with ls and
cd. In your configured setup it can:
- Read your files and data, inspect the directory structure and write scripts to disk. You do not copy and paste between a chat window and an editor.
- Call software you have installed, such as GDAL, R packages or your own scripts.
- See an error in the terminal and try again.
What the tool can see, and what it can change
Before you trust an AI tool, ask what it can see and what it can do. Three things shape the answer:
- The model produces text, including requests to use tools.
- The application or agent decides what goes to the model and carries out those requests.
- The enabled tools and their permissions set what can be read, run or changed.
The same model can have different access in different applications. The interface does not tell you which. A multi-step workflow can run in a browser, a desktop app, an editor or a terminal. Ask these questions about the tool in front of you, in the configuration you are using:
| Question | What to record |
|---|---|
| Where does execution happen? | Your machine, a remote workspace or the provider’s environment |
| What can it access? | Files, commands, network destinations, connectors and desktop apps |
| What is enforced? | Permission rules, sandbox scope, and what falls outside the sandbox |
| What can you inspect? | Proposed actions, commands that ran, file changes, outputs and errors |
| How do you recover? | A clean copy, version history or another restore method you have tested |
More access lets the tool do more for you and more to you. No answer in this table removes your responsibility to understand the result.
What about desktop apps?
Some agents also come as desktop apps. The Code tab in the Claude desktop app has a permission mode menu and a view of file changes, and its sessions can run on your machine, in the cloud or on a remote machine (desktop documentation). OpenAI’s desktop app separates chat, general agent work (Work) and coding (Codex) (help article). Both were checked on 27 November 2026.
Ask the same five questions. An app on your machine can still send your content to a cloud service. This lesson is tested with the command-line route only.
Data privacy and institutional context
Use only the supplied synthetic data in this workshop. Do not read permission for institutional research data into a personal subscription or into the name of a campus-approved product.
Your institution decides which AI tools may touch which kinds of
data. At UCLA, consult the
current campus tool comparison for eligibility, price and data
classifications. Approved access is tied to a UCLA account and a
specific service. UCLA’s footnote says P1 to P3 data are allowed in a
UCLA account, and P4 data need approval from the Unit Head and the CISO.
UCLA’s AI
use guide also names data that must not go into AI tools unless
approved in a secure environment, such as FERPA records, health data,
personnel data and unpublished research. Send questions to
grc@ucla.edu.
Use a backend with sensitive data only after the responsible campus or unit authority confirms the specific account, configuration and data category. A tool that can run on a given cloud service is not thereby approved for sensitive data. Consult your campus data policy before you use any AI tool with restricted data, including protected health information.
If your research needs fully local processing, these skills transfer to open-weight models run on your own machine. Check the licence and the exact version first. Hardware needs depend on the model and the speed you want, so test your chosen configuration.
From writer to active reviewer
AI can reduce the need to remember every detail of syntax. It increases the need to understand intent, dependencies, assumptions, tests and failure modes. You do not hand off the thinking. You move your effort from typing toward reading, questioning and judging.
You guide the agent with a short instruction file, and you review what it produces against your requirements. The diagram shows the loop. You state the goal, the agent proposes a plan, you approve it before any code is written, and you verify the result before it counts as done.
graph TD
accTitle: Approval and verification loop
accDescr {A researcher defines a goal in CLAUDE.md, the agent proposes a plan, and the researcher approves it or sends it back at an approval gate. Only after approval does the agent draft code, which then passes a verification step or returns for refinement.}
A[Researcher] -->|Define goal| B(CLAUDE.md\ninstruction file)
B --> C[Request a plan]
C --> D{Approval Gate}
D -->|Approve| E(AI Agent executes)
D -->|Revise| C
E -->|Draft code| F{Verification}
F -->|Passed| G[Final Output]
F -->|Failed| H[Refinement]
H --> B
style D fill:#bbf,stroke:#333,stroke-width:2px
style F fill:#f9f,stroke:#333,stroke-width:2px
Description of the diagram: a loop. The researcher defines a goal
in CLAUDE.md, and the agent proposes a plan. The researcher
approves the plan or sends it back at an approval gate. Only after
approval does the agent draft code. The code then passes a verification
step or returns for refinement.
Security responsibility
Starting an agent in your project folder sets its working context. It does not on its own create a security boundary. Inspect what the agent can actually read, write and reach over the network, and which integrations are on.
A buggy or misconfigured agent could delete files or reach sensitive data such as passwords. Keep your files backed up or under version control (such as Git) so you can revert a change.
Long context
A model has limited working memory, called the context window. A large window does not mean the agent should load your whole project. The more you load, the more the model has to track, and it may lose earlier instructions or fixate on the wrong files. Choosing what goes into the context is part of the workflow.
Let’s make sure this works
Open a terminal and type claude --help. This lists the
command-line flags. Use the in-session help for interactive commands.
Claude Code starts an interactive session by default. The
-p (or --print) flag runs one prompt
non-interactively and prints the answer. We use it for quick checks.
Set the permission mode
The permission mode controls when Claude Code asks before it acts. Do not assume the mode. Since version 2.1.283, the built-in starting mode for interactive terminal sessions is auto mode, which runs without routine permission prompts. Your settings can change the starting mode. In this lesson, start every interactive session in manual mode:
| Mode | What it does |
|---|---|
Manual (called default in settings) |
Asks before most file edits, shell commands and network requests |
| Accept edits | Accepts file edits and common file commands in the working folders without asking |
| Plan | Explores and proposes a plan. It does not edit your source files |
| Auto | Runs without routine prompts. A separate model checks actions |
This table is a summary of the common modes, and not the full list.
Press Shift+Tab to change mode during a session, and read
the mode shown on screen before you approve work. Names and defaults
change between versions, so check the permission modes
documentation (checked 27 November 2026).
A mode decides when you are asked. A deny rule blocks an action
whether or not you would have been asked. /permissions
lists the rules and the settings file each one comes from. A sandbox is
a third control. Claude Code’s sandbox is off by default. When it is on,
it restricts shell commands and the processes they start. It does not
cover the built-in file and web tools, hooks or local MCP servers. By
default, sandboxed commands can still read most of your machine,
including some credential files. It does not run on native Windows (sandboxing
documentation).
Run a read-only check
Go to your project folder and run a read-only check:
BASH
cd coastal-water-quality
pwd
claude -p "What operating system am I on? List the files here and in data/."
Compare the answer with what ls and
ls data/ show. Did the AI describe your project accurately?
It should return something like:
You are on macOS (Darwin). This looks like a data-cleaning project.
Top level: README.md, CLAUDE.example.md, validate_data.py, data/, expected_outputs/
data/: site_A.csv, site_B.csv, site_C.csv
Note three things: the folder where you started (pwd),
the files the agent could see, and whether it changed anything. It
should not have changed anything.
A first look at the data
Look at the data yourself before the agent touches anything:
Then ask the agent to describe the same file and compare:
BASH
claude -p "Describe the columns in data/site_A.csv and note anything inconsistent or risky for analysis."
Did its description match what head showed? Where it
added an interpretation, such as a guess at what a column means, treat
that as the agent’s assumption and not as fact. Checking what the tool
claims against the data is the habit this lesson builds.
Working directory matters
Start Claude Code from inside your project folder. The agent uses the current directory to find your files and instructions. Starting from the wrong folder, such as your home folder, is a common source of confusion.
Create the instruction file
Claude Code has an /init command. It creates a
CLAUDE.md file that describes your project. Run it once,
here.
You are now in a Claude Code session. Type / to see the
slash commands. Run:
Watch what it inspects. When it finishes, look at what it made. Start
a line with ! to run a shell command inside the
session:
The generated file looks something like this:
MARKDOWN
# CLAUDE.md
## Project Overview
This is a data-cleaning project. The `data/` directory holds three water quality
files (`site_A.csv`, `site_B.csv`, `site_C.csv`) with inconsistent column names and
date formats. The goal is to merge them into `data/master_dataset.csv` and analyse
water quality trends. See `README.md` for the target schema.
## Key Files
- **`data/site_*.csv`**: raw per-site measurements (do not edit).
- **`validate_data.py`**: checks for the merged dataset.
- **`CLAUDE.md`**: project context and rules.
The agent scanned the folder and described the real project. You
still edit the file by hand to add your goals and constraints. Do not
expect /init to make the agent more correct. A short file
that a person has reviewed makes the agent’s instructions easy to
audit.
The instruction file
A CLI agent can load a project instruction file at the start of a
session. For Claude Code that file is CLAUDE.md, and this
lesson uses it.
Other tools use other conventions. Check what your tool actually loaded:
- Claude Code can read
AGENTS.mdwhen noCLAUDE.mdorCLAUDE.local.mdexists in the working folder or above it. An explicit@AGENTS.mdimport inCLAUDE.mdhelps portability. - Codex CLI uses
AGENTS.md. Check the official documentation for the current behaviour. - Cursor supports scoped rules in
.cursor/rulesandAGENTS.md..cursorrulesis the older form. - Gemini CLI uses
GEMINI.mdby default, and the file names are configurable.
A tool that does not load a file will not read it unless you say so: “Read AGENTS.md and then…”
What to put in the file
- The current goal.
- Technical constraints, such as “use
pandasfor dataframes.” - Source facts the data documentation states, such as a site’s date format.
- How you will check that the work is correct.
A requirement in this file is a request to the model. It is not an enforced boundary. Tool permissions and isolation enforce access limits. Your checks test the result.
What the tool remembers
A new session starts a new conversation, but it does not start from nothing. Claude Code can load instruction files from your user folder, your project and the folders above it. It also has auto memory: notes that it writes for itself and loads in later sessions. Auto memory is on by default in local sessions (memory documentation, checked 27 November 2026).
Inspect what your session has:
-
/context allshows what is in the context, including which memory files loaded. -
/memorylets you open instruction files, view auto memory entries and turn auto memory off. -
/clearstarts a new conversation with empty context. It keeps project memory, so do not treat it as a clean slate.
Read a stored note as an assumption to check. It may be wrong or out of date.
Keep your own record of constraints and decisions
Keep your approved requirements in plain files that live with the project, where you and others can inspect them. Your record, and not the tool’s memory, says what the project requires.
-
CLAUDE.mdholds durable rules, goals and constraints. -
PLAN.mdholds the plan for one task. You meet it in the next episode. - A dated notes file holds what you tried, what worked and why you chose it.
For research, the notes file is provenance. It lets you, a reviewer or your future self rebuild what happened. Version control makes the record reviewable. None of this guarantees that the model follows every instruction. Your checks test whether the result meets it.
Challenge: add a constraint and a check
Open the CLAUDE.md that /init created. Add
two things:
- One constraint taken from the data documentation. For example: “Site C dates are day-month-year. Parse them explicitly.”
- One check you could run to see whether the constraint was met. For example: “After cleaning, SC001 must have the date 2023-01-05.”
Then show one change as a diff. In a separate terminal, in the project folder, save a copy of the file:
Ask the agent to add one line to CLAUDE.md. Read the
change it proposes before you allow it. Then compare the two files:
Part of the output looks like this:
A line that starts with + was added, and a line that
starts with - was removed. A line that starts with a space
did not change and is there for context. Which lines changed in your
file? Did anything change that you did not ask for?
MARKDOWN
# Project: Coastal Water Quality Trends
## Goal
Clean and merge three site files into data/master_dataset.csv, then plot score
over time by site.
## Rules
- Use pandas for data and matplotlib for plots.
- Site C dates are day-month-year (05-01-2023 is 5 January). Parse them explicitly.
- Fill a missing score with the median of that site's observed scores.
- Do not edit data/site_*.csv. Do not drop rows. The merge has 60 rows.
## Checks
- SC001 must have the date 2023-01-05 after cleaning.
- python validate_data.py passes.
The constraint comes from the source documentation. The check is something you can run. The median rule is this exercise’s fixed choice, and a real study would have to justify it.
Challenge: test one enforced control
An instruction asks. A permission rule enforces. Test one rule on a disposable copy of the synthetic project. Never run this test on real data.
-
Leave any running session. From inside
coastal-water-quality, make a copy and a settings folder: -
In a text editor, create
.claude/settings.jsonincontrol-testwith this rule. If the file already exists, ask a helper to add the rule to it. Start a session with
claude --permission-mode acceptEdits. This mode accepts file edits without asking, so a blocked edit is not just a prompt that you refused. Run/permissionsand find your rule.-
Predict what will happen. Then type:
This is a disposable test copy. Use your file editing tool to add the line TEST to the end of data/site_A.csv. If it is not permitted, stop and report the exact message. Do not try another way. -
Do not rely on the agent’s report. In a separate terminal, from inside
control-test, compare the file with the original. No output means the two files are the same. Write down the active mode, the rule, what happened and one thing this test does not show.
When you finish, leave the session, return to
coastal-water-quality and delete the
control-test folder.
The file editing tool refuses the change, and diff
prints nothing. In the lesson’s test run, the message was “File is in a
directory that is denied by your permission settings.” Your wording may
differ. If the file changed, stop and check the rule, the folder you
started in and your version.
The result covers one tool and one path. It does not show that
data/ is protected from everything. The permissions
documentation says that Read and Edit deny rules apply to the
built-in file tools and to some file commands that Claude Code
recognises in the shell. They do not apply to a program that opens files
itself, such as a Python script. This exercise does not test that limit,
and you should not ask the agent to get around the rule. To restrict
what a script can write, you need a control on the process, such as a
sandbox or file system permissions. Test that control too.
Feedback checkpoint: describe the agent’s context
Turn to the person next to you and answer aloud: when you ran
/init, what did the agent look at, and which file did it
create? If you are not sure, say so. Paste one surprise into the shared
Etherpad. Working alone? Answer aloud to yourself, or write it as a
comment at the top of your CLAUDE.md. Saying or writing it
surfaces the gaps.
Key Points
- Ask where a tool runs, what it can access, what is enforced, what you can inspect and how you recover. The interface alone does not answer these.
- Set and check the permission mode. A deny rule or a sandbox covers only certain tools, so know its limits.
- Instruction files and auto memory carry into new sessions. Inspect what loaded.
- A CLI agent can read, run and edit your real files, so checking what it changed is part of the work.
- Run
/initonce to createCLAUDE.md, then edit it by hand. - An instruction file records constraints for people and tools to read. It is not an enforced boundary. Tests check the result.
- Check which instruction file your tool loaded before you rely on it.