DEV Community

Cover image for How to save tokens/usage on your Coding Sessions (Claude, etc)
Medard Mandane
Medard Mandane

Posted on

How to save tokens/usage on your Coding Sessions (Claude, etc)

Saving Tokens/Usage especially on your coding sessions

Someone probably covered Most or all of this, I just learn OTG. So no hate pls. I will update this when I learn more strategies and when I have time

The Problem

  • Many of us are working on multiple projects, using shared accounts or maybe can't afford the MAX plans, so reaching the limits is really a pain in the ass that affects our momentum and productivity.

Possible Solutions that I tried myself

1. Install the following Skills

2. Provide initial Context

  • Point agent to a file or list of files related to the task as starting context. If you just ask them to build a feature, they will extract information from your query and do bunch of terminal commands to find the right files to work on.

3. Create New Chat

  • Once you are done working on a specific tasks, switch to a new chat for the others. Since you will be passing unecessary context if you stay in the current chat

4. Compact/Compress context

  • if in a single chat, you talked about many rules or specific instructions on how the agent should work or behave, or you are working on features that are tightly related to each other and that switching to new chat might not be the best solution. It's better to compact the chat before you start working on the next task every time. This saves tons of tokens
  • for claude we use /compact to summarize and reduce the context of the current chat

5. Plan -> Compact -> Implement

  • If you plan first, aside from saving tokens, the implementation is smoother. Since if you just ask the agent to implement a feature, it will do a mix of planning and implementation, a lot of thinking and realizing this is wrong and that is right. So it wastes a lot of tokens
  • When the plan is created, compact the context, then proceed with implementation.

6. Plan -> Implement in new Chat

  • This might be the most token saving approach, since after you create a plan and implement in a new chat, the only context the new chat has is the plan, and it doesn't need to figure out which files to update or do heavy searching of context since we already have a guide.

I personally do a mix and match of these methods, like I usually just compact if the tasks are continuous but not complex or big. And do Plan -> Implement Approach for big changes. It all depends.

Anyway Good luck and thank you for taking your time to read this

Top comments (0)