claude-focus

作者 assafkip已验证

Three hooks that fix Claude Code's attention drift. Cited research, one-line install.

1
Stars
0
Forks
Python
语言
2026/8/24
添加时间

⚠️ 第三方软件声明

本 Skill 为第三方开源软件,独立托管于 GitHub。SkillTip 仅为信息目录,不控制或维护底层仓库。所显示的安全检查为自动化且范围有限,安装前请自行审查源码。

阅读服务条款

安装

添加到你的 Claude Code skills 目录:

# Add to your Claude Code skills
git clone https://github.com/assafkip/claude-focus

快速入门

使用 claude-focus 等 Skills 的指南。

安全报告

已验证

上次扫描:—

{
  "status": "PASSED",
  "issues": []
}

README.md

claude-focus

Three hooks that stop Claude Code from drifting, lying about "done," and burning tokens. ~550 lines of Python. Zero dependencies. MIT. Drop them into ~/.claude/hooks/ and wire three lines of settings.

git clone https://github.com/assafkip/claude-focus.git ~/.claude/hooks/claude-focus
cp ~/.claude/hooks/claude-focus/examples/settings.example.json ~/.claude/settings.json

Open Claude Code. The hooks are live. If you already have a ~/.claude/settings.json, merge the hooks block instead of overwriting.

The three hooks are token-guard.py (circuit breaker), verification-gate.py (catches false "done" reports), and echo-of-prompt.py (re-injects the original task so the model stops drifting). They run as PreToolUse / UserPromptSubmit / Stop hooks. No LLM call sits in the hot path, so they are fast and deterministic.

Version 1.1 - updated 2026-05-28

How do I stop Claude Code from running away and burning tokens?

Add a PreToolUse hook that counts tool calls and blocks the turn when it sees a runaway pattern. token-guard.py is that hook. It catches the model retrying a failed call three times, making 50 tool calls with no user input, spawning subagents that produce nothing, or hammering an MCP server. When a pattern trips, it blocks the turn (exit code 2) and tells the model what to do instead.

TriggerWhat it catchesAction
Same tool + same input, 3xRetry loops without diagnosisBlock
50 tool calls since last user messageRunaway executionBlock
25 subagents since last user messageAgent-spawn stormBlock
30 MCP calls in 60sAPI hammeringBlock
3 edit attempts on same fileWrong-approach edit spiralBlock
Attempted edit to .env, .pem, .keyAccidental secret exposureBlock
15 consecutive reads, no writeGrep driftWarn
Same file read 3xRe-read loopWarn
5 greps since last writeSearching instead of workingWarn
3 agents with no output between themAgents not producingWarn
2 min + 10 calls since last writeTime-based stallWarn

Every threshold is an environment variable (CLAUDE_FOCUS_VOLUME_CEILING, CLAUDE_FOCUS_RETRY_LIMIT, and so on), so you can tune it without touching the code.

Why does Claude Code lose track of the task halfway through?

The drift has research names. "Lost in the Middle" (Liu et al., 2023) describes how models lose the middle of a long context. Multi-turn drift (Laban et al., 2025) describes how they degrade over a long back-and-forth. The fix is not a better prompt. It is a hook that does not depend on the model behaving.

echo-of-prompt.py fights this directly. Write the task into .claude/task-context.md, and every 15 tool calls (configurable via CLAUDE_FOCUS_ECHO_INTERVAL) the hook re-injects it as additionalContext:

[echo-of-prompt - re-anchoring task context at call 30]
...original task content...
[Re-read this. Verify the current tool call still serves the original task.]

Attention drift stops compounding because the original requirements keep coming back into the model's working context.

How do I stop Claude Code from claiming it finished work it never did?

Claude self-reports "done" without checking. verification-gate.py does not let it. Drop a JSON contract in .claude/contracts/:

{
  "name": "daily-report",
  "required_file": "output/report-{date}.json",
  "required_keys": ["summary", "action_items", "sources"],
  "min_size_bytes": 200
}

On every Stop event (when Claude tries to end its turn), the gate checks every active contract. File missing, keys missing, or empty values? It blocks the turn with a diagnostic:

VERIFICATION FAILED. You reported the work is done. It isn't.
  - [daily-report] output/report-2026-05-28.json missing required keys: ['action_items']
Do NOT claim completion until every contract passes.

Self-reports become falsifiable. The turn cannot end until the file on disk actually matches the contract.

What is a Claude Code hook and how do I write one?

A hook is a command Claude Code runs at a lifecycle event: before a tool call (PreToolUse), when you submit a prompt (UserPromptSubmit), when the turn ends (Stop), and others. The hook reads a JSON payload on stdin and signals back with its exit code. Exit 0 allows the action. Exit 2 blocks it and sends stderr back to the model as feedback. All three hooks in this repo follow that contract, which is why they work without any LLM in the loop.

claude-focus vs full Claude Code frameworks

The big free frameworks are kitchen sinks: hundreds of skills, a whole operating system to install when you wanted a seatbelt. The bare guardrail snippets floating around GitHub tend to have no tests, no tuning profiles, and no install path. claude-focus is attention control done well: three small hooks that drop into any setup.

claude-focus (free)Kitchen-sink frameworkToken Guard Kit (paid)
Runaway circuit breakerYesBuried in a large systemYes, hardened
False-done verification gateYesNoYes, deadlock-proof
Task re-anchoringYesNoYes
Install footprintThree filesThe whole frameworkTwo minutes, any repo
TestsNoVaries35 pytest unit tests
Tuning profilesNoNosafe / aggressive / paranoid
Per-OS setup guidesNoVariesmacOS, Linux, Windows

How do I verify the hooks are actually wired?

In any Claude Code session, ask it to do something that forces a retry loop, like "read a file that doesn't exist, then retry 3 times." You should see a block message from token-guard.py instead of a fourth attempt. If you don't, the hook isn't picking up. Check your ~/.claude/settings.json and confirm the command paths resolve to the cloned files.

Can I tune the thresholds?

Yes. Every threshold is an environment variable. Set them in your shell before launching Claude Code:

export CLAUDE_FOCUS_VOLUME_CEILING=30        # hard stop at 30 tool calls instead of 50
export CLAUDE_FOCUS_RETRY_LIMIT=2            # block after 2 identical calls instead of 3
export CLAUDE_FOCUS_ECHO_INTERVAL=10         # re-inject task every 10 calls
export CLAUDE_FOCUS_CONTRACTS_DIR=.claude/contracts
export CLAUDE_FOCUS_CONTEXT_FILE=.claude/task-context.md

The defaults are sane for everyday coding. Full list lives in each hook's source.

What this is not

claude-focus is attention control. It catches deterministic patterns. It does not read intent and it will not fix a vague prompt. It stops the spinning, not the thinking.

License

MIT. See LICENSE.


I built these hooks for my own Claude Code work and open-sourced them. This repo is the free core.

The full Token Guard Kit adds a 35-test pytest suite shipped green, three tuning profiles (safe / aggressive / paranoid), a deadlock-proof Stop gate, an instruction-budget preflight CLI, advanced pipeline reliability modules, and a two-minute installer with per-OS guides: https://claudedaddy.gumroad.com/l/yybwrk

More kits for founders building on Claude Code: https://claudedaddy.io

Want one wired to your own setup, or a larger Claude Code reliability system built around it? I build these for teams. Book a call: https://calendar.app.google/cMFvhvDsfi9iyWYy9

常见问题

What is claude-focus?

claude-focus is an open-source ai agents skill for AI coding assistants such as Claude Code, Codex CLI, and ChatGPT, built by assafkip. Three hooks that fix Claude Code's attention drift. Cited research, one-line install. It has 1 GitHub star.

Is claude-focus safe to use?

Yes. claude-focus passed SkillsLLM's automated security scan — a dependency vulnerability audit plus prompt-injection heuristics — with no high-severity issues. You can read the full report in the Security Report section on this page.

How do I install claude-focus?

Clone the repository with "git clone https://github.com/assafkip/claude-focus" and add it to your Claude Code skills directory (see the Installation section above).

What programming language is claude-focus written in?

claude-focus is primarily written in Python. It is open-source under assafkip on GitHub, so you can review or fork the full source.

Are there alternatives to claude-focus?

Yes. SkillsLLM lists many other AI Agents skills you can browse and compare side by side. Open the AI Agents category from the badge at the top of this page, or use the Related Skills and comparison links further down to weigh claude-focus against similar tools.

评论 (0)

暂无评论,成为第一个分享想法的人!

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情

claude-code

by anthropics

Claude Code is an agentic coding tool that lives in your terminal, understands your codebase, and helps you code faster by executing routine tasks, explaining complex code, and handling git workflows - all through natural language commands.

120,03119,897Shell
AI 智能体
查看详情

开发者还喜欢

基于喜欢此 Skill 的开发者投票和收藏

ECC

by affaan-m

10

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

242,21936,702JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情
15

An agentic skills framework & software development methodology that works.

234,96620,863Shell
AI 智能体ai-agentsbrainstorming
查看详情

hermes-agent

by NousResearch

10

The agent that grows with you

234,43747,175Python
AI 智能体ai-agentsagent-orchestration
查看详情

n8n

by n8n-io

12

Fair-code workflow automation platform with native AI capabilities. Combine visual building with custom code, self-host or cloud, 400+ integrations.

201,88160,308TypeScript
MCP 服务器apisai-tools
查看详情

The agent harness performance optimization system. Skills, instincts, memory, security, and research-first development for Claude Code, Codex, Opencode, Cursor and beyond.

185,94028,768JavaScript
AI 智能体ai-agentsanthropicclaude-code
查看详情

cc-switch

by farion1231

3

A cross-platform desktop All-in-One assistant for Claude Code, Codex, OpenCode, OpenClaw, Grok Build & Hermes Agent. Only official website: ccswitch.io

128,8688,826Rust
AI 智能体claude-codeai-tools
查看详情