In https://lecursos.com/pt-br/articles/o-que-e-ia-e-o-que-nao-e-do-chat-ao-agente-e-por-que-usar-so-o-claude-code you learned that a language model has learned to predict the next word, which is why it writes confidently even when it is wrong. You also saw the distinction that underpins this course: in chat, the product is the answer; with an agent, the product is the project. And you opened Claude Code for the first time, in a folder of your own.Now we will look inside the model, without the math. To manage a tool, you need to know what it is made of, what it costs, and where it tends to fail. In this lesson, you will learn what a token is, how the model was trained, what the context window is, why AI makes things up that look real (with an actual example from one of my videos), and, most importantly, why turning a task into code uses far fewer tokens than repeating the same conversation every week.1. Tokens: AI's unit of account1.1 What is a token?A language model does not read letters or whole words. It reads tokens: chunks of text that can be a short word, part of a word, a punctuation mark, or a space followed by a letter. The Portuguese word "casa" is usually a single token. A long, less common word, such as "desburocratização", is split into several chunks. Numbers are split too: "2026" can become one or two tokens, depending on the model. These chunks let the model assemble any word, even one it has never seen.1.2 Tokens in PortugueseThe most widely used models were trained on much more English text than Portuguese. In practice, this means that a text in Portuguese usually uses more tokens than the same text in English, and a Portuguese word often takes more than one token. The exact ratio varies from model to model, so do not memorize a number: measure it. In this lesson's exercise, you will ask the agent to estimate how many tokens a piece of your own writing contains.For everyday use, a rough sense of scale is enough: a page of text amounts to a few hundred to just over a thousand tokens; a large spreadsheet pasted as text can easily exceed tens of thousands.1.3 Reading costs less than writingEvery request to a model has two costs. Input tokens cover everything the model reads: your question, the files you pasted, the project instructions, and the conversation so far. Output tokens are what it writes back. Model providers' pricing tables typically charge several times more for a written token than for a token read, because generating text takes more computing work than reading it. Check the provider's website for current prices.Claude's paid individual plan does not bill by the token: it has usage limits, and heavy users reach those limits sooner. Tokens are a resource, just like working hours or a budget.When you send a request to a model, which tokens count as input?Answer: everything the model reads: the question, files, instructions, and conversation so far. That is why a long conversation becomes increasingly expensive: with each new message, the model rereads what came before. Its answer counts as output.2. How a model is trained2.1 Predicting the next wordAt its core, training a language model is an exercise repeated billions of times: given a passage of text, guess the next token. "The Central Bank decided to keep the..." The next likely token might be "Selic", "interest", or "benchmark". The model guesses, compares its guess with the actual text, and has its internal parameters adjusted slightly to make fewer mistakes next time.Repeated across an enormous volume of books, websites, articles, and code, this exercise produces something remarkable. To predict the next word in an accounting text well, the model needs to have "absorbed" a great deal about accounting. To continue a piece of code, it needs to have absorbed the logic of the programming language. Nobody taught it the rules: they became embedded in the patterns. A second stage, using examples and human evaluations, then teaches the model to follow instructions and hold a conversation.2.2 The knowledge cutoffTraining runs up to a certain date, then stops. Anything that happened afterward is not part of the model's knowledge. We call this the knowledge cutoff. Ask a model without internet access about the latest decision by Copom, Brazil's monetary policy committee, and it will answer with what it knew at its cutoff date, or invent a plausible decision.The implication for managers: for recent data, go to the source rather than asking the model. The agent can search the web and download official data, as we will do in https://lecursos.com/pt-br/articles/pesquisar-e-analisar-dados-publicos-com-ia-22-indices-do-banco-central-e-do-ibge.2.3 What this explainsKnowing that the model predicts the next word explains why it writes fluently about almost anything and why it is good at summarizing and translating. It also explains its most dangerous failing, the subject of section 4: it produces the most likely text, not the truth. Most of the time, the two coincide. When they do not, it gives no warning.3. The context window3.1 What fits on the "desk"The model has no memory from one conversation to the next, or even within the same conversation in the human sense. What it has is a context window: the total number of tokens it can read at once to write its next response. Think of a desk. The model can see everything on that desk: the project instructions, the files it has read, the conversation, and the results of programs it has run. Anything that is not on the desk does not exist as far as the model is concerned.With current models, that desk is large, holding hundreds of thousands of tokens, depending on the model. That sounds like a lot, but an agent at work fills it quickly: every file opened, every program's output, and every attempt goes onto it.3.2 When the desk fills upIn Claude Code, you can check the desk at any time. The /context command shows how much of the window is already occupied and by what: instructions, files, or conversation. It is the equivalent of checking your balance before spending.When the desk starts getting full, there is /compact: the agent summarizes the conversation so far, keeps the essentials, and frees up space. If you do nothing, it also compacts automatically as it approaches the limit. Summarizing comes at a cost: details left out of the summary are lost. A decision agreed on two hours earlier, recorded only in the conversation, may disappear after compaction.This leads to an important habit, central to https://lecursos.com/pt-br/articles/o-projeto-no-claude-code-claudemd-memoria-e-cada-erro-virando-regra: anything that needs to last cannot live only in the conversation. Project rules go in CLAUDE.md, decisions go in a file, and data goes in the folder. The conversation is a draft; the project is the record.3.3 More context is not always betterDumping everything onto the desk "just in case" (the entire manual, three years of spreadsheets) uses tokens and makes the results worse. With the desk overloaded, important information competes with everything else for attention. It is like handing an intern a box containing a thousand sheets of paper and asking them to find the right clause: they may find it, but it takes time, and they might pick the wrong one. The right approach is the same as delegating to a person: provide the context that matters, point out where the rest is, and let the agent look it up when needed.You spent two hours working with the agent and agreed in the conversation that report figures must always be expressed in thousands of reais. After a /compact, what is the safest approach?Answer: write this rule in CLAUDE.md so it does not depend on the conversation. The compaction summary can lose details; CLAUDE.md is read at the start of every session. Avoiding /compact does not solve the problem: the window fills up, and the agent compacts automatically.4. Why AI gets things wrong with confidence4.1 HallucinationWe call it a hallucination when a model produces text with complete confidence that does not reflect reality: a quote nobody said, a legal provision that does not exist, a made-up number, or a bibliographic reference with a plausible author and year that was never published.This is not a flaw in one particular model: it is a consequence of how models work. The model was trained to continue text in the most likely way. When it lacks the information, the most likely continuation of "the relevant article of the law is..." is an article number that looks real. It has no internal "I don't know this" detector. Newer models make fewer mistakes, but the risk never drops to zero.4.2 A real example: the sentence I never saidHere is an example from my own work, dated November 22, 2026. I recorded a video about universal income for the Le Cursos channel's "Opinion on Brazil" segment (video O03). In my editing workflow, the first step after recording is to transcribe the speech with Whisper, an audio transcription model that runs on my own computer.Whisper accepts a vocabulary "hint", a short text describing the recording's subject and any difficult words that will appear. For this video, the hint listed the segment's name and terms such as Bolsa Família, BPC, Maricá, Finland, Alaska, Selic, and IPCA. This helps a lot: without it, proper names and acronyms come out wrong.Here is what happened: near the beginning of the video, between 16 and 30 seconds, instead of transcribing what I said, Whisper wrote out the hint itself as though I had spoken it. The transcript contained a sentence I had never uttered. There was no warning, no indication of uncertainty: the text was there, with start and end timestamps, just like everything else.This matters because, in my workflow, the agent reads the transcript to decide where to cut and what goes on screen. An invented sentence could lead to a bad edit or an incorrect caption. The fix was to transcribe just that passage again, this time without the hint, and check it manually by listening to the audio. The decision was recorded in the video's configuration file, in a comment stating exactly that: the transcription from 16 to 30 seconds contained the hint text and was redone manually.It was not the first time. In an earlier video, O01, Whisper repeated sentences that were not in the audio when it used previously transcribed text as context to continue. The fix became code: the transcription program was changed so it no longer used the previous text as context, with a comment explaining why.4.3 What to do about itThe management lesson is to design the process knowing that AI makes mistakes:Check what matters most. In a transcript, check the beginning and any passages that will become captions or cuts. In a report, check the figures going to senior management.Ask for the source. When the agent states a fact, ask where it came from. If there is no source, treat it as a hypothesis.Choose calculation over memory. A calculation performed by a program you can run again is more reliable than the model doing "mental arithmetic".Document the error. Every hallucination you catch is an opportunity to change the process so it does not happen again, as I did with transcription.Why does a language model sometimes make up information with complete confidence?Answer: because it generates the most likely text and has no internal detector for "I don't know". Lack of internet access makes the problem worse for recent facts, but it is not the cause: the Whisper incident happened with the full audio available.5. Why code uses fewer tokens than conversationThis is the most important section of the lesson because it explains the economic rationale for using an agent throughout the course.5.1 The hidden cost of repeating the conversationImagine a weekly task: creating a sales report from a spreadsheet. In a chat, the routine repeats itself. You paste the spreadsheet (input tokens), explain the format you want again (more input), and the model reads everything, reasons through it, and writes the report (output). If the result is off, you ask for corrections, and each correction makes the model reread the entire conversation.The following week, you start over: the previous conversation is no longer on the table. Every week, you pay for it to understand the task again and do the work again, and the report for week 2 may come out in a slightly different format from the one for week 1.5.2 The alternative: AI builds, code repeatsWith an agent, the request changes: "Write a program that reads this spreadsheet and generates the report in this format". The agent writes the program and runs it; you check it, and the agent fixes it. That uses tokens, perhaps more than a week's worth of chat. But from then on, every Monday, you run the program. The program does not use the language model: it reads the spreadsheet, does the calculations, and writes the report the same way every time, using zero tokens.The AI only comes back when something changes (the spreadsheet has a new column, management wants a chart): it updates the program, which then goes back to running on its own.5.3 A worked exampleLet's put some numbers to this. Note: this is a hypothetical example using round numbers, just to show the relative costs. Your numbers will be different; you will measure them in the activity.In chat, every Monday: the pasted spreadsheet accounts for 20.000 input tokens, the format instructions add another 1.000, and the written report uses 3.000 output tokens. Total: 20.000 + 1.000 + 3.000 = 24.000 tokens per week. Over 52 weeks, 24.000 × 52 = 1.248.000 tokens. And that assumes no corrections are ever needed, which is optimistic.With the agent: building, testing, and fixing the program in one session uses, say, 150.000 tokens (the agent reads files, runs the program, makes mistakes, and fixes them). Over the year, assume 4 updates of 30.000 tokens each: 4 × 30.000 = 120.000. Annual total: 150.000 + 120.000 = 270.000 tokens. The 52 weekly runs cost zero.The comparison: 1.248.000 ÷ 270.000 ≈ 4,6. In this example, using a program consumes less than a quarter of the tokens used by chat in the first year. In the second year, the gap widens because the initial build is already paid for: chat still uses 1.248.000, while the program only needs updates, at 120.000, roughly ten times fewer.When does the program break even? Building it (150.000) is equivalent to 150.000 ÷ 24.000 = 6,25 weeks of chat. So, from week 7 onward, the program is already ahead. Notice the rule that emerges: the more often a task repeats, the more it pays to turn it into code. A task you do only once does not need a program; one you do every week almost always does. There are benefits beyond the numbers, too: the report comes out the same way every time, and any colleague can run the program.5.4 Two examples from my own workThe first is a social media campaign featuring 22 official Brazilian indicators, from 2019 to 2026. Claude Code wrote a program called montar.py. When I run montar.py --baixar, it downloads the time series from the public APIs of Banco Central and IBGE and saves everything to a data file; another program creates the images, PDF, and videos. To update everything with new data, I run the two programs, with no conversation involved. At https://lecursos.com/pt-br/articles/pesquisar-e-analisar-dados-publicos-com-ia-22-indices-do-banco-central-e-do-ibge we will examine the method behind this example.The second is my video workflow, which you will see in full at https://lecursos.com/pt-br/articles/documentos-apresentacoes-e-videos-com-ia-por-dentro-da-producao-do-canal-le-cursos. The language model handles the work that needs it: Claude reads the lesson transcript and records the editing decisions in a file (where to cut, the opening hook, which image appears at each point, the chapters, the title). That uses tokens, and it is worth it: it requires judgment about text. After that, the repetitive, processing-intensive work (cutting the video, applying zoom, creating subtitles, assembling everything into an MP4) is handled entirely by code, without a single token. If I change a decision, the code reprocesses the affected part.In the hypothetical weekly report example, from which week has the program used fewer tokens overall than chat?Answer: from week 7. Building the program cost 150.000 tokens, equivalent to 6,25 weeks of chat at 24.000 per week. From week 7 onward, every week brings savings (after accounting for updates).6. When to use the model and when to use codePutting it all together gives us a practical rule for dividing the work, one we will return to throughout the course:Use the model for tasks that require judgment about language: understanding a request, reading a transcript and deciding what to cut, summarizing a document, writing a first draft, writing the program.Use code for repetition and calculations: downloading data, calculating indicators, generating the same report every week, rendering a video, checking whether a field has been filled in.Leave accountability to a person: checking critical details, approving anything that will be made public, deciding what to include and what to leave out.This division also reduces hallucinations: a number calculated by a program from an official time series is not something the model "remembers", and anyone can recalculate it. If the model makes a mistake when writing the program, the error is visible, and you fix it once.7. Common mistakes"A token is the same as a word." It is not. A token is a piece of text; in Portuguese, a word usually takes more than one. To estimate cost and context usage, measure tokens rather than counting words."The more I put in the context, the better the answer." Too much context uses tokens and dilutes the model's attention. Provide what matters for the task and leave the rest in the folder, where the agent can find it when needed."If the text sounds fluent and confident, it must be right." Fluency is precisely what the model does well, whether it is right or wrong. The sentence Whisper invented in my video had start and end timestamps like any other. Check against the source, not the tone."Using the agent for everything, every time, is the modern way to work." The efficient approach is to let AI build and code repeat. Asking every week for something a program could do on its own means paying again for the same work.8. Bringing it all togetherThe token is AI's unit of accounting. The model reads and writes in chunks of text; reading costs less than writing; and a long conversation becomes expensive because the model rereads everything with each message.The model predicts the next word and has a knowledge cutoff. Look up recent data at the source rather than asking the model to recall it.The context window is the workbench. Check it with /context, free up space with /compact, and do not leave anything important only in the conversation: anything that needs to last belongs in the project.AI makes mistakes confidently. Hallucinations arise from the way it works. The O03 transcription example shows the remedy: check critical details and turn the correction into a process.Code uses fewer tokens than conversation. AI builds once, and the program repeats the work for free. The more often the task repeats, the greater the savings, while the results remain consistent, verifiable, and documented.In the next lesson, we will set up the actual project: CLAUDE.md, memory, and turning every mistake into a rule.Claude Code activity (20 minutes)1. Open Claude Code in the course's "ia-gestao" folder.2. Choose a one- or two-page text you have written (a report, a long email, a college assignment) and save it in the folder as texto.txt. Ask: "Count the words in texto.txt and estimate how many tokens it contains. Explain how you made the estimate and its margin of error."3. Check: open the file and see whether the word count matches your text editor's counter. Ask the agent how many tokens per word its estimate works out to, and whether that would change if the text were in English.4. Type /context and check how much of the window is already in use and what is using it. Write down the number.5. Now turn a task into a program. Ask: "Write a program that reads texto.txt and generates a file called resumo_numeros.txt containing: the word count, the sentence count, the 10 most frequent words (excluding articles and prepositions), and the average sentence length. Run the program and show me the result."6. Check two of the calculations by hand (for example, the number of sentences in a paragraph). If anything is wrong, explain it to the agent and ask for a correction.7. Run the program again yourself with a different text. Notice that this time, no tokens were used for the calculations.8. Ask the agent to record a rule in CLAUDE.md: "Any task I will repeat becomes a program in the folder; calculations are done in code, not mentally."Class discussion exerciseAn accounting firm uses an AI chat every day to read clients' bank statements, copied and pasted into the chat, and categorize each transaction. Discuss: (a) which parts of this task require judgment about language, and which are repetitive work a program could do? (b) Where would a hallucination be most dangerous, and how could the process catch the error? (c) Make a rough estimate, using invented numbers clearly identified as such, of how many tokens the firm uses each month in chat and how many it would use to build and maintain a program. In which month would the program break even?Exercises1) Which statement about tokens is correct?A) A token is always a whole word.B) A text in Portuguese usually uses more tokens than the same text in English.C) Only the model's response consumes tokens.D) Input and output tokens always cost the same.E) Numbers and punctuation do not become tokens.2) A manager asks a model without internet access what last month's inflation rate was. The main risk is:A) The model refusing to answer any question about economics.B) The model using too many tokens for the answer.C) The model crashing the computer.D) The model giving a plausible but outdated or invented number because of its knowledge cutoff.E) The model copying another user's answer.3) In Claude Code, the /context and /compact commands are used, respectively, to:A) See how much of the context window is in use; summarize the conversation to free up space.B) Delete the project; create CLAUDE.md.C) Install Claude Code; update the model.D) Download data from the internet; compress files into .zip archives.E) Show the token price; request a refund.4) For a weekly task, building a program cost the equivalent of 5 weeks of chat. Excluding updates, the program starts saving tokens:A) In week 1.B) In week 3.C) Only after a year.D) Never, because building it costs more.E) From week 6 onward.5) (True or false) "In the transcript of video O03 from the Le Cursos channel, Whisper flagged the passage containing the vocabulary tip as uncertain, making the error easier to find."( ) True ( ) False6) (True or false) "Using the language model to make decisions and write the program, while leaving repetitive tasks to the code, reduces token usage and makes the result easier to check."( ) True ( ) FalseAnswer Key1) B — The models were trained on more English text, and a Portuguese word typically takes more than one token. Both input and output use tokens, and output tokens usually cost more than input tokens.2) D — Without access to the source, the model answers based on what it knew before its knowledge cutoff, or continues the text with a seemingly plausible number. Recent data should be checked at the official source.3) A — /context shows how much of the context window is in use; /compact summarizes the conversation and frees up space, at the risk of losing details that appeared only in the conversation.4) E — If building the program cost the equivalent of 5 weeks of chat, the first 5 weeks cover that cost; from the 6th week onward, every week the program runs represents savings.5) False — There was no warning: the fabricated text had start and end timestamps just like the rest. That is why having a person check the critical passage is part of the process.6) True — AI is used where judgment is needed; repetitive tasks run without tokens, the same way every time, and anyone can read and rerun the code.
Reactions
0
0 Comments
Be the first to comment
Nothing here yet.