#claude-code #mcp #agents #tooling

one linkedin message, 35,887 characters

the gmail connector returned a one-sentence message as 35,887 characters, most of it html. the same thread through a small script is 1,688. so i measured every tool call i've made and started writing my own tools.

published
reading time
5 min read

one of my claude code sessions read a one-sentence linkedin message through the claude.ai gmail connector and got back 35,887 characters. almost all of it was html: style blocks, layout markup, and tracking links with query strings longer than the message.

the same thread through a script i wrote this week comes back as 1,688 bytes of plain text. the agent asked for the same thing both times. only the format of the answer was different.

how big is the problem, really

i wanted a number before building anything, so i counted tool results across 18,873 of my claude code and codex transcript files: 270,405 tool calls, about 439 million tokens of tool output. claude code logs each request’s input size, so the growth between requests can be split across the results that came in. codex doesn’t, so its results are estimated from characters. treat the total as an estimate. it counts results only, not the tool definitions that load into context before anything is called.

toolshare of tool-result tokens
bash48%
reading files35%
every mcp connector combined3.6%
everything else (codex shell, web, subagents)13%

i’d been blaming the connectors for bloated sessions, and they’re the small slice. most of my context goes to shell output and file reads. that’s a separate project, and an easier one: those are my own scripts and files, which i can actually change.

3.6% is still 15.9 million tokens, and it isn’t spread evenly. gmail search is the worst single tool at 2 million tokens over 503 calls, about 4k a call. next, at 1.75 million, is the agent memory server i wrote myself, so that one’s on me. then gmail get_thread, linear list_issues, and calendar list_events, which runs about 5.5k tokens a call because every event comes with its html description, conference data and reminder settings.

the pattern is the same everywhere. the connector hands back the api’s whole object, and the agent reads a few fields of it. gmail is worse than that: the connector has the right parameter and the wrong default. its schema says plain text, and leaving the format out returned the html too. that looks like a connector bug, and i can’t fix someone else’s default. a script i own picks its own.

same request, both ways

requestconnector (chars)script (chars)
that one linkedin thread35,8871,688
a week of calendar, 12 events14,085802
25 linear issues35,2162,952

12 to 21 times smaller. the scripts keep the fields i actually use: sender, date and body for mail, time and title for calendar, id, state and title for issues.

what i built

a folder of small scripts that both claude code and codex call through the shell, one per job:

gmail-thread    read one thread as plain text, quoted history cut
gcal-agenda     events as one line each: start, end, title, where
gdrive-find     files by name: id, kind, modified, name
gdrive-read     a doc as text, or a sheet range as tsv, paged
linear-find     issues as one line each: id, state, priority, title, project

they sit on things i already had (gws, a google workspace command-line tool, and linear’s api) and share one small helper, so each script is about a hundred lines. they all follow the same rules:

  • text by default, one record per line
  • --json for ndjson when another script is reading it
  • --fields id,title to pick columns
  • --max-chars on every free-text field, so one result can’t flood the window
  • each run reports the raw bytes it processed, so i can count what it saved instead of guessing

they’re read-only on purpose. every expensive call i measured was a read, and a send or a label change through the shell would skip the confirmation the connector gives you.

codex was the other reason. it doesn’t get my claude.ai connectors at all, so a script is the one thing both agents can share.

a guard for the connectors i keep

some connectors stay. so there’s also a claude code hook as a safety net:

  • before a gmail get_thread or get_message that didn’t pick a format, it adds messageFormat: PLAIN_TEXT. a call that asks for html on purpose is left alone.
  • after any mcp call over 20,000 characters, it saves the full result to disk and gives the model a trimmed copy: html bodies dropped (mail tools only), base64 blobs replaced, query strings cut off very long urls. images, and markup from other tools, are left alone. the first line says what was cut and where the full copy is, in case a link needed its query string.

replaying just the trim over a different recorded get_thread took it from 24,151 characters to 1,979, at 30 to 40 milliseconds a run. live, the format fix gets there first and the server sends about 2,500. it’s two hook entries in ~/.claude/settings.json (tested on claude code 2.1.331), and it passes the original through untouched if anything goes wrong. the saved copies hold whole emails, so they’re owner-only files that get deleted after 14 days.

the hook trims after the fact. the scripts never fetch the junk in the first place. i want the second one wherever i can get it, and the first one everywhere else.

i also went through every mcp tool in that count, gave each one a replacement or a reason to keep it, and summed the tokens. 38% of connector tokens are now covered by the scripts, 21% is that memory server of mine and needs fixing at the source, 15% already has a cli (gh for github) or belongs to tools i’ve retired, and 25% stays. that last part is chrome, screenshots and computer use, which have to see the screen.

code mode, one run

claude code has an experimental code mode (CLAUDE_CODE_EXPERIMENTAL_CODE_MODE=1). the model writes a program that calls its tools, and in principle only what the program returns lands in context. it’s the same idea as the scripts, built into the harness. as of 2.1.331 it’s chosen when a session starts, it turns off claude in chrome, computer use and remote control, and it won’t start in some enterprise setups. i ran it once on a light task: it saved about 6,800 tokens at session start and nothing while the task ran. both runs grew by 27,200 tokens, cost the same $0.36 and gave the same answer. one light run proves little, so it stays an opt-in i turn on for data-heavy sessions like inbox triage.

what i don’t know yet

whether agents actually reach for the scripts. a rule that says “check the library first” only works if the model follows it, so every run gets logged against the connector calls it replaces. if the connector share doesn’t drop, the rule isn’t working, and i’ll see it in the counts.

i also didn’t count the tool definitions, as i said above, and the hook does nothing for codex. the scripts are the part that helps both.

the stats script, the hook and the scripts are in my public agent field manual repo, as a context budget section next to the rest of how i run agents.

type to search...

↑↓ move ↵ open

keyboard shortcuts

/ or ⌘ then K or Ctrl then K
search the site
?
show these shortcuts
t
switch between dark and light
g then h
go to home
g then s
go to stories
g then f
go to field manual
g then p
go to projects
g then w
go to writing
g then a
go to about
esc
close search or this sheet

Shortcuts pause while you type in a field.