Compare commits

...

4 commits

Author SHA1 Message Date
mwiegand
df85d45c46
docs(agents): add rule to avoid literal ! in inline Bash commands
Claude Code's Bash tool escapes every ! to \! at the transport layer
(anthropics/claude-code#61121, a regression of a 2.1.87 fix), corrupting
Python !=, jq, Jira JQL, branch names, etc. Documents the single robust
workaround: write !-containing code to .tmp/ via the Write tool and run
the file; .tmp/ is prompt-free via the Edit(.tmp/**) allow rule.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
2026-06-13 12:47:36 +02:00
mwiegand
31bf923872
docs(agents): add code-health and interpreting-requests sections 2026-05-17 20:02:09 +02:00
mwiegand
3f458f5114
docs(agents): treat ccc index / ccc init as read-safe maintenance 2026-05-17 19:58:38 +02:00
mwiegand
7679cf9f4b
feat(statusline): reset countdowns, thinking fallback, color-grade percentages
- Replace fixed "5h"/"7d" window labels with hours/days remaining until
  the rate-limit window resets, derived from rate_limits.*.resets_at.
- Wire up the previously-captured-but-unused $thinking variable as a
  fallback marker when no explicit effort.level is present.
- Color-grade all three percentages (context, 5h, 7d): yellow >=80%,
  red >=90%. Uses \e[39m to restore default fg without losing the
  surrounding dim attribute.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
2026-05-17 02:14:04 +02:00
2 changed files with 94 additions and 3 deletions

View file

@ -14,6 +14,42 @@
project's `AGENTS.md` / `CLAUDE.md` specifies a different directory, project's `AGENTS.md` / `CLAUDE.md` specifies a different directory,
that wins. that wins.
## Code health
Strategic over tactical, with follow-through. Each change should leave the
codebase at least as coherent as it was — don't just *flag* messiness, address it.
- **Default to acting on cleanups, not just mentioning them.** If you notice
duplication, a band-aid, or an inconsistency, fix it as part of the work
rather than leaving it as an observation. "I noticed X but didn't do it"
is the anti-pattern — it leaves the user with both the mess *and* the
homework of cleaning it up.
- **Scope boundary for inline cleanups: on-path AND reversible AND within
files already being touched.** Inline when all three hold. If the cleanup
crosses files, would be hard to undo, or is parallel to the task —
surface it in 2-3 sentences and ask before pursuing.
- **Tolerate duplication until the pattern is real.** Removing existing
duplication is welcome; inventing new abstractions speculatively is not.
Rule of three: don't unify two instances, wait for the third.
- **Treat friction as architectural data.** Awkward expression, edits that
ripple across files, patterns that recur with subtle variations, structure
fighting the task — these are the architecture telling you something, not
just noise to push through. Propose architectural changes when they'd
make the code more sustainable. Frame as proposals with a clear ask
("now, or follow-up?"), not silent rewrites.
## Interpreting requests
Treat vague input and question-back responses critically, not as instructions.
- **Vagueness is not authorization.** "Make it cleaner", "maybe X?",
"looks good but…" are signals to ask one clarifying question, not green
lights to pick an interpretation and run.
- **A tangent is not an answer.** If you ask "A or B?" and get "maybe X?",
that's a new question, not a pick. Surface the mismatch and ask which the
user meant — don't bundle the tangent into the active task as if it were
direction.
## Sandbox ## Sandbox
- **Always run commands sandboxed first.** Only use `dangerouslyDisableSandbox: true` as a last resort after a sandbox-related failure — never preemptively. - **Always run commands sandboxed first.** Only use `dangerouslyDisableSandbox: true` as a last resort after a sandbox-related failure — never preemptively.
@ -25,6 +61,22 @@
- `$TMPDIR` is set by the sandbox to a writable path. `.tmp/` inside the project directory is always writable without prompts. - `$TMPDIR` is set by the sandbox to a writable path. `.tmp/` inside the project directory is always writable without prompts.
- Ensure `.tmp/` is listed in `.gitignore` when creating temp files in a tracked repo. - Ensure `.tmp/` is listed in `.gitignore` when creating temp files in a tracked repo.
## Shell — literal `!` in Bash commands
- **Never put a literal `!` in an inline Bash command.** Claude Code's Bash tool
escapes every `!` to `\!` at the transport layer before any shell sees it —
even inside single/double quotes and in non-interactive shells
(anthropics/claude-code#61121, a regression of a fix shipped in 2.1.87). The
stray backslash corrupts downstream tools: Python `!=` → SyntaxWarning + broken
string, jq, Jira JQL (`status != Done` → server 400), branch names, etc.
`bash -c '...'` and quoted heredocs do **not** avoid it.
- **One rule covers everything:** if a command needs a `!`, write the command/code
to a file with the Write tool under `.tmp/` and run the file. `.tmp/` is
prompt-free via the `Edit(.tmp/**)` allow rule in `~/.claude/settings.json`. Do
**not** create the file with inline `printf`/`echo >` — that re-escapes the `!`.
- Need a literal `!` inline anyway: ANSI-C hex `$'\x21'` (e.g. `B=$'\x21'; cmd
"${B}=…"`) yields a real `!` with no literal `!` in the command.
## Tooling ## Tooling
- **`ccc` for semantic code search.** Repos containing a - **`ccc` for semantic code search.** Repos containing a
@ -36,3 +88,8 @@
it, results are filtered to the current working directory's it, results are filtered to the current working directory's
subtree. The `ccc` skill has the full reference; subtree. The `ccc` skill has the full reference;
`grep`/`rg`/`find` remain fine for exact-string lookups. `grep`/`rg`/`find` remain fine for exact-string lookups.
- **`ccc index` / `ccc init` are read-safe maintenance.** They only
write to the gitignored `.cocoindex_code/` directory, never to
source. Run them without confirmation prompts — at session start,
after refactors, or before a search when the index may be stale.
Treat like `grep` for permission purposes, not like a code edit.

View file

@ -12,7 +12,40 @@ used=$(echo "$input" | jq -r '.context_window.used_percentage // empty')
# Rate limits # Rate limits
rl_5h=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty') rl_5h=$(echo "$input" | jq -r '.rate_limits.five_hour.used_percentage // empty')
rl_5h_reset=$(echo "$input" | jq -r '.rate_limits.five_hour.resets_at // empty')
rl_7d=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty') rl_7d=$(echo "$input" | jq -r '.rate_limits.seven_day.used_percentage // empty')
rl_7d_reset=$(echo "$input" | jq -r '.rate_limits.seven_day.resets_at // empty')
# Whole hours until a unix-epoch timestamp, ceiling-rounded; falls back to label on past/empty
hours_until() {
local ts="$1" fallback="$2"
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
local diff=$(( ts - $(date +%s) ))
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
printf '%dh' "$(( (diff + 3599) / 3600 ))"
}
# Same idea, days
days_until() {
local ts="$1" fallback="$2"
[[ -z "$ts" ]] && { printf '%s' "$fallback"; return; }
local diff=$(( ts - $(date +%s) ))
(( diff <= 0 )) && { printf '%s' "$fallback"; return; }
printf '%dd' "$(( (diff + 86399) / 86400 ))"
}
# Render a percentage with optional suffix; yellow >=80, red >=90. \e[39m restores default fg without dropping the surrounding dim.
pct_color() {
local val="$1" suffix="$2" int color=''
int=${val%.*}
(( int >= 90 )) && color=$'\e[31m'
(( int >= 80 && int < 90 )) && color=$'\e[33m'
if [[ -n "$color" ]]; then
printf '%s%.0f%%%s\e[39m' "$color" "$val" "$suffix"
else
printf '%.0f%%%s' "$val" "$suffix"
fi
}
# Thinking / effort # Thinking / effort
thinking=$(echo "$input" | jq -r '.thinking.enabled // empty') thinking=$(echo "$input" | jq -r '.thinking.enabled // empty')
@ -23,11 +56,12 @@ dim=""
[[ -n "$branch" ]] && dim="$dim ($branch)" [[ -n "$branch" ]] && dim="$dim ($branch)"
[[ -n "$model" ]] && dim="$dim $model" [[ -n "$model" ]] && dim="$dim $model"
[[ -n "$effort" ]] && dim="$dim $effort" [[ -n "$effort" ]] && dim="$dim $effort"
[[ -n "$used" ]] && dim="$dim $(printf '%.0f%%' "$used")" [[ -z "$effort" && -n "$thinking" ]] && dim="$dim thinking"
[[ -n "$used" ]] && dim="$dim $(pct_color "$used")"
usage="" usage=""
[[ -n "$rl_5h" ]] && usage="$usage $(printf '%.0f%%/5h' "$rl_5h")" [[ -n "$rl_5h" ]] && usage="$usage $(pct_color "$rl_5h" "/$(hours_until "$rl_5h_reset" 5h)")"
[[ -n "$rl_7d" ]] && usage="$usage $(printf '%.0f%%/7d' "$rl_7d")" [[ -n "$rl_7d" ]] && usage="$usage $(pct_color "$rl_7d" "/$(days_until "$rl_7d_reset" 7d)")"
[[ -n "$usage" ]] && dim="$dim -$usage" [[ -n "$usage" ]] && dim="$dim -$usage"
printf '\033[1m%s\033[0m\033[2m%s\033[0m\n' "$dir" "$dim" printf '\033[1m%s\033[0m\033[2m%s\033[0m\n' "$dir" "$dim"