Transcript
00:00:00If you've been working with agents for a while, you might also have hit your limits in the middle
00:00:03of doing something important, and you have to wait for it to reset before you can continue your work
00:00:08again. That's been a cause of frustration for us too, due to which we use a certain set of measures
00:00:13to make the limits last as long as possible so that we can get more work done on the same plan,
00:00:18but the main goal is not only to get more work done, but also to get the highest quality result
00:00:23from it. If this is your first time, we're a software company, and this is our channel AI Labs,
00:00:28and in this video, we're going to go over all 24 tips we have collected for countering this context
00:00:32problem and list everything that actually worked for us in both Claude Code and Codex. Now, this
00:00:38video is split into three levels, and they go from the habits you need in your workflow to the changes
00:00:42you make to the tools themselves, and there are timestamps below, so you can skip to whichever
00:00:47level you need. Now, the first section is about how the context window and your usage limits work
00:00:52in both Claude Code and Codex, so if you're familiar with this, you can skip on to the next section from
00:00:57the timestamps down below. Now, before we go into usage limits, let's first understand the context
00:01:02window. The context window is how much a model can hold in one conversation at any one time,
00:01:07and it's measured in tokens, which are basically small chunks of words that a model reads and writes.
00:01:12So, to understand the context window, you also need to know that models on their own don't remember
00:01:18anything. With every prompt you send, the whole conversation along with your new prompt gets sent to the
00:01:23model, and that's how it knows what happened before and gives you a new answer. And this is exactly why
00:01:29the message you sent when you just started the session and the same message you send when you
00:01:33are deep into the session costs you differently. Everything gets counted in tokens, so a message
00:01:38you send later in a conversation costs you more because there's a whole conversation getting
00:01:42sent along with it. And your conversation isn't the only thing in there. When you open a session,
00:01:47your system instructions and your cloud.md go into the context window before you've typed anything,
00:01:53along with the name and description of every tool and skill you've got connected, and all of that
00:01:57stays there for the whole session. Now, if you don't know what a cloud.md is, it's the file where you
00:02:02write the instructions you want the tool to follow on that project. And in codex, that file is called
00:02:07agents.md, but it does the same job. And how much that window can hold depends on which model you're on.
00:02:13Opus gives you a million tokens, and GPT 5.6 SOL inside codex gives you 272,000. And once a conversation
00:02:20goes past that, it can't all fit anymore. But your usage limit is a completely different thing. It's
00:02:25basically the total amount of work or tokens you can spend with Claude Code across every session. Both
00:02:31Claude Code and Codex run on plans that you buy, and each one gives you a different amount of usage.
00:02:37Claude has Pro at $20 a month, and Max at either $100 or $200,
00:02:42and Codex runs on your ChatGPT plan, which is free, go, plus, or pro. And if you have the $20 plan of
00:02:49either one of them, then you need to use these token hacks more strictly, because you'll hit your
00:02:53limits way earlier. And that usage limit resets every five hours in both Claude Code and Codex.
00:02:58What this means is that you get a set amount to spend inside those five hours, and the clock starts
00:03:03on your first message. And there's a weekly usage limit on top of the five hour one. And that usage
00:03:08limit is shared across every model. So even if you switch the model after you've used it up,
00:03:13you won't get any of it back. Now that you know how the context window works, let's move on to the
00:03:18level one. And this level is all about the habits you build around things that are already built into
00:03:23Claude Code and Codex. So the first one is the clear command, and it works the same way in both
00:03:28Claude Code and Codex. You should run the clear command whenever you're about to start a new task that has
00:03:33nothing to do with the one you just finished. It empties out your context window and starts you off
00:03:38like you've just opened the tool, so the prompt for your new task doesn't get sent up with all that
00:03:43unrelated information attached. The second one is the compact command, and that's the same in both
00:03:48Claude Code and Codex. Compaction basically reads through your whole conversation, summarizes it,
00:03:53and starts you again from that summary instead of from a blank slate. But the problem is that most of
00:03:57the detail gets lost in that summary, so the model carries on with less than it had and the quality of
00:04:03the responses after that drops because it doesn't have context for the quality response. And compacting
00:04:08isn't free either, because the agents have to read that whole conversation to build the summary and
00:04:14all of that reading contribute to your usage limit. So the longer the conversation is, the more tokens it
00:04:19will consume in compacting. So your session does start with less in the context window after that,
00:04:24but you don't get back whatever it's spent from your usage limit. And it also matters when you compact.
00:04:29While you're working, Claude is keeping a ready-made copy of your conversation on its servers so that it
00:04:34doesn't have to read the whole thing again every single time that you send a message. And reading from
00:04:38that copy is basically a tenth of the price, but that copy is only there while you're still going.
00:04:43If you stop for long enough, then it gets thrown away, and the next thing that you do has to be read
00:04:48from the top again at the full price. And compacting reads your whole conversation,
00:04:52so if you can see that your context is filling up, you should compact before you take a break and not
00:04:56after you come back from one. So we'd say that don't compact on purpose again and again. And when
00:05:00you actually need to, always tell it what to keep in the instructions after the compact command. So the
00:05:06details that actually matter survive the summary. Now the third one is the rewind command, and this is
00:05:11for when the agent didn't do the work the way you wanted. Writing the correction into the next prompt
00:05:16leaves the mistake in your context window. So this way you're carrying both the mistake and the
00:05:21correction on every message after it. So instead you rewind, which removes the message out of the
00:05:26context window entirely, and then you put the correction into the next prompt you give. In Claude
00:05:31code, you can either run the rewind command or double tap escape. And in codex, there's no command for
00:05:36it, so you double tap escape instead. Now the fourth one is a prompting practice. You should put everything
00:05:41into one long prompt and send it once, instead of queuing up messages and splitting the job across
00:05:46several of them. That's because it isn't only your own messages that get sent up. Every time the agent
00:05:51reads a file or runs a command, the whole conversation goes up with it as well. So multiple small changes in
00:05:57different prompts mean more context is sent at once to the model, consuming more of the limit. And there's
00:06:02another reason for this, which is that both Claude code and codex are good at handling a lot of tasks
00:06:07at once. So when they get one big prompt instead of a few small ones, they plan the whole thing out and
00:06:12work through it together instead of taking each task on its own. We ran into this when we were building
00:06:16a website. We had a set of design changes to make like taking off the gradients, removing the glow,
00:06:21and fixing a few alignment problems. We put all of them into one prompt and handed it over in one go,
00:06:26and it came out costing far fewer tokens than running them one at a time. Now the fifth one is automatic
00:06:31recaps, and this one is Claude code only because codex doesn't do them at all. If you're running a few
00:06:36sessions at once, you lose track of what each one was doing. So Claude code gives you a one line
00:06:41summary of where that session got to whenever you come back to it. Now there are two ways you can get
00:06:46a recap. One is the automatic one we just talked about, and the second is that slash command which
00:06:51you run yourself. But to write that summary, Claude codex sends its own prompt off to the model without
00:06:56you asking, so it comes out of your usage limit like everything else. So to turn it off, you run the
00:07:01config command, search for session recap in there and switch it off, and then you run the recap
00:07:06command yourself whenever you actually want one. But before we go into level two, it would be great
00:07:11if you subscribe to the channel and hit the hype button. This small gesture of support goes a long
00:07:16way for us. Now this is level two, and this is where you stop changing how you work and start changing how
00:07:22the tools are set up. So we start with the model you're running on because that decides more of your
00:07:26usage limit than anything else in here. In Claude code, you get Opus, Sonnet, and Haiku. Opus is the most
00:07:32capable one and it takes the most out of your usage limit, so keep that for the genuinely hard work.
00:07:37Sonnet is efficient enough for the day-to-day work, and Haiku is the small fast one for quick answers.
00:07:42Codex also has a range of models. GPT 5.6 Soul is the most powerful one, and GPT 5.4 Mini is the smaller
00:07:50and cheaper one for the simple jobs, with a few others in between. And they're different in how much
00:07:54reasoning each one does before it answers you, and that's exactly where the cost comes from. So the model you
00:07:59pick has to match how hard the task actually is. So if you're on the twenty dollar plan, you should
00:08:04generally use Sonnet or GPT 5.6 Terra for your everyday tasks. Switch to Opus or GPT 5.6 Sol when
00:08:12the work gets more complex and the smaller models start struggling. We don't recommend using Opus for
00:08:17every task, because it's a lot more token intensive. But if you're on the one hundred dollar plan, then you
00:08:22should use Opus instead of Sonnet as your day-to-day model, because you've got the limit for it, and Opus performs
00:08:28a lot better than Sonnet does. To change which model you are using, you run the model command, which is
00:08:33the same in both Claude code and Codex. Now you can also configure how much the model thinks before it
00:08:38answers, and that setting is called the effort level. Every model works the problem out before it answers
00:08:43you, and the effort level controls how deep you let it go. That thinking determines how much the context
00:08:48limit gets used up, so the higher you set that level, the more of your usage limit each answer takes.
00:08:54To change it in Codex, you run the model command and then select which model you want. Once you select
00:08:59it, you can choose between the effort levels which are low, medium, high, and extra high. In Claude code,
00:09:04you run the effort command instead, and on Opus, you get more levels than that to choose from. So keep
00:09:09it on medium as your default, and when something genuinely needs the deeper thinking, turn it up for
00:09:14that one task rather than leaving it high for everything you do. You can also increase the thinking
00:09:19level by using the keyword "ultrathink" in your prompt. Now picking the model and setting the effort for
00:09:24every single task is genuinely hard to keep up with. To do that, you can use sub-agents. Normally when an
00:09:29agent spawns a sub-agent, it runs on the same model you're already using, but you can also spawn a
00:09:34sub-agent on a different model. The easiest way to do this is to specify the model right in your prompt,
00:09:39along with the task you want that sub-agent to handle. The agent then spawns a sub-agent on that model,
00:09:45and hands it the task automatically. But if you want that happening without you saying anything,
00:09:49the rule has to live somewhere. You'd put that rule in your Claude.md, and there's a problem with
00:09:54doing that. As your conversation grows, the agent pays most attention to your most recent messages,
00:09:59so instructions from the very start of the session are the first thing it drifts away from. So we
00:10:04built a skill instead, and called it Model Router, and this one runs on every prompt, looks at what
00:10:09you're about to ask for, and sends it to the model that fits. Now if you're going to build skills like
00:10:13that one, there's a size limit worth knowing, and it's 200 lines. By default only a skill's name and
00:10:19description go into your context window, which is how the agent knows it's there at all. The moment
00:10:24it uses one, the whole skill.md file loads, which is the file the skill itself is written in, so keep
00:10:30that file small, and put the detail into separate reference files alongside it, which can be as long
00:10:35as you want, because the agent only pulls the one it needs at the time. When we're building apps,
00:10:39we also add a lot of different skills. For example, when we were working on a software project management
00:10:44site, we added design skills from our own design systems so that they can help the agent design
00:10:49better, and since the app needed to store and manage data, we added the Superbase skills too.
00:10:54We use Superbase in most of our own projects too, because of how easy it is to use with agents like
00:10:59Claude Code and Codex. Superbase provides a lot of tools which help make the development using AI coding
00:11:05tools so much more easier, such as not having the database on your own computer and in the cloud.
00:11:10And to make all of them even simpler for agents, we use Superbase skills because it gives the agent
00:11:15all the instructions it needs for working with Superbase tools, so we don't have to tell the agent
00:11:20anything on how to use it. We just prompt it to build the app and the skills load up on their own
00:11:25and start setting up the logins and where all the data gets stored. In this way, we don't have to go
00:11:30and do any of the setup on the dashboard ourselves at all. And because these instructions only load in
00:11:35when the agent's actually working on the data or the user accounts, they're not loaded in the context
00:11:40window taking up space, so the agent doesn't load design skills when it's working with database
00:11:44related tasks. Aside from that, if you are writing Claude.md files for your workflow, they also need
00:11:50to be shorter than 200 lines, just like how skills are, which is the one file that contains all the
00:11:55instructions for working with the project. So anything specialized belongs in a skill instead. If you put
00:12:00your design rules in a skill, they only turn up when the agent is working on the design. If you leave
00:12:05them in Claude.md, they're loaded for the whole session, even when you're working on something else
00:12:10entirely. And in the Claude.md, keep only the things the agent doesn't already know. If you ask an agent
00:12:15to write that file, it'll fill it with things like how to run your app, which these models already know,
00:12:20and those lines then load every session for nothing. That's why when we work on our apps, we tell Claude
00:12:26exactly what to write in the Claude.md file instead of letting it write that on its own, so only the
00:12:32important information ends up in the context window. So don't put all of that into your main Claude.md
00:12:38when you're working on a big project with a lot of folders in it. Give each folder its own Claude.md,
00:12:43which holds only the instructions for that folder, and it only loads when the agent opens a file in there.
00:12:48So when you're working on the one part of the app, the rules of working on other parts are not in your
00:12:53context window at all. Asides from that, you need to track your usage on how much you've spent and
00:12:57where. For that, you run the usage command. It shows you how much of your 5-hour window and the weekly
00:13:03limit you've spent, then it shows you all the areas that are consuming most of the window. It names the
00:13:08skills, the MCP servers, and the habits that are eating the most of your limits. Now as we mentioned,
00:13:13we were building an app and we had connected Superbase to store the data. Superbase lives in
00:13:18the cloud instead of on your own laptop, which lets everyone access the same data from anywhere. But it
00:13:23also raises another problem. And that is that the agent you're using has no direct way to access it.
00:13:28So to let agents interact with Superbase, there are two ways to do so. You can either connect the CLI
00:13:33or use an MCP. That's where the next tip comes in. Because just like Superbase offers both CLI and the MCP,
00:13:40a lot of tools also offer both of them. And which one you pick changes how much of your context window
00:13:45gets used. Both of them basically work the same way. The real difference is in what each of them
00:13:50loads into your context window. When you connect an MCP, all of its tool names and descriptions get
00:13:56loaded into the context window and stay there, whether you're working on the data part of the app or not.
00:14:00The CLI doesn't get loaded in like the MCP does, since the agent just runs it through the terminal.
00:14:06It only runs its commands when the agent's actually working on the data, so nothing ends up in your
00:14:10context window unless it's actually needed. Now in the app we were building, when you prompt it,
00:14:15it loads the Superbase skills and asks which of the two you want to connect. Since the CLI uses fewer
00:14:21tokens than the MCP, we went with that and installed it. Once installed, you just log into your Superbase
00:14:26account using the login command, and after you've logged in, the agent will manage your projects and build the
00:14:32whole app from there. Now you might be wondering how the agent even knows the CLI is there in the
00:14:37first place. With an MCP, it knows a tool exists because its information is in the context window,
00:14:42but the CLI isn't loaded in there at all. That's where skills come in, because they tell the agent
00:14:47how to use it. The Superbase skills work the exact same way, they give the agent everything it needs
00:14:52to work with Superbase. Now this is level 3, and most of this is things that are on by default and
00:14:58quietly costing you. So the first one is memory. Both Claude Code and Codex build up memories as you
00:15:03use them, which are patterns and details out of your past sessions that they hold onto so they can help
00:15:09you better next time. The problem is that those memories get loaded into your context window, so
00:15:13you're paying for them on every single message, whether they have anything to do with what you're
00:15:18working on or not. So run the memory command and turn it off. It stops saving new ones, and you stop
00:15:22carrying the old ones around. You can do the same if you're on Codex as well. Claude Code
00:15:27also ships with a set of skills already built in, like the review ones. Most of them are those which
00:15:32you don't use much frequently. So set disable bundled skills to true in your settings if you're not using
00:15:37them, and next time you open a session that list is a lot shorter. And you can either open that file
00:15:42and edit it yourself, or just ask the agent to do it for you. Now Codex doesn't have this next feature
00:15:47that we're going to talk about, but Claude Code has it, and it's called workflows. A workflow kicks off a
00:15:51large number of sub-agents at once to work through something big, and that gets through your usage
00:15:56limit fast. So run the config command, find workflows, and turn them off if you don't use them. And if you
00:16:01do want them, you can set how big they're allowed to get. So on the $20 plan, you want the smaller ones.
00:16:07Now when Claude runs a command, it prints an output, and that output goes into the context window,
00:16:12but that fills the context window up, so there are two ways to limit how much of it gets sent in. The
00:16:16precise one is a hook, and if you don't know what a hook is, it's a small script that runs before a
00:16:21command and can change it. When we build an app, we write tests to check that it's doing what we want,
00:16:26but when an agent runs those tests, it injects all the output into the context, whether the tests are
00:16:32passing or failing, but the agent only needs the failing tests instead of the passing ones polluting
00:16:37the context window since those are the ones it has to fix. So we built a hook that stops this. We asked
00:16:43Claude code to write a hook that filters the passing tests out of the context window and only keeps the
00:16:48failing ones in there. You can pause here and copy the prompt to build your own. Once it's done, open
00:16:53the .clawed folder and then settings.json. You'll find the hook already registered with its script
00:16:58sitting in the hooks folder. The other way doesn't look at the output at all, it just sets a limit on how
00:17:03much can come back. In Claude code, that's bash max output length, which is the number of characters of
00:17:08terminal output that make it back into your conversation and you bring it down from 30,000 to
00:17:1310,000. You need to add this one to that same settings.json file inside your .clawed folder,
00:17:19the one you opened earlier for the hook. You can either open it yourself in a code editor like vs code,
00:17:24or just ask Claude code to edit it for you. Codex has its own version called tool output token limit,
00:17:30which counts tokens and covers every tool, not just the terminal. Now Claude code has an experimental
00:17:35feature called the advisor, which pairs your main model with a stronger one that Claude consults at
00:17:40the hard moments before it commits to an approach or when it keeps hitting the same error. It genuinely
00:17:45helps because that second model catches things the first one misses, but it costs a lot because every
00:17:50time it gets called, it sends the entire conversation over to the stronger model and that one gets no
00:17:55saved copy to read from, so it processes all of it from scratch every single time. And Claude decides when
00:18:00to call it not you, so turn the advisor off and build your own advisor agent instead. Give it the same
00:18:06name and it takes the place of the built-in one, so you keep the stronger model, but it only runs when
00:18:11you ask. In codex you set the same thing up in its config file and you tell it to use gpt 5.6 with the
00:18:17reasoning turned all the way up. Now Claude code recently got the ability to let your open sessions
00:18:22talk to each other and this changes how you work when you've got several sessions open. Now if you want to
00:18:27handle multiple sessions, you just name them and tell one to message the other with only the part that
00:18:32matters. So the second session gets only the thing it needed instead of everything around it. Now the
00:18:37agent and the skill we mentioned in this video are available in AI Labs Pro, which is our community. So if
00:18:42you found value in what we do and want to support the channel, this is the best way to do it. The link's in
00:18:47description. That brings us to the end of this video. If you'd like to support the channel and help us keep
00:18:52making videos like this, you can do so by using the super thanks button below. As always, thank you for
00:18:58watching and I'll see you in the next one.
Community Posts
No posts yet. Be the first to write about this video!
Write about this video