[BUG] `/context` do not respect `--system-prompt` flag
Status Closed — not planned
Maintainer reply None cached
Activity 9 comments · opened Nov 3, 2025 · closed Jan 25, 2026
Preflight Checklist
- [x] I have searched existing issues and this hasn't been reported yet
- [x] This is a single bug report (please file separate reports for different bugs)
- [x] I am using the latest version of Claude Code
What's Wrong?
Description
When I run claude --system-prompt "Answer with ALL CAPS" the /context command shows that System Prompt is still usual 2.4K token.
What Should Happen?
/context should show actual size when --system-prompt is used.
Steps to Reproduce
- Run
claude --system-prompt "Answer with ALL CAPS" - Run
/contextin TUI
Claude Model
Sonnet (default)
Is this a regression?
I don't know
Claude Code Version
2.0.35
Platform
Anthropic API
Operating System
macOS
Terminal/Shell
Terminal.app (macOS)
9 Comments
Found 3 possible duplicate issues:
This issue will be automatically closed as a duplicate in 3 days.
🤖 Generated with Claude Code
same issue -
/contextare broken when using--append-system-prompt
Repro
Without
--append-system-promptit shows correct counts<img width="945" height="460" alt="Image" src="https://github.com/user-attachments/assets/088d9114-b8d5-40fb-bb13-764bedb18483" />
✅ Correct:
62k(total from/context) minus buffer45kequals the real token count18011(from bottom right)After adding ~16k context with
--append-system-promptit shows wrong counts<img width="945" height="460" alt="Image" src="https://github.com/user-attachments/assets/328da78b-3e15-4578-81b3-70fbcbdc60af" />
❌Wrong:
64k(total from/context) minus buffer45kmeans/contextthinks current token usage is~20kwhile the actual usage is
36k(as seen in bottom right)this proves that the
16kappended system prompt context was not included in the/contextcount36k (correct) - 20k (incorrect) = 16k (appended system context)as expected@bcherny I don't know whether this will be useful, but I asked Claude Code to fix system prompt calculation for
/contextslash command in the minified source code of Claude Code. Here is its report:---
Fix: /context Command Ignoring --system-prompt Flag
The Bug
When using
--system-prompt "custom text", the/contextcommand showed 2.8k tokens (the default system prompt size) instead of the actual custom prompt's token count. The API correctly used the custom prompt, but/contextalways calculated tokens for the default prompt.Root Cause
The
--system-promptvalue lived only in the interactive session component's closure, inaccessible to slash commands:Before:
Slash commands accessed app state, but
systemPromptwasn't stored there.Solution
Thread the custom prompt through app state into the token calculation chain:
After:
Changes
1. Store in app state
2. Sync component prop to state
3. Pass to token calculator
4. Thread through metrics calculator
5. Use custom prompt when calculating tokens
Result
Running
--system-prompt "Your name is Waka-Waka"now shows ~17 tokens in/contextinstead of 2.8k tokens.This issue has been inactive for 30 days. If the issue is still occurring, please comment to let us know. Otherwise, this issue will be automatically closed in 30 days for housekeeping purposes.
I just double-checked with the latest (
2.0.76) version, the issue is still present.This issue has been automatically closed due to 60 days of inactivity. If you're still experiencing this issue, please open a new issue with updated information.
This issue was closed incorrectly despite recent human comments. This behavior of the bot is reported at https://github.com/anthropics/claude-code/issues/16497. Please upvote that issue, so maybe it gets noticed.
This issue has been automatically locked since it was closed and has not had any activity for 7 days. If you're experiencing a similar issue, please file a new issue and reference this one if it's relevant.