non-interactive `/compact`
I use Claude code via Telegram app to manage my pet projects on a remote server. As the context of each project accumulates, I sometimes get the error message "prompt is too long". When this happens, I need to open an interactive SSH session, navigate to the appropriate directory, run the claude command with the -c flag, and then type the /compact command interactively. After that, I can continue working with the project via Telegram.
I'm wondering if there's a way to run the context compression tool in non-interactive mode. I've tried using the -c -p /compact flags, but it doesn't seem to work. Maybe there's something else I'm missing? Any suggestions would be greatly appreciated.
+1
Automatic compaction should be working today- is it possible that the issue is instead that the prompt is fairly long and is causing this?
The issue is that if the automatic compression feature worked, 95% or more (in this case 196k) of the 200K tokens would be compressed automatically and the "error 400" would never occur. Therefore, if the auto-compression feature works properly in non-interactive mode, the problem could be considered solved. However, manual compression is still needed for cases like the one shown in the screenshot. When context filled <95%, but prompt is still too long to fit in context.
Result: API Error: 400 {"type":"error","error":{"type":"invalid_request_error","message":"input length and `max_tokens` exceed context limit: 183579 + 21333 > 200000, decrease input length or `max_tokens` and try again"}}
It is still happening
This is related to the size of the last user prompt being sent- basically if the last prompt is too large then the compact does not reserve enough space.
In general our recommendation is when possible to make information available as tools and let the model pull what it needs.
I see a weird issue where it automatically compacts successfully but the next message after that always returns "prompt is too long" even though I just send "hi"
+1
any updates here? it still happens keep getting prompt is too long
@dicksontsai would be great if you can check this one also
This would be nice - I'm running an iterative sdk workflow where I'm attempting to resume conversations, and even with a really small resume prompt, I'm seeing this issue. I tried a few ways to manually trigger a compaction, but none of them seem to work. My workaround is to prompt the previous session to output a compaction file, then start a new conversation with that file. I think there's still a chance I get the same issue, but I haven't seen it yet.
Is there even a way to manually trigger compaction? And yeah it appears we're getting this with even small last-user messages
Sometimes, I receive a message "Prompt is too long" in response. At the same time, the same prompt sequence works in interactive mode. If autocompact works, how can I see it in the messages from the SDK?