Claude for agencies

Claude Code Tutorial for Agency Owners: Build and Test a Small Brief Checker

Claude Code Tutorial for Agency Owners: Build and Test a Small Brief Checker

A claude code tutorial is most useful when it ends with something you can run, inspect and hand to a colleague. This one walks through a small checker that confirms each client brief in a batch has the two fields your team cannot start without: the client and the deliverable. The cases below show the observed output and exit code for each, but the exact fixture files are not reproduced, so treat the case names and table as a description of what we tested rather than something to copy byte for byte.

The code was generated in a single Claude Code 2.1.260 run through an Anthropic-compatible gateway with tools disabled and model anthropic/claude-haiku-5.5. It is not a consumer login or an autonomous editing session.

Ten controlled input/error cases for the generated brief checker
CaseInput conditionExpected exitObserved exit
completeRequired strings supplied00
missingDeliverable missing22
mixedOne ready and one incomplete record22
typesNull, array and primitive entries22
blankWhitespace-only required values22
optionalRequired values with null optional fields00
emptyEmpty JSON array00
objectNon-array top-level object11
invalid-jsonMalformed JSON11
missing-fileFile path does not exist11

Build a brief checker, not a whole client portal

The first version should answer one narrow question: does each brief in a batch contain the fields the team cannot start without? We chose client and deliverable as required fields. Budget and deadline stay optional, and the tool never fills them in, because inventing a deadline to satisfy a checker would be worse than leaving the field blank.

If you are still deciding how reusable instructions should be packaged, our claude code skills guide explains where a small checker like this could later live. For this tutorial, a single script and a single JSON file are enough to learn the workflow.

We do not recommend starting with a portal, a database or a client-facing login. Each of those adds permissions, hosting and maintenance before you have proven that the rule itself is right.

Write the input and output contract

Write the contract before asking for code. Our input is a JSON array of brief objects. A fictional example entry has a client named Northstar and a deliverable of one landing page draft, plus optional budget and deadline values if your team uses them. The contract fixes what counts as valid, so the model has a specification to implement rather than a vague goal.

The output is a JSON report with a valid count, an invalid count and one row per brief. Each row records its index, the client name where it is a usable string, a ready flag and the list of missing required fields. The exit code carries the result for scripts. Our agency version also links the output to the wider process in our AI Automation Services: Examples, Scope and Delivery for Agencies page, which covers when a checker like this belongs inside a paid service.

  • Input must be a JSON array; a single object is rejected with exit status 1.

  • A required field that is missing, not a string, or only whitespace counts as missing.

  • Optional budget and deadline fields do not change the result.

  • The script returns only 0, 1 or 2 as its exit status.

Ask Claude Code for a small implementation

Use a narrow prompt that names the runtime, the allowed behaviour and the failure codes. Our retained generation request asked for JSON with two keys, code and explanation, for a dependency-free Node.js ES module CLI. It reads one file path from the command line, requires client and deliverable to be non-empty strings, never invents budget or deadline, and exits 2 when a required field is missing and 0 otherwise. It also asked for exit 1 on invalid JSON or file errors and for arrays, null and strings to be treated as invalid entries. The request told the model not to run commands, read files, use tools or install anything, so it returned text only. The request said the file expects an array but did not explicitly ask for rejection of a top-level non-array; the generated code inferred that, so check that branch yourself.

Generated brief checker, with escaped line breaks corrected before the ten-case run.
#!/usr/bin/env node
import { readFile } from 'node:fs/promises';

const REQUIRED_FIELDS = ['client', 'deliverable'];

function isNonEmptyString(value) {
  return typeof value === 'string' && value.trim().length > 0;
}

function isPlainObject(value) {
  return value !== null && typeof value === 'object' && !Array.isArray(value);
}

function evaluateEntry(entry, index) {
  if (!isPlainObject(entry)) {
    return { index, client: null, ready: false, missing: [...REQUIRED_FIELDS] };
  }
  const missing = REQUIRED_FIELDS.filter((field) => !isNonEmptyString(entry[field]));
  return {
    index,
    client: isNonEmptyString(entry.client) ? entry.client : null,
    ready: missing.length === 0,
    missing,
  };
}

function reportError(message) {
  console.error(JSON.stringify({ error: message }));
}

async function main() {
  const filePath = process.argv[2];
  if (typeof filePath !== 'string' || filePath.length === 0) {
    reportError('Usage: node check-briefs.mjs <path-to-json-file>');
    return 1;
  }

  let raw;
  try {
    raw = await readFile(filePath, 'utf8');
  } catch (err) {
    reportError(`File error: ${err.message}`);
    return 1;
  }

  let data;
  try {
    data = JSON.parse(raw);
  } catch (err) {
    reportError(`Invalid JSON: ${err.message}`);
    return 1;
  }

  if (!Array.isArray(data)) {
    reportError('Input must be a JSON array of client-brief objects');
    return 1;
  }

  const rows = data.map(evaluateEntry);
  const validCount = rows.filter((row) => row.ready).length;
  const invalidCount = rows.length - validCount;

  console.log(JSON.stringify({ valid_count: validCount, invalid_count: invalidCount, rows }, null, 2));
  return invalidCount > 0 ? 2 : 0;
}

main().then(
  (code) => { process.exitCode = code; },
  (err) => { reportError(`Unexpected error: ${err.message}`); process.exitCode = 1; }
);

The returned JSON carried the code as one escaped string, with line breaks written as backslash-n sequences. We converted those sequences to real line breaks before running anything. Treat that conversion as a review step you record, not a hidden fix.

Before you ask for code, install the CLI and confirm it runs. The Claude Code quickstart covers installation, the first login prompt and a first session in a project directory, which is enough to get started before you try print mode.

Save and inspect the generated file

Save the code as check-briefs.mjs in an empty folder and read the whole file before you run it. Our generated version used only the built-in file reader and console output. Look for network calls, child processes, eval, hard-coded paths and any code that writes files. If the model uses a library you did not request, delete the function and regenerate rather than installing it.

The commands you would use are node check-briefs.mjs briefs.json for a normal run and node check-briefs.mjs missing.json for a file that does not exist, then echo $? in your shell to read the exit status. These are illustrative; our records capture case names, exit codes and output rather than the literal command lines.

The Claude Code CLI reference documents the claude -p form, which sends one query and exits, and it is the place to check flags before you copy a command into a script.

Our claude code automation guide is the right next step if you later want the checker to run on a schedule, but do not schedule anything until the manual cases pass.

Run the happy path and the failure cases

We ran ten local cases: complete, missing, mixed, types, blank, optional, empty, object, invalid JSON and missing file. Every case returned the exit code we expected. The table summarises six of them, chosen to show the main outcomes: pass, fail, mixed batch, bad entry types, and the two exit-1 input errors.

The happy path returned a valid count of 1 and an invalid count of 0, with a row for index 0 showing the client Northstar, ready set to true and an empty missing list. The missing case flagged only the deliverable and exited with status 2. In the mixed case, a second fictional entry with the client Unknown was marked not ready while the first stayed valid. The types case contained five entries that were not usable objects; each one reported both client and deliverable as missing, with the client shown as null. The blank case, optional case and empty array case also returned their expected codes, but we have not reproduced their full output here.

The blank, optional and empty-array cases also returned their expected codes. Note that an empty array produces valid count 0, invalid count 0 and exit 0, so an empty batch passes. If that is wrong for your team, add a check for it. Full output for those three is not reproduced here.

The programmatic Claude Code guide explains that claude -p runs non-interactively and exits with code 0 on success and a non-zero code when the run fails, which is why scripts can branch on that status. Your checker's exit codes are its own convention and are separate from that behaviour.

Decide whether the tool is ready for other people

Our evidence covers one Gateway print-mode run, one Claude Code version and ten local cases with fictional inputs. It does not measure accuracy on real client briefs, and it says nothing about other models or other interfaces. Before sharing the checker, run it on a copy of your own briefs with the sensitive fields removed, and add the edge cases your team actually sees.

Before running generated code, review its file paths, imports, network access, child processes and writes. In this demonstration, tools were disabled during generation and the saved checker only reads the JSON path it is given. The Claude permissions documentation explains that in Manual mode reads inside the working directory need no approval while edits and shell commands do, and that you can view and change allow, ask and deny rules in /permissions. Use those host settings to limit what a broader coding session can reach.

If the next version will choose actions instead of only checking fields, our claude ai agents guide explains how to define the stopping rule and review boundary. That is a separate design decision from whether this small checker passes its local cases.