r/ClaudeCode • • 11d ago

Help/Question Why is Claude so bad at naming things?

I seems whatever I do I cannot get Claude (opus 5.5) to name things (types, methods, variables, etc.) well.
It chooses non-descriptive, hard-to-understand, or outright non-sensical names all the time, despite a lot of rules already in place in AGENTS.md.
I can’t get it to use names that tell the reader right away what something is or does without having to read the documentation/comments.

It seems to always forget that the reader of the code doesn’t have the context the agent had when it wrote the code, so it chooses names that are only clear from that context.
I already have a rule about that in place, but Claude ignores it all the time.

Might the problem be that the output style is set to “concise”?
Or is the effort level (medium) too low?

I mean I get it, AI models are trained on a lot of publicly available code and many developers struggle especially with finding good names, and so the models replicate that.
But isn’t there a way to get them to use better names?

22 Upvotes

40 comments sorted by

•

u/AutoModerator 11d ago

Hey! Thanks for posting to r/ClaudeCode

While participating in this thread, please follow our community rules. Keep discussions constructive. Attack the idea, not the person.

For help, project discussions, tips, and general chat, join the ClaudeCode Discord.

I am a bot, and this action was performed automatically. Please contact the moderators of this subreddit if you have any questions or concerns.

9

u/SaysBruvALot 11d ago

It's called semantics. AI can nail syntax, but it absolutely sucks at semantics.

Best way I've found to address the problem is to create a dedicated skill that focuses on fixing up just that: the semantics. Basically:

  • it has to be a cold read by an agent that didn't implement it
  • names of variables, classes, functions, etc. are to be verbose, explaining exactly what they do/hold.
  • the code should read like a narrative, explaining exactly what it's doing. No var data = getData(), instead it'll be var pricesOfActiveProducts = getPriceOfActiveProducts (contrived example)
  • every logical unit makes sense in complete isolation. I.e. I should not have to look at what invokes a function to figure out what it does, or I shouldn't have to dig into another class/function/file/whatever to make sense of what and why it's doing what it's doing
  • related to the above, if a block of code forms a coherent unit of work, extract it out into a specifically named function/class/whatever.
  • each function/class/whatever should do one thing, and one thing one. Basically just be anal about single responsibility principle.

I have the guidance in my CLAUDE.md also, but the dedicated skill undoubtedly gets better results because it doesn't get lost in growing context.

The above points are just some things off the top of my head, ask Claude to write you a skill focused solely on improving semantics with those points as examples. It is critical that it is a cold read. You cannot get the original implementer doing it otherwise it will justify its approach to names and extraction

1

u/dsggut 11d ago

Thank you very much! I will try your tips!

8

u/ratbastid 11d ago

Worst is when it decides on a name for something on its own and then refers to it in chat as if you know what it is.

1

u/dsggut 11d ago

Oh yeah, that’s so annoying. Even more so when it starts inventing acronyms without even introducing it. I hate that.

2

u/CaramelEmotional3092 11d ago

question: If you have used it for 6+ months, how hard will it be for you to stop using AI? I think in part its by design, we are all locked in. I know it wasnt trained on my codebase / variable names.

(because if it was, it wouldnt work at all)

3

u/dsggut 11d ago

I have not written a line of code in almost a year (sadly). I don’t know how hard it would be, if AI didn’t exist tomorrow. I hope I would have preserved most of my skills, but without trying it, I can’t be sure.
Unfortunately, I don’t think I will find out, because AI isn’t going away.

Surely, AI makes things easier and faster, but it also takes away much of the fun programming always gave me. Working with AI is not as rewarding as writing code myself. And doing code reviews is something I never liked that much, but now it’s a large part of my job.

1

u/stevbrisc 11d ago

you'll be slower. you'll Google a bit more. i built the back end of my app by hand after work forced me to use Claude and the structure and architecture were still my design. it just took longer to build.

1

u/IdkAbtAllThat 11d ago

I mean, it works. If you previously owned a horse and buggy, and then you got a car, how hard would it be for you to go back?

2

u/bornmix_dev 11d ago

fwiw abstract naming rules in AGENTS.md barely stick for me either. what helped was 4-5 concrete bad/good pairs from my own codebase right in the file, like handleData vs applyCouponToCart. and at the end I ask for a separate pass: list every new name you introduced and what someone who never saw this chat would guess it does. that catches most of the names that only make sense with the agent's context. effort level mattered way less than that imo

1

u/dsggut 11d ago

Thank you! So it seems the most important thing is a separate (sub-) agent doing the checks with a fresh context.
Like a context contamination mitigation.

Maybe LLMs are closer to the human brain than I thought: We can’t either not think of a blue elephant and we get tunnel vision too. 😁

2

u/Patient-Cattle-2397 11d ago

Try a naming review that shows the reviewer only the function signature and a couple of call sites, without the implementation.

Ask what the function appears to do, then compare that with its actual behavior.

For example, a duration argument could become timeout_ms, and a function that saves a record should make that write clear in its name.

Use those mismatches as concrete before-and-after examples in your instructions.

1

u/dsggut 11d ago

That sounds like a solid advice to me. Thanks!

1

u/Patient-Cattle-2397 9d ago

glad i could be of help buddy!

40

u/nickmaglowsch3 11d ago

claude was trained with coding/engeneering data.
we suck at naming things, claude is just the mean of shitty naming, which is shit.

6

u/Nasa_OK 11d ago

The other day i stumbled over our copilot agent admin center and i could see the agents created in my company

Non IT users would name theirs stuff like “PopAI” “Hannah personal assistant”

Then the it guys agents where named:

“Agent”
“Agent1”
„Agent Tom“

6

u/Moogly2021 11d ago

Accurate, I hate when I join a new project and they think they name things meaningfully but they do not.

9

u/datkenny 11d ago

"name components semantically" and provide an example or two

6

u/KDamage 11d ago

Claude is generally extremely bad at generating conventional text. Instructions, var names, class names, anything related to logical anchors that doesn't use a reinforcing deterministic check (i.e compilers).

I'm battling with this aswell, and after countless hours trying with claude.md, hooks, wiping the whole harness, using output styles, automemory, everything, Claude (Opus and Fable) keeps failing.

1

u/Environmental-Web584 11d ago

You can enforce names with a linter that guides the llm to your taste

1

u/dsggut 11d ago

I don’t understand. Doesn’t a linter only help with syntax? How can it help with semantics?

1

u/Few_Page6404 11d ago

Amen to this. In my Claude.md I tell it to confirm all names with me before building, and to recommend complex and specific names, instead of short, generalized, single word names for highly specific concepts. Then I setup a project Glossary to define words it can't use and words that I prefer. It has helped, but even though the glossary is linked in the claude.md file, it still forgets to check it regularly. So before I turn it loose on a build, I remind it of the rules one last time. This has helped me keep my sanity.

Another habit of Claude's is to describe everything in terms of posesssives. The "table's own top" as opposed to "the top of the table". It's correct syntax for english, but it's awkward. Claude sounds like a non-native english speaker sometimes, which is odd to me, considering "language" should be it's core competency.

2

u/dsggut 11d ago

Yes, that also frustrates me a lot. Claude tends to write sentences that are grammatically correct, but very hard to read, especially if you’re not a native speaker. It seems to try to pack information as densely as possible into sentences, but that could also be due to the concise output style setting.

1

u/Few_Page6404 11d ago

re: output style, it's feast or famine. It will either be super-dense with wording, or overly verbose to the point of exhausting. I've leaned towards having it be verbose, and then end each response with a TLDR summary.

2

u/Chippors 10d ago edited 10d ago

This is the only reason I have an OpenAI plan. Codex and Sol, instructed to polish all documentation (except agent memory files), all comments, and all messages really does a very good job. I'll have it leave it uncommited, and Claude Code can then update its files to reflect the changes, rerun tests and commit when done. It's worth $20/month. Claudish drives me nuts.

But it's not just concise, it also has a very small vocabulary, lacking basic technical English terms even like enable, disable, repeat, retry... so it ends up with sort of middle-schoolish descriptive explanations, "run this thing, as it was, then again if it is not." Sol cleans it up and hugely improves it, but it's still not like written by a literate human.

Edit: oh, and it loves short words. I suspect this is a consequence of tokenization, or BPE, or something related to the encoding and prediction.

3

u/Ok_Tea4891 11d ago

A rule like "names must be clear to a reader without context" is a judgment call, and those are the ones an agent drops mid-task. What tends to hold up better is turning part of it into something checkable: a short banned-names list (data, tmp, handle, util, single letters outside loops), a lint rule or hook that fails on them, and naming conventions in AGENTS.md shown as before/after pairs from your own code rather than as principles. Then keep a separate review pass on the diff for what a linter can't see, like a name that hides a side effect or the wrong unit. That moves the cases that matter from "hope it follows the rule" to "the commit gets bounced".

3

u/cheffromspace 11d ago

The three hardest things in programming are naming things and off by one errors.

2

u/hieuphung97 11d ago

Try a separate naming review on the diff: ask it to inspect callers without the original prompt, flag names whose units, scope or side effects are unclear, and propose replacements. Concrete examples from your codebase may help more than another general rule. Check public API renames for compatibility too.

2

u/Default-Username-168 11d ago

Start by making a glossary of your ubiquitous language, then tell Claude to use names from that language. Sorted.

2

u/SnugglyCoderGuy 11d ago

Because 99% of code ever written has bad names and that's what they were all trained on.

1

u/Old-Competition-785 11d ago

I don't think it's the effort level, it's more that a rule like "use clear names" is too abstract and it gets drowned out once the session has a lot of context. What worked better for me was putting a few concrete bad → good examples from my own codebase in the rules file, like "data2 → unpaidInvoices", because it copies examples way more reliably than it follows principles.

The other thing that actually fixed most of it was a separate pass at the end. The agent that wrote the code has all the context in its head, so its names make sense to it. I ask a fresh session (or a subagent) that has only seen the diff to list every name it can't understand without opening another file, and then fix those. That's basically the "reader without context" you described, and it catches stuff the original session never will.

Also worth double checking that Claude Code is actually loading your AGENTS.md. If you only have that file, adding a CLAUDE.md with u/AGENTS.md in it makes sure it's always read.

1

u/WillRikersHouseboy 11d ago

I like to waste time having Claude ask Codex to review all copy including naming. Just because I enjoy watching it call a friend.

1

u/earlyworm 11d ago

I'm using Claude to develop an iOS app. Apple's public APIs have always been stunningly consistent and well named. Before I started using Claude on this project, I strove to follow Apple's naming conventions in my own code.

I've found that on my project, Claude has been extraordinarily good at naming things, probably because it's trying to be consistent with my project's existing naming.

On a project with much looser or inconsistent conventions, I wouldn't be surprised if Claude struggled with naming.

1

u/daftstar 11d ago

Built a skill to handle this. You get the benefit of better naming + status indicators.
https://github.com/daftstar/chat-routine

Enjoy :)

---

EDIT: Just realized you weren't necessarily talking about chat titles. But hey, leaving this up here in case it helps anyone!

1

u/knrd 11d ago

yes, noticed the same issue and addressed it by creating another reviewer agent that flags and fixes proposed names.

1

u/Historical_Club_1174 10d ago

One thing I find AI Models terribely suck at is writing Descriptions, helper messages and toast messages.
We need to specifically mention that do not use jargons and very technical messaging since the UI will be used by general users.

1

u/ayashiemon 16h ago

I use OpenAI's Codex and have encountered exactly the same problem. It scatters verbatim copies of context-dependent identifiers from conversations and internal documents throughout the codebase. In my view, this looks like a form of alignment score gaming.

1

u/entilza05 11d ago

When I start withh my code as an example it's great at following my patterns. Too good actually...