agentleFS
koteitankoteitan/my-skills/skills/get-context/SKILL.md

get-context

Skill1 starsChanged 3 months agoMITView on GitHub

Report the current Claude Code session's context-window usage percentage, computed locally from the session JSONL usage metadata

3 other projects use a version of this.

Adopted by

Most recently taken up by

The file

We split this skill into the rules it gives an agent

3 rules. 0 are common, 2 are distinctive, and 1 is very specific to this project.

  • 0

    Common

    Most of the 3 edited versions we read keep these.

  • 2

    Distinctive

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Before a long task, to decide whether compaction is near.

    line 15
  2. Distinctive:

    Run the bundled script and report its stdout:

    line 19
  3. Very specific:

    Read the last usage field — the token metadata auto-attached to each assistant message.

    line 37

“Common” is measured: kept by at least 6 in 10 of the 3 edited versions of this file we could read. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

get-context

Print how much of the context window the current session is using, as a percentage.

When to invoke

  • User asks how full the context is ("今どれくらいコンテキスト使ってる?", "context 残量", "how much context is left").
  • Before a long task, to decide whether compaction is near.

How to get it

Run the bundled script and report its stdout:

skills/get-context/scripts/get-context

It prints e.g. 12.4%. For the raw token count too:

GET_CONTEXT_RAW=1 skills/get-context/scripts/get-context   # -> 12.4% (123977/1000000 tokens)

How it works

  1. Locate the current session JSONL strictly via $CLAUDE_CODE_SESSION_ID (~/.claude/projects/**/<session-id>.jsonl). If the variable is unset, exit with an error instead of guessing — picking the wrong session would be worse than failing.
  2. Read the last usage field — the token metadata auto-attached to each assistant message. The latest entry reflects the whole conversation because the prior context is re-read from cache every turn.
  3. context_tokens = input + cache_creation + cache_read + output, then pct = context_tokens / CONTEXT_WINDOW * 100.

Env overrides

  • CONTEXT_WINDOW — context window size in tokens (default 1000000).
  • GET_CONTEXT_RAW — set to 1 to also print the raw token count.

Note

This is a local estimate from the session log, not the value Claude itself sees. It matches the /context figure closely (e.g. 11.9% computed vs 12% shown). The exact context_window.used_percentage is only available to the status line via Claude Code's stdin payload, not to a standalone script.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.