Voltar aos PodcastsClaude
Claude Code 101
Gerenciamento de contexto no Claude Code
is Claw's working memory.
é a memória de trabalho do Claude.
Every file it reads, every command it runs, every message you send, it all takes up space in the context window.
Cada arquivo que ele lê, cada comando que executa, cada mensagem que você envia, tudo isso ocupa espaço no context window.
Think of the context window as the amount of space that Claude could hold in his memory.
Pense no context window como a quantidade de espaço que o Claude pode manter em sua memória.
Whenever you enter a prompt, Claude reads a file, runs a tool call, gets a tool call result.
Sempre que você insere um prompt, o Claude lê um arquivo, executa uma chamada de ferramenta, obtém um resultado de chamada de ferramenta.
This is added on to the context window.
Isso é adicionado ao context window.
And since there's only a finite amount you can put in the context window, it becomes extremely important to optimize this as much as possible.
E como há apenas uma quantidade finita que você pode colocar no context window, torna-se extremamente importante otimizá-lo o máximo possível.
Now, when you approach this limit, the context window is automatically compacted.
Quando você se aproxima desse limite, o context window é compactado automaticamente.
Compaction will summarize important details and remove the unnecessary tool call results and free up a lot of space in your context window.
O compact resumirá detalhes importantes e removerá os resultados de chamadas de ferramentas desnecessários, liberando muito espaço no seu context window.
Do note though that this could potentially lose details in your previous conversation.
Note, porém, que isso pode potencialmente perder detalhes da sua conversa anterior.
You can run the compaction manually as well with the /compact command.
Você também pode executar a compactação manualmente com o comando /compact.
This will compact everything that you've done up to that point, which could be handy if you want to clear up context space, but also have a memory of what you previously worked on.
Isso vai compactar tudo o que você fez até esse ponto, o que pode ser útil se você quiser liberar espaço de contexto, mas também manter uma memória do que trabalhou anteriormente.
If you want to completely start from scratch without memory of what was previously worked on, you can also run /cle and that will remove everything starting from scratch.
Se você quiser começar completamente do zero sem memória do que foi trabalhado anteriormente, você também pode executar /clear e isso removerá tudo começando do zero.
To check the state of your context, run the /context command.
Para verificar o estado do seu contexto, execute o comando /context.
Here you'll get a big picture of how large your context size is, the different categories that are taking up the most context, and a graphic showing you all of this.
Aqui você terá uma visão geral de quão grande é o seu contexto, as diferentes categorias que estão ocupando mais contexto, e um gráfico mostrando tudo isso.
A general rule of thumb is when you're working on a specific feature and are going over the context window, but need to continue, then compact.
Uma regra geral é que quando você está trabalhando em um recurso específico e vai ultrapassar o context window, mas precisa continuar, então use compact.
Keeping the context relevant for this feature is important when continuing development.
Manter o contexto relevante para esse recurso é importante ao continuar o desenvolvimento.
If you have finished the plan and want to start on a new feature, then clear.
Se você terminou o plano e quer começar em um novo recurso, então use clear.
You don't want the previous conversation to present bias in anything new that you want to create.
Você não quer que a conversa anterior apresente viés em qualquer coisa nova que você queira criar.
For things that you do want Claude to remember in other sessions, put it in the claw.md file.
Para coisas que você quer que o Claude lembre em outras sessões, coloque no arquivo claude.md.
That way, it doesn't have to rediscover things from scratch all over again.
Assim, ele não precisa redescobrir as coisas do zero a cada vez.
Be specific.
Seja específico.
The irony behind writing a smaller prompt is that it in the long run, it will take up more context.
A ironia por trás de escrever um prompt menor é que, a longo prazo, ele vai ocupar mais contexto.
Without being explicit, Claude is forced to look around your codebase more and do its own thinking, which takes up a lot more context.
Sem ser explícito, o Claude é forçado a vasculhar sua codebase e fazer seu próprio raciocínio, o que ocupa muito mais contexto.
window space than if you were just a little bit more clear with a sentence or two.
espaço de janela do que se você tivesse sido um pouco mais claro com uma frase ou duas.
MCP servers load all of the tools available into context by default.
Os servidores MCP carregam todas as ferramentas disponíveis no contexto por padrão.
So, if you have a lot of MCP servers for things that are unrelated to the project, it might be worth turning them off.
Então, se você tem muitos servidores MCP para coisas não relacionadas ao projeto, pode valer a pena desativá-los.
You can also try out skills, which works similarly to MCP servers, but doesn't put the entire thing into context, saving you space.
Você também pode experimentar skills, que funcionam de forma similar aos servidores MCP, mas não carregam tudo no contexto, economizando espaço.
Sub agents run in parallel with your main agent but has a complete separate context window.
Sub agents executam em paralelo com seu agente principal, mas têm um context window completamente separado.
So for tasks that require an answer without the journey like where is the authentication endpoints located, you can have the sub agent do the work and return just a summary to your main agent.
Então, para tarefas que requerem uma resposta sem o percurso, como onde estão os endpoints de autenticação, você pode fazer o sub agent realizar o trabalho e retornar apenas um resumo para seu agente principal.
Managing context within cloud code is crucial.
Gerenciar o contexto dentro do Claude Code é crucial.
Use slash compact to summarize long sessions and slashclear to start fresh.
Use /compact para resumir sessões longas e /clear para começar do zero.
To use your context window effectively, be specific with what you want.
Para usar seu context window de forma eficaz, seja específico com o que você quer.
Check what's using your current context window and use sub agents to delegate tasks you only need the answer for.
Verifique o que está usando seu context window atual e use sub agents para delegar tarefas das quais você só precisa da resposta.