Blog / claude code
Claude Code only saw the start of my SessionStart hook
Hook output over about 10,000 characters reaches Claude Code as a 2 KB preview. How to check what it saw, and how to keep the important lines in.
On this page
- How do I see what Claude Code actually got?
- Does JSON output get around it?
- Can't Claude Code just read the saved file?
- How do I keep the important lines in?
- What belongs in a SessionStart hook?
- Notes that stay short by themselves
- Frequently asked questions
- Why does Claude Code ignore the end of my SessionStart hook output?
- Is the limit different for JSON additionalContext?
- How do I give Claude Code a long document at session start?
- How can I tell whether my hook output was cut?
- Try it with your team
A SessionStart hook is the usual way to hand Claude Code the team's notes at the start of every session: today's decisions, who owns what, the freeze date. It works until the notes grow. Past a certain size, Claude Code no longer shows the hook's output to the model. It saves the text to a file and shows only the first 2 KB, and the line that mattered is in the part nobody read.
We tested where that happens and what to do about it, with Claude Code 2.1.318 and claude -p.
How do I see what Claude Code actually got?#
Ask it, and tell it not to use any tools, so it can't go and read the file itself. We made a hook that prints numbered notes and then one line at the end:
{
"hooks": {
"SessionStart": [
{ "hooks": [ { "type": "command", "command": "python3 .claude/ctx.py" } ] }
]
}
}for i in range(1, 150):
print(f"note {i:03d}: the team rule number {i} is to keep things tidy and short")
print("LAST-LINE-MARKER: the release freeze starts Friday")Then:
python3 .claude/ctx.py | wc -c
claude -p "Without using any tools or reading any file: does the SessionStart hook context you received end with a LAST-LINE-MARKER line? If yes, quote it. Was it shown in full or as a preview?"At 10,075 characters the answer was no:
The hook output I received was shown as a preview, not in full.
I only saw the first ~2KB, which ends at "note 029" followed by "...".
That preview contains no LAST-LINE-MARKER line.With one note fewer, at 9,395 characters, it quoted the marker and said the output was shown in full. The limit sits close to 10,000 characters.
Does JSON output get around it?#
No. A hook can also print JSON with the text in hookSpecificOutput.:
import json
lines = [f"note {i:03d}: the team rule number {i} is to keep things tidy and short" for i in range(1, 150)]
lines.append("LAST-LINE-MARKER: the release freeze starts Friday")
print(json.dumps({"hookSpecificOutput": {"hookEventName": "SessionStart", "additionalContext": "\n".join(lines)}}))Same size, same result: a 2 KB preview and no marker.
Can't Claude Code just read the saved file?#
It can, and when we allowed tools and asked for the last line, it did. But it only reads the file when the question sends it there. In a normal session nobody asks "what was at the end of the hook output?", so the freeze date at line 150 is simply unknown to the agent. Treat anything past the preview as not delivered.
How do I keep the important lines in?#
Three habits, in order of how much they help.
Print the short version, point to the rest. Put the full notes in a file in the repository and have the hook print only what every session must know, plus where the rest lives:
#!/bin/sh
echo "Release freeze starts Friday: no merges to main after Thursday 18:00."
echo "Full team notes: TEAM.md. Read the parts you need before you change anything."We put 27 KB of notes in TEAM.md and asked a question that needed both:
claude -p "When does the release freeze start, and what is team rule number 147?"It answered the freeze from the hook and found rule 147 in TEAM.md by itself.
Put what matters first. If the output might ever grow past the limit, the first 2 KB are what survives. Decisions and warnings go at the top; history and background go last or go in the file.
Check the size in the hook's own test. One line in CI or a pre-commit check stops it creeping back:
test "$(python3 .claude/ctx.py | wc -c)" -lt 9000 || echo "SessionStart output too long"Leave some room under 10,000: the limit counts what Claude Code receives, and an emoji or accented name takes more than one byte.
What belongs in a SessionStart hook?#
Think of the output as the note you'd leave on a colleague's keyboard, not the wiki. What earns a place:
- What changed since yesterday. A decision the team made, a file that moved, an API that's being replaced. These are the things an agent gets wrong from old habits.
- What's off limits right now. A freeze, a folder someone else is rewriting, a migration that must not be touched until it lands.
- Where the rest lives. File names, not file contents.
What doesn't: the whole README, the style guide, every rule ever written, the output of a long command. Rules that never change belong in CLAUDE.md or AGENTS.md, which the agent reads from the repository anyway. The hook is for what's true today.
A few more things we'd check on any SessionStart hook:
- It's fast. It runs before every session starts. A hook that calls the network or builds something makes every start slower, and a slow or broken network makes it fail.
- It prints nothing secret. Whatever it prints goes into the conversation and the transcript. Never echo a token, an environment file or a customer record.
- It works from any folder in the project. We used paths relative to the project, which worked because we started Claude Code from the project root. If people start it from subfolders, use the project directory variable Claude Code passes to hooks or an absolute path.
Notes that stay short by themselves#
The output grows because a team's notes grow: every decision gets appended and nothing is taken out. A file people actually prune helps more than any hook trick. Our template for a shared notes file every agent reads keeps it to who owns what, today's decisions and open questions. Joxo hands each session the project's current context the same way for every agent, and keeps it short so it arrives whole.
Frequently asked questions#
Why does Claude Code ignore the end of my SessionStart hook output?#
Output over about 10,000 characters is saved to a file and only a 2 KB preview reaches the model. In our tests 9,395 characters came through whole and 10,075 did not. Keep the output under that, with the important lines first.
Is the limit different for JSON additionalContext?#
Not in our test with Claude Code 2.1.318. The same text in hookSpecificOutput.additionalContext was cut to the same 2 KB preview.
How do I give Claude Code a long document at session start?#
Commit the document to the repository and have the hook print two short lines: the facts every session needs and the file name to read for the rest. Claude Code then reads the file when a question needs it.
How can I tell whether my hook output was cut?#
Start a session and ask, without tools, whether it can see the last line of the hook output and to quote it. If it describes a preview or can't quote the line, the output is too long.