# authoring-code-safely

Adopt this skill: https://proskills.md/skills/other/gavin844-claude-code-skills-skills-authoring-code-safely

Page: https://proskills.md/skills/other/gavin844-claude-code-skills-skills-authoring-code-safely
This document is the public skill bundle for that page. It contains SKILL.md and every helper file the catalog carries. No login is required.

## File: skills/authoring-code-safely/SKILL.md
size: 5028
upstream: https://github.com/gavin844/claude-code-skills/blob/main/skills/authoring-code-safely/SKILL.md

````text
---
name: authoring-code-safely
description: Write and edit source files with Write/Edit, never through bash heredocs or python -c string surgery. Use when creating or modifying any code file. Prevents escaping corruption that silently breaks the file you just wrote.
---

# Authoring code safely

**Rule: source files are written with Write and Edit. Never with a bash heredoc, never
with `python - <<'PY'` doing string replacement, never with `sed -i`.**

This is not style. Every layer between the intent and the file is a chance for the
text to change on the way through, and the failure is silent: the write succeeds, the
file is broken, and you find out on the next build.

## What actually went wrong (2026-08-20/21, one session)

| What I wrote | What landed in the file | Result |
|---|---|---|
| `return "\n".join(L)` inside a heredoc | a literal newline inside the string | `SyntaxError: unterminated string literal` |
| `text + "\n" + wb` inside a heredoc | same | same |
| `re.compile(r"(\d+)")` in a `python -c` | `SyntaxWarning: invalid escape sequence '\d'` | silent regex change |
| `{/* comment */}` before a JSX element | two children in an expression slot | `Failed to compile` |
| `-Args` (guessed the flag) | passed the literal string `-Args` | script errored, exit 2 |
| backticked names inside `python - <<PY` | shell ran each one as a **command**; every name deleted from four files | four broken skill files, silently written |

Four of those cost a full extra round trip each. One of them (`\d`) would have changed
behaviour without erroring at all. The last one happened **while I was writing this
skill**, which is the strongest argument for it: an unquoted heredoc delimiter (`<<PY`
instead of `<<'PY'`) leaves the body open to `$var` expansion and backtick command
substitution, so text that is perfectly valid in the file you meant to write gets
rewritten on the way in. Quoting the delimiter fixes that one case. It does not fix the
other four, which is why the rule is "use Write/Edit", not "quote your heredocs".

## The rule, concretely

- **New file** → `Write`.
- **Change to an existing file** → `Edit` with exact `old_string`/`new_string`.
- **Same change in many files** → still `Edit`, once per file. Repetition is cheaper
  than a corrupted file you have to find.
- **Bash is for running things**, not authoring them: tests, builds, git, greps, one
  line of `python -c` that only PRINTS.

## The one exception, and its guard

Generating many files from data (say, a metadata block per route) is legitimately a
script. When you do that:

1. Write the generator with `Write`, as a real file.
2. Have it write files, not patch them by string replacement where you can avoid it.
3. **Immediately parse every file it touched.** `python -c "import ast; ast.parse(open(f).read())"`
   for Python, `npx tsc --noEmit` for TypeScript. A generator that produced 71 files is
   71 chances to be wrong.
4. Read one generated file back and look at it.

## Before you run anything that writes

- Am I about to embed `\n`, `\t`, `\d`, `\s`, a backtick, `$`, or a quote in a shell
  string that becomes source code? Use `Write`/`Edit` instead.
- Am I inserting into JSX? A `{/* comment */}` is a CHILD. It cannot go in an
  expression slot (`cond ? ( ... ) : ( ... )`) beside the element. Use `//` above the
  return, or put the comment inside the element.
- Am I guessing a CLI flag? Read `--help` or the `param(...)` block first. One command
  is cheaper than one wrong run.

## After you write

Parse or typecheck **before** moving on. Not after three more edits, when you can no
longer tell which one broke it.

```
python -c "import ast; ast.parse(open('file.py',encoding='utf-8').read())"   # python
npx tsc --noEmit                                                            # ts/tsx
node --check file.js                                                        # js
```

If the language has no cheap parse, read the region you changed with `Read`.

## Related skills

Checked 2026-08-21 against the ~100 skills installed here and the public collections
before writing this one, after the user asked whether well-made skills already existed.
They did for two of the six I drafted, and those were folded into the existing skills
rather than duplicated:

- `verification-before-completion` - proving a claim before making it. Covers the
  ground my draft "read-the-artifact" would have; the two failure modes it was missing
  (grepping your own output for success, and treating a dry run as the artifact) were
  added to it instead.
- `systematic-debugging` - root cause before fixes.
- `karpathy-guidelines` - surfacing assumptions, surgical changes.
- `ponytail` - whether the thing needs to exist at all. Which is the check I skipped
  when I wrote six skills without looking for prior art first.

Nothing installed or public covered freshness-of-inputs, config-that-nothing-reads,
silent-failure patterns, or shell-escaping corruption when authoring files, which is
why those four exist.
````

## File: README.md
upstream: https://github.com/gavin844/claude-code-skills/blob/main/README.md

````text
# Claude Code skills

A skill is a folder holding a `SKILL.md`: markdown instructions that
[Claude Code](https://claude.com/claude-code) loads when it is in a particular
situation, so a lesson learned once does not have to be relearned every session. Some
also carry a script.

These 37 were written while shipping real systems through 2026, in seven groups. The
first four groups are rules: most exist because something broke quietly and the mistake
only surfaced when a person looked at the result, so each records what went wrong, the
rule that came out of it, and how to recognise the moment it applies again. The last three
are working playbooks for a consultancy, a recruiting product and a betting analyst. They
ship with sample companies and sample numbers in place of the real ones; each says what
to replace to make it yours.

## Install

Copy any skill folder into your skills directory:

```sh
git clone https://github.com/gavin844/claude-code-skills.git
cp -r claude-code-skills/skills/honest-code/fail-loud ~/.claude/skills/
```

Claude Code picks it up on the next session. The group folder is only for browsing; the
skill folder goes straight into `~/.claude/skills/`. Every skill has its own page with
what it does, when it loads, what is inside, and its install commands.

A few skills mention helper tools from their home workspace (`ui_check.js`,
`ux_audit.js`, `done_gate.py`). Those are not included; the skills stand without them.

## [Working methods](skills/working-methods)

How the agent behaves across a session: when to act, when to ask, what to say, and what counts as finished.

| Skill | What it does |
|---|---|
| [short](skills/working-methods/short) | Hard word caps on every reply: the answer first, no narration, no recaps. |
| [just-keep-working](skills/working-methods/just-keep-working) | When the next step is obvious and reversible, do it and report, instead of asking permission. |
| [correction-to-rule](skills/working-methods/correction-to-rule) | Turn a user's correction into a durable rule so the same mistake does not come back next session. |
| [midwork-triggers](skills/working-methods/midwork-triggers) | Load the right skill from what the agent is about to do mid-task, not only from the words of the request. |
| [preflight](skills/working-methods/preflight) | Before anything that writes, sends, deploys or spends, run the one check that settles the assumption, and never quietly change a rule the user set. |
| [done-means-proven](skills/working-methods/done-means-proven) | Nothing is called done without evidence from outside the work: a screenshot looked at, a job that fired, a live URL fetched. |
| [creative-mode](skills/working-methods/creative-mode) | On a request for creativity, diverge widely before converging, and aim for a bold, shippable leap over a safe tweak. |

## [Honest code](skills/honest-code)

Code that tells the truth about itself: failures that show, checks that are proven, settings that are wired, scripts that are kept.

| Skill | What it does |
|---|---|
| [authoring-code-safely](skills/honest-code/authoring-code-safely) | Write code with the file tools, never through shell string surgery, so escaping cannot corrupt the file. |
| [fail-loud](skills/honest-code/fail-loud) | Make failures visible instead of swallowed, so broken code cannot pass for working code. |
| [locate-before-you-guard](skills/honest-code/locate-before-you-guard) | Find the line that produced the wrong output before adding a check that would hide it. |
| [prove-the-checker](skills/honest-code/prove-the-checker) | Test every validator against a known-bad and a known-good case before trusting what it says. |
| [wire-the-knob](skills/honest-code/wire-the-knob) | Prove some code reads a new setting before claiming the setting changes anything. |
| [save-the-script](skills/honest-code/save-the-script) | Turn a working one-off script into a kept tool instead of rewriting it next time. |

## [Trustworthy data](skills/trustworthy-data)

Numbers and records a person can rely on: fresh inputs, money read from the source, user decisions that survive a rebuild.

| Skill | What it does |
|---|---|
| [user-state-is-sacred](skills/trustworthy-data/user-state-is-sacred) | Anything a person decided by hand survives every rebuild, re-sync and regeneration. |
| [one-writer-per-record](skills/trustworthy-data/one-writer-per-record) | A record that a scheduled job and a live session can both write gets exactly one owner. |
| [freshness-is-a-precondition](skills/trustworthy-data/freshness-is-a-precondition) | Check the age of cached data, prices and stats before acting on them. |
| [money-is-read-never-derived](skills/trustworthy-data/money-is-read-never-derived) | Read balances and profit from the system of record, never recompute them from history. |
| [version-your-definitions](skills/trustworthy-data/version-your-definitions) | Stamp a metric's definition next to its values, so numbers from different formulas are never compared. |
| [correlated-exposure](skills/trustworthy-data/correlated-exposure) | Group by what decides the outcome, not by the label, so an "at most N" limit catches hidden overlap. |
| [enumerate-before-ranking](skills/trustworthy-data/enumerate-before-ranking) | List the whole option set before picking the best, so the pick is not made from a partial list. |

## [Web apps](skills/web-apps)

Shipping a web surface that is finished, does not look generated, and moves well.

| Skill | What it does |
|---|---|
| [web-app-baseline](skills/web-apps/web-app-baseline) | The 20 checks every web app passes before it is called done, with the commands that prove them. |
| [website-craft](skills/web-apps/website-craft) | The 30 tells that make a site look machine-made, with a detector that finds them. |
| [web-motion-3d](skills/web-apps/web-motion-3d) | Real animation and 3D in a web app (Lottie, React Three Fiber, Vectary) without it reading as generated. |

## [Client work](skills/client-work)

A consultancy's sales and delivery documents, from the first call to the release notes. Ships with a sample company, Fieldstone AI, to replace with your own.

| Skill | What it does |
|---|---|
| [blueprint-builder](skills/client-work/blueprint-builder) | A tailored top-of-funnel Opportunity Blueprint that shows a prospect where AI can move their business. |
| [discovery-call-prep](skills/client-work/discovery-call-prep) | A one-page brief before a prospect call: who is in the room, where the deal stands, the angle and the opening question. |
| [client-follow-up](skills/client-work/client-follow-up) | A meeting transcript becomes a follow-up email draft and a table of next actions with owners and dates. |
| [sow-scoping](skills/client-work/sow-scoping) | Discovery notes become a Statement of Work draft with phases, deliverables, roles and assumptions, price left as XXX. |
| [demo-script](skills/client-work/demo-script) | A timed two-minute product demo: the hook, the one live wow moment, the proof and a single ask. |
| [release-notes](skills/client-work/release-notes) | Git history becomes release notes that read like a product update, not a commit log. |

## [Recruiting](skills/recruiting)

Screening resumes in batches, selling to staffing agencies, and grading job postings. Ships with sample data to replace with your own.

| Skill | What it does |
|---|---|
| [resume-batch-run](skills/recruiting/resume-batch-run) | Run a client's batch of resumes through an AI screener, tier the candidates, and give a reason for every score. |
| [staffing-outreach](skills/recruiting/staffing-outreach) | Cold outreach to staffing agencies that offers to rank one of their live batches, with two follow-ups. |
| [job-posting-grader](skills/recruiting/job-posting-grader) | Grade a job posting from the seeker's side, and keep a grader honest when it publishes about named companies. |

## [Betting and money](skills/betting-and-money)

A recommend-only sports betting analyst and a persona
````
