ProgressBar

How Does AI Edit Your Files?

How does the text AI returns turn into actual file changes through terminals, tools, and the operating system?

By ZongyuPublished: Updated:

Today, let’s talk a little about how AI edits your files.

 

Doesn’t it seem strange? When you chat with ChatGPT, you type text, and it sends text back. But with AI agents like Codex and Claude Code, how come they can edit files on your computer?

 

After all, the model is still only generating text.

 

To understand this, let’s put the chat window aside for a moment and think: how do we normally tell a computer to do things?

 

 

Computers Can Already Be Operated Through Text

You’ve probably seen it in movies: a black screen covered in text. If you’ve used DOS before, that screen should look familiar too.

 

There don’t seem to be any buttons, or anything to click with a mouse. But that doesn’t mean you can’t operate the computer.

 

You can type a command and press Enter to have the computer list files, open a program, or write content to a file.

 

So text has always been a way to operate a computer.

 

There is one condition, though: a program has to receive that text, interpret it according to established rules, and ask the operating system to carry out the action.

 

If you write “delete the file” in Notepad, the file won’t just disappear. That’s because Notepad simply stores the sentence. It doesn’t treat it as a command.

 

The same text produces different results depending on which program handles it.

 

 

The Terminal Is One Way In

Both Windows and macOS have environments where you can enter commands. You may have heard of the terminal, or Command Prompt.

 

These names don’t all refer to exactly the same thing, but let’s focus on one idea for now: this kind of interface lets you tell a computer what to do through text.

 

To be a little more precise, the terminal lets you type input and displays the results. The program that interprets the commands is usually called a shell.

 

You enter text, and the shell interprets the command’s structure and carries out the corresponding action. Of course, if you type some random text it doesn’t recognize, it may just return an error message.

 

So there’s already a whole mechanism connecting these pieces. You don’t have to handle how data gets written to the drive, or know how the circuits inside the computer are connected.

 

You just have to give instructions in a form it understands.

 

 

You Can Edit Files Through Text Without AI

Let’s start with a very simple command called echo.

 

The examples below are hypothetical demonstrations using syntax common to shells on macOS or Linux. They have not been run on your computer.

 

echo 123

 

This command displays 123.

 

Whatever text you give it, it outputs that text. Don’t worry about everything else it can do for now. We’re just looking at this most basic use.

 

Next, what if we write it like this?

 

echo 123 > example.txt

 

Now the result does more than appear on the screen.

 

The > tells the shell to write the preceding command’s output to example.txt. Assuming the file doesn’t already exist and writing is allowed in the current location, this creates a file containing 123, followed by a newline.

 

If a file with the same name already exists, this normally overwrites its contents.

 

See? There’s no AI involved at all, and we can already change a file.

 

That’s because this text is passed to a program that executes commands, and that program has permission to write to the file.

 

 

Connect Commands, and You Can Do More

What if you have several steps?

 

For example, output 123, then 456, and finally 789.

 

echo 123
echo 456
echo 789

 

This displays three lines in order. It doesn’t automatically join them into 123456789 on a single line.

 

You can save these lines in a file and have the shell execute it. That’s a very simple script.

 

Operations you would otherwise type one line at a time can be arranged into a sequence to run.

 

Besides running commands in order, the shell can also connect programs together. One way to do this is with a pipe, usually written as |.

 

It connects one program’s standard output to the next program’s standard input.

 

That sounds a little abstract, so let’s look at an example:

 

echo 123 | cat

 

The echo at the front outputs 123. The cat after it reads the content passed along and outputs it again.

 

So you still see 123.

 

But the program on the receiving end has to read that input. You can’t just connect an echo 456 and expect it to automatically add the preceding content to its own output.

 

The pipe passes data along. How that data gets processed depends on the receiving program.

 

Likewise, passing text to another program doesn’t necessarily mean it will be executed as a command. It can only potentially turn into an action if the receiving program can interpret commands, as a shell does.

 

 

This Is How AI-Generated Text Connects to Tools

Back to the original question: how can AI edit your files?

 

Suppose we have an AI agent that can execute shell commands, and you ask it: “Create an example.txt file for me containing 123.”

 

The model can generate the command we just saw:

 

echo 123 > example.txt

 

If it simply pastes this into the chat window, all you see is text.

 

But if the surrounding program is connected to an execution tool, it can send that command to the shell. The shell then writes the content to the file through the operating system.

 

There’s now an extra step that actually carries out the action.

 

Editing files doesn’t always have to go through the terminal, though.

 

Some tools can read or write files directly, or apply a set of changes. The model supplies the file location and the text to change, and the surrounding program calls a tool to perform the write.

 

So thinking of an AI agent as “a program that enters terminal commands for you” can help you understand one common approach. But the tools available to it may also include file editing, search, or browser operations.

 

The model decides what to do next, the tool carries it out, and the result goes back to the model. This is also a core idea in how Anthropic explains these systems in its article introducing AI agents.

 

 

Why Can It Keep Taking Steps After You Ask Just Once?

Because the surrounding program can send the execution results back to the model.

 

Suppose you ask it to edit an article. It might first read the file to get the original text, decide which passage to change, call a tool to write the changes, and finally read the file again to check the content.

 

If the tool reports that it can’t find the file, the model can use that result to decide whether to look for the file’s location first.

 

This creates a loop: decide on an action, call a tool, get the result, and decide what to do next.

 

That’s why you can give it one instruction and have it continue through several steps. When it stops depends on the task’s status, the program’s settings, and the tools’ limits.

 

Generating a long stream of text doesn’t mean the whole job is done. Whether a tool executes successfully directly affects what happens next.

 

 

Which Files It Can Edit Still Depends on Permissions

Does that mean it can edit anything?

 

That depends on what capabilities are available in the environment where the tools run.

 

For example, a tool might only be allowed to read a particular folder, or only write within the working directory. Even if the model generates a command to edit other files, execution may be blocked.

 

If the account running the program has higher privileges, it can usually affect a wider range of things.

 

But even a superuser may still be subject to a sandbox, operating system protections, or other restrictions. You can’t assume that granting the highest privileges guarantees access to everything on the computer.

 

The next time AI says “the file has been modified,” you can check its tool logs: which file did it read, what changes did it submit, and what result did the tool report?

 

If it only returns a revised passage, someone or some program still needs to save that content. If it has called a tool to write to the file and the tool reports success, then you have evidence that the file was actually written.

Zongyu

Zongyu

Recording courses is killing me!!!