Add hull integrity monitoring and relief on station#16
Merged
harrymunro merged 3 commits intomainfrom Feb 20, 2026
Merged
Conversation
Remove references to deleted index files (admiralty-templates.md, damage-control.md, standing-orders.md) and add missing entries (royal-marines.md, commendations.md, battalion-ashore.md, marine-deployment-brief.md, scripts/) to README and CLAUDE.md. Fix $nelson to /nelson in agent definition.
Ships can now monitor their context window consumption and file structured damage reports. When a ship's hull integrity drops to Red, the admiral orchestrates relief on station — a tactical handover where the damaged ship writes a turnover brief to file and a fresh replacement reads it to continue the mission. New damage control procedures: - hull-integrity.md: threshold definitions, squadron readiness board - relief-on-station.md: planned ship replacement with chained reliefs - session-hygiene.md: clean start procedure for new sessions New admiralty templates: - damage-report.md: JSON format for hull integrity reports - turnover-brief.md: standard and flagship handover briefs New script: - count-tokens.py: reads exact token counts from Claude Code session JSONL files (zero external dependencies, no estimation needed)
The flagship monitors hull integrity across all ships by scanning the
session directory. Subagent JSONL files live at {session}/subagents/
and each contains its own API usage data, so the flagship reads every
ship's exact token count in one pass.
Ships cannot easily self-monitor (they do not know their own agent ID
to locate their JSONL file), but the admiral handles all hull integrity
checks at each quarterdeck checkpoint — which is the correct pattern.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Ships in a Nelson squadron now have damage control for the one thing that actually sinks AI agents: running out of context window.
The admiral monitors hull integrity across the entire squadron by reading exact token counts from Claude Code session JSONL files. No estimation heuristics, no paid APIs, no external dependencies — the numbers come straight from the API usage data that Claude Code already records on every assistant turn.
Each subagent (ship) has its own JSONL file at
{session-id}/subagents/agent-{agentId}.jsonl, separate from the flagship's session file. The admiral scans the whole directory in one pass to build a squadron readiness board — a single view of every ship's context health.When a ship's hull integrity drops to Red, the admiral orchestrates relief on station — a tactical handover borrowed from Royal Navy patrol doctrine. The damaged ship writes a rich turnover brief to file (not a message, to keep the replacement's context clean), a fresh ship reads it and picks up exactly where the other left off. The flagship monitors itself too, and can hand over to a new session before it founders.
What's new
3 damage control procedures:
2 admiralty templates:
.claude/nelson/damage-reports/{ship-name}.json1 utility script:
count-tokens.py— Three modes of operation:--session— Read a single JSONL file for exact token counts--squadron— Scan a session directory for the flagship + all subagent JSONL files and produce a full readiness board--file— Heuristic fallback for plain text (character count / 4)SKILL.md integration:
The key insight
Claude Code already records exact token counts (
input_tokens + cache_creation_input_tokens + cache_read_input_tokens) on every assistant turn in the session JSONL. We don't need to estimate anything — we just read the last assistant message's usage data.Ships can't easily self-monitor (they don't know their own agent ID to locate their JSONL), but that's the correct pattern: the flagship monitors everyone. The admiral runs
--squadronagainst the session directory at each quarterdeck checkpoint and gets the full picture.Live readiness board from the session that built this PR:
Test plan
--sessionproduces correct JSON with exact token counts from JSONL--squadronscans flagship + all subagent files and returns a readiness board--filefalls back to heuristic for plain textscripts/check-references.shpasses — all cross-references valid